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


Python model_factories.ProjectF类代码示例

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


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

示例1: test_post_with_admin

    def test_post_with_admin(self):
        user = UserF.create()
        project_1 = ProjectF.create(**{'creator': user})
        project_2 = ProjectF.create(**{'creator': user})
        data = {
            str(project_1.id): 'on'
        }

        view = UserNotifications.as_view()
        url = reverse('admin:notifications')
        request = APIRequestFactory().post(url, data)
        request.user = user

        from django.contrib.messages.storage.fallback import FallbackStorage
        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = view(request).render()
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertTrue(
            Admins.objects.get(project=project_1, user=user).contact
        )
        self.assertFalse(
            Admins.objects.get(project=project_2, user=user).contact
        )
开发者ID:NatEvatt,项目名称:geokey,代码行数:27,代码来源:test_views.py

示例2: setUp

    def setUp(self):
        self.creator = UserF.create()
        self.admin = UserF.create()
        self.view_member = UserF.create()
        self.contributor = UserF.create()
        ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )

        ProjectF.create(
            add_admins=[self.admin, self.contributor]
        )
开发者ID:NatEvatt,项目名称:geokey,代码行数:13,代码来源:test_views.py

示例3: test_single_lookup

    def test_single_lookup(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        lookup = LookupFieldFactory.create(
            **{'category': category, 'key': 'lookup'}
        )
        kermit = LookupValueFactory.create(**{
            'field': lookup,
            'name': 'Kermit'
        })
        gonzo = LookupValueFactory.create(**{
            'field': lookup,
            'name': 'Gonzo'
        })
        ObservationFactory.create_batch(3, **{
            'project': project,
            'category': category,
            'attributes': {'lookup': kermit.id}
        })
        ObservationFactory.create_batch(3, **{
            'project': project,
            'category': category,
            'attributes': {'lookup': gonzo.id}
        })

        result = project.observations.all().search('kermit')
        self.assertEqual(len(result), 3)

        for o in result:
            self.assertEqual(o.attributes.get('lookup'), str(kermit.id))
开发者ID:NatEvatt,项目名称:geokey,代码行数:30,代码来源:test_manager.py

示例4: setUp

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

        self.project = ProjectF(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            add_viewers=[self.view_member]
        )
        self.other_project = ProjectF.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:IdahoInstitute,项目名称:geokey,代码行数:28,代码来源:test_views.py

示例5: setUp

    def setUp(self):
        self.factory = RequestFactory()
        self.admin = UserF.create()
        self.contributor = UserF.create()
        self.non_member = UserF.create()

        self.project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
开发者ID:sfwatergit,项目名称:geokey,代码行数:10,代码来源:test_views.py

示例6: test_admin

    def test_admin(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        view = GroupingFactory.create(**{
            'project': project,
            'isprivate': False
        })

        self.assertTrue(view.can_view(user))
        self.assertTrue(view.can_read(user))
        self.assertTrue(view.can_moderate(user))
开发者ID:IdahoInstitute,项目名称:geokey,代码行数:11,代码来源:test_model.py

示例7: test_get_update_projects

    def test_get_update_projects(self):
        # Setup everything
        updated_project_1 = ProjectF.create()
        updated_project_2 = ProjectF.create()
        not_updated_project = ProjectF.create()

        for x in range(0, 2):
            for project in [
                    updated_project_1, updated_project_2, not_updated_project]:
                ObservationFactory.create(project=project)

        updated = ObservationFactory.create(project=updated_project_2)

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        ObservationFactory.create(project=updated_project_1)
        updated.update(attributes={'key': 'value'}, updator=UserF.create())

        # the tests
        command = Command()
        updated_projects = command.get_updated_projects(yesterday)
        self.assertIn(updated_project_1, updated_projects)
        self.assertIn(updated_project_2, updated_projects)
        self.assertNotIn(not_updated_project, updated_projects)
开发者ID:NatEvatt,项目名称:geokey,代码行数:24,代码来源:test_commands.py

示例8: setUp

    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserF.create()
        self.creator = UserF.create()
        self.viewer = UserF.create()
        self.project = ProjectF(
            add_admins=[self.admin],
            add_contributors=[self.creator]
        )

        self.contribution = ObservationFactory.create(
            **{'project': self.project, 'creator': self.creator}
        )

        ImageFileFactory.create_batch(5, **{'contribution': self.contribution})
开发者ID:sfwatergit,项目名称:geokey,代码行数:15,代码来源:test_views.py

示例9: test_daily_digest

    def test_daily_digest(self):
        moderator = UserF.create()
        contributor = UserF.create()
        UserF.create()

        project = ProjectF.create(
            add_admins=[moderator],
            add_contributors=[contributor]
        )

        suspended = ObservationFactory.create(
            created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
            project=project,
            creator=contributor,
            status='active'
        )

        updated = ObservationFactory.create(
            project=project,
            creator=contributor
        )

        approved = ObservationFactory.create(
            project=project,
            creator=contributor,
            status='pending'
        )

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        suspended.update(
            attributes=None,
            status='pending',
            updator=UserF.create()
        )
        updated.update(attributes={'key': 'value'}, updator=UserF.create())
        approved.update(attributes=None, status='active', updator=moderator)

        for user in [moderator, contributor]:
            ObservationFactory.create(
                project=project,
                creator=user,
                status='pending'
            )

        command = Command()
        command.send_daily_digest(yesterday)
        self.assertEquals(len(mail.outbox), 3)
开发者ID:NatEvatt,项目名称:geokey,代码行数:48,代码来源:test_commands.py

示例10: test_multiple_lookup

    def test_multiple_lookup(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        lookup = MultipleLookupFieldFactory.create(
            **{'category': category, 'key': 'lookup'}
        )
        kermit = MultipleLookupValueFactory.create(**{
            'field': lookup,
            'name': 'Kermit'
        })
        gonzo = MultipleLookupValueFactory.create(**{
            'field': lookup,
            'name': 'Gonzo'
        })
        piggy = MultipleLookupValueFactory.create(**{
            'field': lookup,
            'name': 'Ms Piggy'
        })
        ObservationFactory.create_batch(3, **{
            'project': project,
            'category': category,
            'attributes': {'lookup': [piggy.id, kermit.id]}
        })
        ObservationFactory.create_batch(3, **{
            'project': project,
            'category': category,
            'attributes': {'lookup': [gonzo.id]}
        })

        result = project.observations.all().search('kermit')
        self.assertEqual(len(result), 3)

        for o in result:
            self.assertIn(kermit.id, json.loads(o.attributes.get('lookup')))

        result = project.observations.all().search('piggy')
        self.assertEqual(len(result), 3)

        for o in result:
            self.assertIn(kermit.id, json.loads(o.attributes.get('lookup')))
开发者ID:NatEvatt,项目名称:geokey,代码行数:40,代码来源:test_manager.py

示例11: test_get_update_stats

    def test_get_update_stats(self):
        moderator = UserF.create()
        contributor = UserF.create()
        some_dude = UserF.create()

        project = ProjectF.create(
            add_admins=[moderator],
            add_contributors=[contributor]
        )

        suspended = ObservationFactory.create(
            created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
            project=project,
            creator=contributor,
            status='active'
        )

        updated = ObservationFactory.create(
            project=project,
            creator=contributor
        )

        approved = ObservationFactory.create(
            project=project,
            creator=contributor,
            status='pending'
        )

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        suspended.update(
            attributes=None,
            status='pending',
            updator=UserF.create()
        )
        updated.update(attributes={'key': 'value'}, updator=UserF.create())
        approved.update(attributes=None, status='active', updator=moderator)

        for user in [moderator, contributor]:
            ObservationFactory.create(
                project=project,
                creator=user,
                status='pending'
            )

        command = Command()

        report = command.get_updated_items(project, moderator, yesterday)
        to_moderate = report.get('to_moderate')
        self.assertEqual(len(to_moderate.get('new')), 2)
        self.assertEqual(len(to_moderate.get('suspended')), 1)
        self.assertIsNone(report.get('yours'))

        report = command.get_updated_items(project, contributor, yesterday)

        yours = report.get('yours')
        self.assertEqual(len(yours.get('changed')), 3)
        self.assertEqual(len(yours.get('approved')), 1)
        self.assertEqual(len(yours.get('suspended')), 1)

        report = command.get_updated_items(project, some_dude, yesterday)
        self.assertEqual(report, None)
开发者ID:NatEvatt,项目名称:geokey,代码行数:62,代码来源:test_commands.py

示例12: AllContributionsMediaAPIViewTest

class AllContributionsMediaAPIViewTest(TestCase):
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserF.create()
        self.creator = UserF.create()
        self.viewer = UserF.create()
        self.project = ProjectF(
            add_admins=[self.admin],
            add_contributors=[self.creator]
        )

        self.contribution = ObservationFactory.create(
            **{'project': self.project, 'creator': self.creator}
        )

        ImageFileFactory.create_batch(5, **{'contribution': self.contribution})

    def tearDown(self):
        files = glob.glob(os.path.join(
            settings.MEDIA_ROOT,
            'user-uploads/images/*'
        ))
        for f in files:
            os.remove(f)

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

        request = self.factory.get(url)
        force_authenticate(request, user)
        view = AllContributionsMediaAPIView.as_view()
        return view(
            request,
            project_id=self.project.id,
            contribution_id=self.contribution.id
        ).render()

    def post(self, user, data=None):
        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()

    def test_get_images_with_admin(self):
        response = self.get(self.admin)
        self.assertEqual(response.status_code, 200)

    def test_get_images_with_contributor(self):
        response = self.get(self.creator)
        self.assertEqual(response.status_code, 200)

    def test_get_images_with_some_dude(self):
        response = self.get(UserF.create())
        self.assertEqual(response.status_code, 404)

    def test_get_images_with_anonymous(self):
        response = self.get(AnonymousUser())
        self.assertEqual(response.status_code, 404)

    def test_upload_image_with_admin(self):
        response = self.post(self.admin)
        self.assertEqual(response.status_code, 201)

    def test_upload_image_with_contributor(self):
        response = self.post(self.creator)
        self.assertEqual(response.status_code, 201)

    def test_upload_image_with_some_dude(self):
        response = self.post(UserF.create())
        self.assertEqual(response.status_code, 404)

    def test_upload_image_with_anonymous(self):
        response = self.post(AnonymousUser())
        self.assertEqual(response.status_code, 404)

#.........这里部分代码省略.........
开发者ID:sfwatergit,项目名称:geokey,代码行数:101,代码来源:test_views.py


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