本文整理汇总了Python中api.tests.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.list_view = ViewSet.as_view({'get': 'list'})
self.detailed_view = ViewSet.as_view({'get': 'retrieve'})
self.anonymous_user = AnonymousUserFactory()
self.user_without_sources = UserFactory.create(username='test-username')
self.user_with_sources = UserFactory.create(username='test-username-with-sources')
self.user = self.user_with_sources
self.provider = ProviderFactory.create()
self.user_identity = IdentityFactory.create_identity(
created_by=self.user_without_sources,
provider=self.provider)
self.user_identity = IdentityFactory.create_identity(
created_by=self.user_with_sources,
provider=self.provider)
self.allocation_source_1 = AllocationSourceFactory.create(name='TG-TRA110001',
compute_allowed=1000)
self.allocation_source_2 = AllocationSourceFactory.create(name='TG-TRA220002',
compute_allowed=2000)
self.allocation_source_3 = AllocationSourceFactory.create(name='TG-TRA330003',
compute_allowed=3000)
UserAllocationSourceFactory.create(user=self.user_with_sources, allocation_source=self.allocation_source_1)
UserAllocationSourceFactory.create(user=self.user_with_sources, allocation_source=self.allocation_source_2)
示例2: setUp
def setUp(self):
self.view = ViewSet.as_view({'get': 'retrieve'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.leadership = LeadershipFactory.create(
user=self.user,
group=self.group
)
self.staff_user = UserFactory.create(is_staff=True)
self.provider = ProviderFactory.create()
self.identity = IdentityFactory.create(
provider=self.provider,
created_by=self.user)
self.quota = QuotaFactory.create()
self.allocation = AllocationFactory.create()
IdentityMembershipFactory.create(
member=self.group,
identity=self.identity,
quota=self.quota
)
factory = APIRequestFactory()
url = reverse('api:v2:identity-detail', args=(self.identity.id,))
self.request = factory.get(url)
force_authenticate(self.request, user=self.user)
self.response = self.view(self.request, pk=self.identity.id)
示例3: setUp
def setUp(self):
self.list_view = ViewSet.as_view({'get': 'list'})
self.detailed_view = ViewSet.as_view({'get': 'retrieve'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.staff_user = UserFactory.create(is_staff=True)
self.provider = ProviderFactory.create()
self.quota = QuotaFactory.create()
self.identity = IdentityFactory.create(
provider=self.provider, quota=self.quota, created_by=self.user
)
IdentityMembershipFactory.create(
member=self.group,
identity=self.identity,
)
factory = APIRequestFactory()
detail_url = reverse(
'api:v2:identity-detail', args=(self.identity.id, )
)
self.detail_request = factory.get(detail_url)
list_url = reverse('api:v2:identity-list')
self.list_request = factory.get(list_url)
示例4: create_an_instance
def create_an_instance(user=None, ip_address=None):
# This method should be replaced when the InstanceFactory can create an
# instance w/o requiring any arguments
import uuid
from api.tests.factories import (
UserFactory, InstanceFactory, ProviderMachineFactory, IdentityFactory,
ProviderFactory)
from django.utils import timezone
if not user:
user = UserFactory.create()
staff_user = UserFactory.create(is_staff=True, is_superuser=True)
provider = ProviderFactory.create()
user_identity = IdentityFactory.create_identity(
created_by=user,
provider=provider)
staff_user_identity = IdentityFactory.create_identity(
created_by=staff_user,
provider=provider)
machine = ProviderMachineFactory.create_provider_machine(staff_user, staff_user_identity)
start_date = timezone.now()
return InstanceFactory.create(
name="",
provider_alias=uuid.uuid4(),
source=machine.instance_source,
ip_address=ip_address,
created_by=user,
created_by_identity=user_identity,
start_date=start_date)
示例5: setUp
def setUp(self):
self.permissions = CanEditOrReadOnly()
self.user = UserFactory.create()
self.admin = UserFactory.create(is_staff=True)
self.creator = UserFactory.create()
self.anonymous_user = AnonymousUserFactory.create()
self.obj = mock.Mock()
self.obj.created_by = self.creator
self.request = mock.Mock()
self.view= mock.Mock()
示例6: setUp
def setUp(self):
self.view = UserViewSet.as_view({'get': 'list'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.staff_user = UserFactory.create(is_staff=True)
factory = APIRequestFactory()
url = reverse('api:v2:atmosphereuser-list')
self.request = factory.get(url)
force_authenticate(self.request, user=self.user)
self.response = self.view(self.request)
示例7: setUp
def setUp(self):
self.view = ViewSet.as_view({'get': 'list'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.staff_user = UserFactory.create(is_staff=True)
self.image = ImageFactory.create(created_by=self.user)
factory = APIRequestFactory()
url = reverse('api:v2:application-list')
self.request = factory.get(url)
force_authenticate(self.request, user=self.user)
self.response = self.view(self.request)
示例8: setUp
def setUp(self):
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.project = ProjectFactory.create(owner=self.group)
self.not_user = UserFactory.create()
self.not_group = GroupFactory.create(name=self.not_user.username)
self.view = ProjectViewSet.as_view({"delete": "destroy"})
self.factory = APIRequestFactory()
self.url = reverse("api:v2:project-detail", args=(self.project.id,))
self.request = self.factory.delete(self.url)
示例9: setUp
def setUp(self):
self.tag = TagFactory.build()
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.staff_user = UserFactory.create(is_staff=True)
self.factory = APIRequestFactory()
self.url = reverse('api:v2:tag-list')
self.request = self.factory.post(self.url, {
'name': self.tag.name,
'description': self.tag.description
})
self.view = TagViewSet.as_view({'post': 'create'})
示例10: setUp
def setUp(self):
self.view = ViewSet.as_view({'get': 'list'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.staff_user = UserFactory.create(is_staff=True)
self.provider_type = ProviderTypeFactory.create()
factory = APIRequestFactory()
url = reverse('api:v2:providertype-list')
self.request = factory.get(url)
force_authenticate(self.request, user=self.user)
self.response = self.view(self.request)
示例11: setUp
def setUp(self):
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.project = ProjectFactory.create(owner=self.group)
user2 = UserFactory.create()
group2 = GroupFactory.create(name=user2.username)
ProjectFactory.create(owner=group2)
self.view = ProjectViewSet.as_view({'get': 'retrieve'})
factory = APIRequestFactory()
url = reverse('api:v2:project-detail', args=(self.project.id,))
self.request = factory.get(url)
示例12: setUp
def setUp(self):
self.view = ViewSet.as_view({'get': 'retrieve'})
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.group = GroupFactory.create(name=self.user.username)
self.staff_user = UserFactory.create(is_staff=True)
self.quota = QuotaFactory.create()
factory = APIRequestFactory()
url = reverse('api:v2:quota-detail', args=(self.quota.id,))
self.request = factory.get(url)
force_authenticate(self.request, user=self.user)
self.response = self.view(self.request, pk=self.quota.id)
示例13: setUp
def setUp(self):
self.anonymous_user = AnonymousUserFactory()
self.user = UserFactory.create()
self.staff_user = UserFactory.create(is_staff=True)
factory = APIRequestFactory()
self.list_view = UserViewSet.as_view({'get': 'list'})
self.detail_view = UserViewSet.as_view({'get': 'retrieve'})
detail_url = reverse(self.url_route + '-detail', args=(self.user.id,))
list_url = reverse(self.url_route + '-list')
self.detail_request = factory.get(detail_url)
self.list_request = factory.get(list_url)
示例14: test_create_event
def test_create_event(self):
event_count = EventTable.objects.count()
self.assertEqual(event_count, 0)
user = UserFactory.create()
alloc_src = AllocationSource.objects.create(
name='DefaultAllocation', compute_allowed=1000
) # UUID assigned by default.
UserAllocationSource.objects.create(
user=user, allocation_source=alloc_src
)
event_payload = {
'allocation_source_id': str(alloc_src.uuid),
'compute_used':
100.00, # 100 hours used ( a number, not a string!)
'global_burn_rate': 2.00, # 2 hours used each hour
}
new_event = EventTable.create_event(
name='allocation_source_snapshot',
payload=event_payload,
entity_id=str(alloc_src.uuid)
)
event_count = EventTable.objects.count()
self.assertEqual(event_count, 2)
events = EventTable.objects.all()
self.assertEqual(new_event, events[1])
self.assertEqual(events[0].name, 'allocation_source_threshold_met')
self.assertEqual(events[0].entity_id, str(alloc_src.uuid))
self.assertEqual(
events[0].payload, {
'actual_value': 10,
'allocation_source_id': str(alloc_src.uuid),
'threshold': 10
}
)
示例15: create_admin_and_two_regular_users
def create_admin_and_two_regular_users(context):
context.client = Client()
user = UserFactory.create(username='lenards', is_staff=True, is_superuser=True)
user.set_password('lenards')
user.save()
with modify_settings(AUTHENTICATION_BACKENDS={
'prepend': 'django.contrib.auth.backends.ModelBackend',
'remove': ['django_cyverse_auth.authBackends.MockLoginBackend']
}):
context.admin_user = user
context.client.login(username='lenards', password='lenards')
user_1 = UserFactory.create(username='amitj')
context.user_1 = user_1
user_2 = UserFactory.create(username='julianp')
context.user_2 = user_2