当前位置: 首页>>代码示例>>Python>>正文


Python UserFactory.create方法代码示例

本文整理汇总了Python中api.tests.factories.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api.tests.factories.UserFactory的用法示例。


在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:29,代码来源:test_allocation_sources.py

示例2: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:Cyberlusion,项目名称:Restoring-the-ecosystem,代码行数:30,代码来源:test_identities.py

示例3: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:28,代码来源:test_identities.py

示例4: create_an_instance

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
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)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:31,代码来源:test_web_tokens.py

示例5: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
 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()
开发者ID:Cyberlusion,项目名称:Restoring-the-ecosystem,代码行数:12,代码来源:test_permissions.py

示例6: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:hwijung,项目名称:atmosphere,代码行数:13,代码来源:test_users.py

示例7: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:15,代码来源:test_images.py

示例8: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:Cyberlusion,项目名称:Restoring-the-ecosystem,代码行数:15,代码来源:test_projects.py

示例9: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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'})
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:16,代码来源:test_tags.py

示例10: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:16,代码来源:test_provider_types.py

示例11: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:miquelcie,项目名称:atmosphere,代码行数:16,代码来源:test_projects.py

示例12: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:16,代码来源:test_quotas.py

示例13: setUp

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
    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)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:17,代码来源:test_users.py

示例14: test_create_event

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
 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
         }
     )
开发者ID:iPlantCollaborativeOpenSource,项目名称:atmosphere,代码行数:36,代码来源:test_event_table.py

示例15: create_admin_and_two_regular_users

# 需要导入模块: from api.tests.factories import UserFactory [as 别名]
# 或者: from api.tests.factories.UserFactory import create [as 别名]
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
开发者ID:xuhang57,项目名称:atmosphere,代码行数:18,代码来源:allocation_story_steps.py


注:本文中的api.tests.factories.UserFactory.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。