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


Python ProjectF.create方法代码示例

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


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

示例1: test_post_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    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:nagyistoce,项目名称:geokey,代码行数:29,代码来源:test_views.py

示例2: setUp

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    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:oliverroick,项目名称:geokey,代码行数:15,代码来源:test_views.py

示例3: test_post_non_existing_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_post_non_existing_with_admin(self):
        """
        Update the view with project admin should render an error message
        """
        project = ProjectF.create()
        user = project.creator

        self.request.user = user
        self.request.method = 'POST'
        self.request.POST = {
            'name': 'Name',
            'description': 'Description',
        }

        response = self.view(
            self.request,
            project_id=project.id,
            subset_id=634842156456).render()

        rendered = render_to_string(
            'subsets/subsets_settings.html',
            {
                'error_description': 'Subset matching query does not exist.',
                'error': 'Not found.',
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)
开发者ID:nagyistoce,项目名称:geokey,代码行数:33,代码来源:test_views.py

示例4: test_post_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_post_with_admin(self):
        """
        Updating with project admin should create the subset and redirect to
        the subset data page.
        """
        self.request.method = 'POST'
        self.request.POST = {
            'name': 'Name',
            'description': 'Description',
        }

        project = ProjectF.create()
        user = project.creator

        self.request.user = user
        response = self.view(self.request, project_id=project.id)

        self.assertEqual(1, Subset.objects.count())
        subset = Subset.objects.first()
        self.assertEqual(subset.name, 'Name')
        self.assertEqual(subset.description, 'Description')
        self.assertEqual(subset.project, project)
        self.assertEqual(subset.creator, user)

        self.assertEqual(response.status_code, 302)
        self.assertIn(
            '/admin/projects/%s/subsets/%s/' % (project.id, subset.id),
            response['location']
        )
开发者ID:nagyistoce,项目名称:geokey,代码行数:31,代码来源:test_views.py

示例5: test_post_with_user

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_post_with_user(self):
        """
        Updating with normal user should render the page with an
        error message
        """
        self.request.method = 'POST'
        self.request.POST = {
            'name': 'Name',
            'description': 'Description',
        }

        user = UserF.create()
        project = ProjectF.create()

        self.request.user = user
        response = self.view(self.request, project_id=project.id).render()

        rendered = render_to_string(
            'subsets/subsets_create.html',
            {
                'error_description': 'Project matching query does not exist.',
                'error': 'Not found.',
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)
        self.assertEqual(0, Subset.objects.count())
开发者ID:nagyistoce,项目名称:geokey,代码行数:32,代码来源:test_views.py

示例6: test_post_with_admin_no_rules

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_post_with_admin_no_rules(self):
        view = RuleSettings.as_view()
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        grouping = GroupingFactory.create(**{'project': project})
        rule = RuleFactory.create(**{'grouping': grouping})

        data = {
            'category': category.id
        }

        url = reverse(
            'admin:rule_settings',
            kwargs={
                'project_id': project.id,
                'grouping_id': grouping.id,
                'rule_id': rule.id
            }
        )
        request = APIRequestFactory().post(url, data)
        request.user = project.creator

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

        response = view(
            request,
            project_id=project.id,
            grouping_id=grouping.id,
            rule_id=rule.id)

        self.assertEqual(response.status_code, 302)
开发者ID:tainita01,项目名称:geokey,代码行数:36,代码来源:test_views.py

示例7: test_post_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_post_with_admin(self):
        data = {
            'name': 'Grouping',
            'description': ''
        }

        view = GroupingSettings.as_view()
        project = ProjectF.create()
        grouping = GroupingFactory.create(**{'project': project})

        url = reverse(
            'admin:grouping_settings',
            kwargs={'project_id': project.id, 'grouping_id': grouping.id}
        )
        request = APIRequestFactory().post(url, data)
        request.user = project.creator

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

        response = view(
            request,
            project_id=project.id,
            grouping_id=grouping.id)
        self.assertEqual(response.status_code, 200)
开发者ID:tainita01,项目名称:geokey,代码行数:29,代码来源:test_views.py

示例8: setUp

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    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:tainita01,项目名称:geokey,代码行数:30,代码来源:test_views.py

示例9: test_delete_with_user

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_delete_with_user(self):
        user = UserF.create()
        view = RuleDelete.as_view()
        project = ProjectF.create(add_contributors=[user])
        grouping = GroupingFactory.create(**{'project': project})
        rule = RuleFactory.create(**{'grouping': grouping})

        url = reverse(
            'admin:rule_delete',
            kwargs={
                'project_id': project.id,
                'grouping_id': grouping.id,
                'rule_id': rule.id
            }
        )

        request = APIRequestFactory().get(url)
        request.user = user

        response = view(
            request,
            project_id=project.id,
            grouping_id=grouping.id,
            rule_id=rule.id).render()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(Rule.objects.count(), 1)
        self.assertContains(
            response,
            'You are not member of the administrators group of this project '
            'and therefore not allowed to alter the settings of the project'
        )
开发者ID:tainita01,项目名称:geokey,代码行数:34,代码来源:test_views.py

示例10: test_get_data_combined

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_get_data_combined(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        category_1 = CategoryFactory(**{'project': project})
        category_2 = CategoryFactory(**{'project': project})
        category_3 = CategoryFactory(**{'project': project})
        view = GroupingFactory(**{'project': project})
        for x in range(0, 5):
            ObservationFactory.create(**{
                'project': project,
                'category': category_1}
            )
            ObservationFactory.create(**{
                'project': project,
                'category': category_2}
            )
            ObservationFactory.create(**{
                'project': project,
                'category': category_3}
            )

        RuleFactory(**{
            'grouping': view,
            'category': category_1
        })
        RuleFactory(**{
            'grouping': view,
            'category': category_2
        })

        self.assertEqual(view.data(user).count(), 10)
        for observation in view.data(user):
            self.assertNotEqual(
                observation.category, category_3)
开发者ID:tainita01,项目名称:geokey,代码行数:36,代码来源:test_model.py

示例11: test

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test(self):
        admin = UserF.create()
        project = ProjectF.create(add_admins=[admin])
        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'text',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1,
            'properties': {'text': 'yes'}}
        )

        viewer = UserF.create()
        view = GroupingFactory(add_viewers=[viewer], **{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'text': 'yes'}
        })

        serializer = GroupingSerializer(view, context={'user': admin})
        self.assertEqual(len(serializer.get_data(view).get('features')), 5)
        self.assertEqual(serializer.get_num_contributions(view), 5)
开发者ID:tainita01,项目名称:geokey,代码行数:33,代码来源:test_serializer.py

示例12: test_delete_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_delete_with_admin(self):
        view = RuleDelete.as_view()
        project = ProjectF.create()
        grouping = GroupingFactory.create(**{'project': project})
        rule = RuleFactory.create(**{'grouping': grouping})

        url = reverse(
            'admin:rule_delete',
            kwargs={
                'project_id': project.id,
                'grouping_id': grouping.id,
                'rule_id': rule.id
            }
        )

        request = APIRequestFactory().get(url)
        request.user = project.creator

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

        response = view(
            request,
            project_id=project.id,
            grouping_id=grouping.id,
            rule_id=rule.id)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(Rule.objects.count(), 0)
开发者ID:tainita01,项目名称:geokey,代码行数:33,代码来源:test_views.py

示例13: test_single_lookup

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    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,
            'properties': {'lookup': kermit.id}
        })
        ObservationFactory.create_batch(3, **{
            'project': project,
            'category': category,
            'properties': {'lookup': gonzo.id}
        })

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

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

示例14: test_update_where_clause

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_update_where_clause(self):
        project = ProjectF.create()
        cat_1 = CategoryFactory.create(**{'project': project})
        cat_2 = CategoryFactory.create(**{'project': project})
        usergroup = UserGroupF.create(**{'project': project})
        usergroup.filters = {
            cat_1.id: {},
            cat_2.id: {}
        }
        usergroup.save()

        self.assertIn(
            UserGroup.objects.get(pk=usergroup.id).where_clause,
            [
                '((category_id = %s)) OR ((category_id = %s))' % (
                    cat_2.id, cat_1.id
                ),
                '((category_id = %s)) OR ((category_id = %s))' % (
                    cat_1.id, cat_2.id
                )
            ]
        )

        usergroup.filters = {}
        usergroup.save()

        self.assertEqual(
            UserGroup.objects.get(pk=usergroup.id).where_clause,
            'FALSE'
        )
开发者ID:oliverroick,项目名称:geokey,代码行数:32,代码来源:test_models.py

示例15: test_get_with_admin

# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
    def test_get_with_admin(self):
        view = RuleSettings.as_view()
        project = ProjectF.create()
        grouping = GroupingFactory.create(**{'project': project})
        rule = RuleFactory.create(**{'grouping': grouping})

        url = reverse(
            'admin:rule_settings',
            kwargs={
                'project_id': project.id,
                'grouping_id': grouping.id,
                'rule_id': rule.id
            }
        )
        request = APIRequestFactory().get(url)
        request.user = project.creator

        response = view(
            request,
            project_id=project.id,
            grouping_id=grouping.id,
            rule_id=rule.id).render()

        self.assertEqual(response.status_code, 200)
        self.assertNotContains(
            response,
            'You are not member of the administrators group of this project '
            'and therefore not allowed to alter the settings of the project'
        )
开发者ID:tainita01,项目名称:geokey,代码行数:31,代码来源:test_views.py


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