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


Python model_factories.UserFactory类代码示例

本文整理汇总了Python中geokey.projects.tests.model_factories.UserFactory的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setUp

    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.other_project = ProjectFactory.create()

        # Create 20 locations, 10 should be accessible for the project
        for x in range(0, 5):
            LocationFactory()
            LocationFactory(**{
                'private': True,
                'private_for_project': self.other_project
            })
            LocationFactory(**{
                'private': True,
                'private_for_project': self.project
            })
            LocationFactory(**{
                'private': True
            })
开发者ID:Josh1billion,项目名称:geokey,代码行数:26,代码来源:test_views.py

示例2: setUp

 def setUp(self):
     self.contributor = UserFactory.create()
     self.admin = UserFactory.create()
     self.non_member = UserFactory.create()
     self.project = ProjectFactory(
         add_admins=[self.admin],
         add_contributors=[self.contributor]
     )
     self.contribution = ObservationFactory.create(**{
         'project': self.project,
         'creator': self.contributor
     })
     comment = CommentFactory.create(**{
         'commentto': self.contribution
     })
     response = CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': comment
     })
     CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': response
     })
     CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': comment
     })
     CommentFactory.create(**{
         'commentto': self.contribution
     })
开发者ID:ExCiteS,项目名称:geokey,代码行数:30,代码来源:test_views.py

示例3: post

    def post(self, user, data=None):
        if user.is_anonymous and not User.objects.filter(
                display_name='AnonymousUser').exists():
            UserFactory.create(display_name='AnonymousUser')

        if data is None:
            data = {
                'name': 'A test image',
                'description': 'Test image description',
                'file': get_image()
            }

        url = reverse(
            'api:project_media',
            kwargs={
                'project_id': self.project.id,
                'contribution_id': self.contribution.id
            }
        )

        request = self.factory.post(url, data)
        force_authenticate(request, user)
        view = AllContributionsMediaAPIView.as_view()
        return view(
            request,
            project_id=self.project.id,
            contribution_id=self.contribution.id
        ).render()
开发者ID:Josh1billion,项目名称:geokey,代码行数:28,代码来源:test_views.py

示例4: setUp

 def setUp(self):
     """Set up test."""
     self.superuser = UserFactory.create(**{'is_superuser': True})
     self.admin = UserFactory.create(**{'is_superuser': False})
     self.contributor = UserFactory.create(**{'is_superuser': False})
     self.regular_user = UserFactory.create(**{'is_superuser': False})
     self.project = ProjectFactory.create(
         add_admins=[self.admin],
         add_contributors=[self.contributor],
         **{'isprivate': True})
开发者ID:ExCiteS,项目名称:geokey-sapelli,代码行数:10,代码来源:test_sapelli_tags.py

示例5: get_response

    def get_response(self, user):
        if user.is_anonymous and not User.objects.filter(display_name="AnonymousUser").exists():
            UserFactory.create(display_name="AnonymousUser")

        factory = APIRequestFactory()
        request = factory.post(
            "/api/projects/%s/maps/all-contributions/%s/comments/" % (self.project.id, self.contribution.id),
            {"text": "A comment to the contribution."},
        )
        force_authenticate(request, user=user)
        view = CommentsAPIView.as_view()
        return view(request, project_id=self.project.id, contribution_id=self.contribution.id).render()
开发者ID:ExCiteS,项目名称:geokey,代码行数:12,代码来源:test_views.py

示例6: test_get_isowner

    def test_get_isowner(self):
        user = UserFactory.create()
        comment = CommentFactory.create(**{'creator': user})

        serializer = CommentSerializer(comment, context={'user': user})
        self.assertTrue(serializer.get_isowner(comment))

        serializer = CommentSerializer(
            comment, context={'user': UserFactory.create()})
        self.assertFalse(serializer.get_isowner(comment))

        serializer = CommentSerializer(
            comment, context={'user': AnonymousUser()})
        self.assertFalse(serializer.get_isowner(comment))
开发者ID:Josh1billion,项目名称:geokey,代码行数:14,代码来源:test_serializers.py

示例7: setUp

 def setUp(self):
     self.user1 = UserFactory.create()
     self.user2 = UserFactory.create()
     self.app1 = ApplicationFactory(**{
         'user': self.user1
     })
     self.app2 = ApplicationFactory(**{
         'user': self.user1
     })
     self.app3 = ApplicationFactory(**{
         'user': self.user2
     })
     self.deleted_app = ApplicationFactory(**{
         'user': self.user1,
         'status': 'deleted'
     })
开发者ID:ExCiteS,项目名称:geokey,代码行数:16,代码来源:test_managers.py

示例8: test

    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        observation = ObservationFactory.create(**{
            'project': project
        })
        comment = CommentFactory.create(**{
            'commentto': observation
        })

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/observations/%s/comments/' %
            (project.id, observation.id),
            {
                'text': 'Response to a comment',
                'respondsto': comment.id
            }
        )
        force_authenticate(request, user=admin)
        view = AllContributionsCommentsAPIView.as_view()
        response = view(
            request,
            project_id=project.id,
            observation_id=observation.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            json.loads(response.content).get('respondsto'),
            comment.id
        )
开发者ID:Josh1billion,项目名称:geokey,代码行数:32,代码来源:test_views.py

示例9: test_get_with_unconnected_user

 def test_get_with_unconnected_user(self):
     view = ApplicationDisconnect.as_view()
     url = reverse('admin:app_disconnect', kwargs={'app_id': self.app.id})
     request = APIRequestFactory().get(url)
     request.user = UserFactory.create()
     response = view(request, app_id=self.app.id)
     self.assertTrue(isinstance(response, HttpResponseRedirect))
开发者ID:Josh1billion,项目名称:geokey,代码行数:7,代码来源:test_views.py

示例10: test_post_with_user

    def test_post_with_user(self):
        data = {
            'name': 'test app',
            'description': '',
            'download_url': 'http://example.com/download',
            'redirect_uris': 'http://example.com/redirect',
            'authorization_grant_type': 'password'
        }

        view = ApplicationSettings.as_view()
        url = reverse('admin:app_settings', kwargs={'app_id': self.app.id})
        request = APIRequestFactory().post(url, data)
        request.user = UserFactory.create()
        response = view(request, app_id=self.app.id).render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            'You are not the owner of this application and therefore not '
            'allowed to access this app.'
        )

        ref = Application.objects.get(pk=self.app.id)
        self.assertNotEqual(ref.name, data.get('name'))
        self.assertNotEqual(ref.description, data.get('description'))
        self.assertNotEqual(ref.download_url, data.get('download_url'))
        self.assertNotEqual(ref.redirect_uris, data.get('redirect_uris'))
        self.assertNotEqual(
            ref.authorization_grant_type,
            data.get('authorization_grant_type')
        )
开发者ID:Josh1billion,项目名称:geokey,代码行数:30,代码来源:test_views.py

示例11: test

    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{
            'project': project
        })
        comment = CommentFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (project.id, contribution.id),
            {
                'text': 'Response to a comment',
                'respondsto': comment.id
            }
        )
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(
            request,
            project_id=project.id,
            contribution_id=contribution.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            json.loads(response.content).get('error'),
            'The comment you try to respond to is not a comment to the '
            'contribution.'
        )
开发者ID:ExCiteS,项目名称:geokey,代码行数:31,代码来源:test_views.py

示例12: test_get_with_user

 def test_get_with_user(self):
     view = ApplicationOverview.as_view()
     url = reverse('admin:app_overview')
     request = APIRequestFactory().get(url)
     request.user = UserFactory.create()
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
开发者ID:Josh1billion,项目名称:geokey,代码行数:7,代码来源:test_views.py

示例13: test_get_contribution_with_some_dude

 def test_get_contribution_with_some_dude(self):
     some_dude = UserFactory.create()
     view = SingleCommentAPIView()
     view.get_contribution(
         some_dude,
         self.project.id,
         self.contribution.id
     )
开发者ID:ExCiteS,项目名称:geokey,代码行数:8,代码来源:test_views.py

示例14: get_response

    def get_response(self, user):
        if user.is_anonymous and not User.objects.filter(
                display_name='AnonymousUser').exists():
            UserFactory.create(display_name='AnonymousUser')

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/maps/all-contributions/%s/comments/' %
            (self.project.id, self.observation.id),
            {'text': 'A comment to the observation'}
        )
        force_authenticate(request, user=user)
        view = AllContributionsCommentsAPIView.as_view()
        return view(
            request,
            project_id=self.project.id,
            observation_id=self.observation.id
        ).render()
开发者ID:Josh1billion,项目名称:geokey,代码行数:18,代码来源:test_views.py

示例15: test_for_viewer

 def test_for_viewer(self):
     observations = Observation.objects.all().for_viewer(
         UserFactory.create())
     self.assertEqual(len(observations), 5)
     for observation in observations:
         self.assertNotIn(
             observation.status,
             ['draft', 'pending', 'deleted']
         )
开发者ID:ExCiteS,项目名称:geokey,代码行数:9,代码来源:test_managers.py


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