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


Python CategoryFactory.create方法代码示例

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


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

示例1: test_update_where_clause

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory 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

示例2: test_get_context_data

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_get_context_data(self):
        """Test getting context data."""
        user = UserFactory.create(**{'is_superuser': True})

        # 1 contribution, 1 comment
        project_1 = ProjectFactory.create()
        category_1 = CategoryFactory.create(project=project_1)
        contribution_1 = ObservationFactory.create(
            project=project_1,
            category=category_1)
        CommentFactory.create(commentto=contribution_1)

        # 2 contributions (1 deleted), 2 comments
        project_2 = ProjectFactory.create(add_admins=[user])
        category_2 = CategoryFactory.create(project=project_2)
        contribution_2 = ObservationFactory.create(
            project=project_2,
            category=category_2)
        CommentFactory.create(commentto=contribution_2)
        contribution_3 = ObservationFactory.create(
            project=project_2,
            category=category_2)
        CommentFactory.create(commentto=contribution_3)
        contribution_3.delete()

        # 2 contributions (1 deleted), 3 comments (1 deleted)
        project_3 = ProjectFactory.create(add_moderators=[user])
        category_3 = CategoryFactory.create(project=project_3)
        contribution_4 = ObservationFactory.create(
            project=project_3,
            category=category_3)
        CommentFactory.create(commentto=contribution_4)
        comment_to_delete = CommentFactory.create(commentto=contribution_4)
        comment_to_delete.delete()
        contribution_5 = ObservationFactory.create(
            project=project_3,
            category=category_3)
        CommentFactory.create(commentto=contribution_5)
        contribution_5.delete()

        # 1 contribution, 2 comments (1 deleted)
        project_4 = ProjectFactory.create(add_contributors=[user])
        category_4 = CategoryFactory.create(project=project_4)
        contribution_6 = ObservationFactory.create(
            project=project_4,
            category=category_4)
        CommentFactory.create(commentto=contribution_6)
        comment_to_delete = CommentFactory.create(commentto=contribution_6)
        comment_to_delete.delete()

        view = ManageProjects()
        context = view.get_context_data()
        self.assertEqual(len(context.get('projects')), 4)

        for project in context.get('projects'):
            project.refresh_from_db()
            self.assertEqual(project.contributions_count, 1)
            self.assertEqual(project.comments_count, 1)
            self.assertEqual(project.media_count, 0)
开发者ID:ExCiteS,项目名称:geokey,代码行数:61,代码来源:test_views.py

示例3: setUp

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def setUp(self):
        self.factory = APIRequestFactory()
        self.project = ProjectFactory.create()

        self.category_0 = CategoryFactory.create(**{'project': self.project})
        self.category_1 = CategoryFactory.create(**{'project': self.project})
        self.category_2 = CategoryFactory.create(**{'project': self.project})
        self.category_3 = CategoryFactory.create(**{'project': self.project})
        self.category_4 = CategoryFactory.create(**{'project': self.project})
开发者ID:ExCiteS,项目名称:geokey,代码行数:11,代码来源:test_views.py

示例4: test_upload_data_to_private_project

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_upload_data_to_private_project(self):
        project = ProjectFactory.create()
        type1 = CategoryFactory.create(**{'project': project})
        field = TextFieldFactory(**{'category': type1})

        data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
                '20&location_alt=&location_bearing=&category={category}&'
                '{field_key}_{category}=Westbourne+Park'.format(
                    category=type1.id,
                    field_key=field.key)
                )

        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:upload', kwargs={
            'project_id': project.id
        })
        request = factory.post(
            url + '?type=data',
            data,
            content_type='application/x-www-form-urlencoded'
        )

        view = EpiCollectUploadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '0')
开发者ID:ExCiteS,项目名称:geokey-epicollect,代码行数:28,代码来源:test_views.py

示例5: test_upload_checkboxes

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_upload_checkboxes(self):
        project = ProjectFactory.create(
            **{'isprivate': False, 'everyone_contributes': True}
        )
        EpiCollectProjectModel.objects.create(project=project, enabled=True)
        type1 = CategoryFactory.create(**{'project': project})
        field = MultipleLookupFieldFactory(**{'category': type1})
        val_1 = MultipleLookupValueFactory(**{'field': field})
        val_2 = MultipleLookupValueFactory(**{'field': field})

        data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
                '20&location_alt=&location_bearing=&category={category}&'
                '{field_key}_{category}={checkbox_1}%2c+{checkbox_2}'.format(
                    category=type1.id,
                    field_key=field.key,
                    checkbox_1=val_1.id,
                    checkbox_2=val_2.id
                ))

        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:upload', kwargs={
            'project_id': project.id
        })
        request = factory.post(
            url + '?type=data',
            data,
            content_type='application/x-www-form-urlencoded'
        )

        view = EpiCollectUploadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '1')
开发者ID:ExCiteS,项目名称:geokey-epicollect,代码行数:35,代码来源:test_views.py

示例6: test_upload_data_without_location

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_upload_data_without_location(self):
        project = ProjectFactory.create(
            **{'isprivate': False, 'everyone_contributes': True}
        )
        EpiCollectProjectModel.objects.create(project=project, enabled=True)
        type1 = CategoryFactory.create(**{'project': project})
        field = TextFieldFactory(**{'category': type1})

        data = ('category={category}&{field_key}_{category}=Westbourne+'
                'Park'.format(
                    category=type1.id,
                    field_key=field.key)
                )

        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:upload', kwargs={
            'project_id': project.id
        })
        request = factory.post(
            url + '?type=data',
            data,
            content_type='application/x-www-form-urlencoded'
        )

        view = EpiCollectUploadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '0')
开发者ID:ExCiteS,项目名称:geokey-epicollect,代码行数:30,代码来源:test_views.py

示例7: test_upload_data_with_media

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_upload_data_with_media(self):
        project = ProjectFactory.create(
            **{'isprivate': False, 'everyone_contributes': True}
        )
        EpiCollectProjectModel.objects.create(project=project, enabled=True)
        type1 = CategoryFactory.create(**{'project': project})
        field = TextFieldFactory(**{'category': type1})

        data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
                '20&location_alt=&location_bearing=&category={category}&'
                '{field_key}_{category}=Westbourne+Park&photo=abc&'
                'video=def'.format(
                    category=type1.id,
                    field_key=field.key)
                )

        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:upload', kwargs={
            'project_id': project.id
        })
        request = factory.post(
            url + '?type=data',
            data,
            content_type='application/x-www-form-urlencoded'
        )

        view = EpiCollectUploadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(EpiCollectMedia.objects.count(), 2)
        self.assertEqual(response.content, '1')
开发者ID:ExCiteS,项目名称:geokey-epicollect,代码行数:33,代码来源:test_views.py

示例8: test_show_restrict

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
 def test_show_restrict(self):
     category = CategoryFactory.create()
     self.assertEqual(
         filter_tags.show_restrict({str(category.id): {}}, category),
         '<a href="#" class="text-danger activate-detailed">' "Restrict further</a>",
     )
     self.assertEqual(filter_tags.show_restrict({"2": {}}, category), "")
开发者ID:ExCiteS,项目名称:geokey,代码行数:9,代码来源:test_templatetags.py

示例9: test_post_with_admin

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

        data = {
            'category': category.id,
            'rules': json.dumps({
                'text': 'blah',
                'min_date': '2015-01-01',
                'max_date': '2015-10-01'
            })
        }

        url = reverse(
            'admin:rule_create',
            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, 302)
        self.assertEqual(Rule.objects.count(), 1)
开发者ID:tainita01,项目名称:geokey,代码行数:36,代码来源:test_views.py

示例10: test_post_save_when_category_made_inactive

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_post_save_when_category_made_inactive(self):

        project = ProjectFactory.create(status='active')
        category = CategoryFactory.create(project=project)

        aq_project = AirQualityProjectFactory.create(
            status='active',
            project=project
        )
        aq_category = AirQualityCategoryFactory.create(
            category=category,
            project=aq_project
        )

        category.status = 'inactive'
        category.save

        post_save_category(Category, instance=category)

        reference = AirQualityProject.objects.get(pk=aq_project.id)
        self.assertEqual(reference.status, 'inactive')
        self.assertEqual(
            AirQualityCategory.objects.filter(pk=aq_category.id).exists(),
            False
        )
        self.assertEquals(len(mail.outbox), 1)
开发者ID:ExCiteS,项目名称:geokey-airquality,代码行数:28,代码来源:test_models.py

示例11: test_create_search_index

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_create_search_index(self):
        category = CategoryFactory.create()
        TextFieldFactory.create(
            **{'key': 'text_1', 'category': category, 'order': 0}
        )
        TextFieldFactory.create(
            **{'key': 'text_2', 'category': category, 'order': 0}
        )
        TextFieldFactory.create(
            **{'key': 'text_3', 'category': category, 'order': 0}
        )
        o = ObservationFactory.create(**{
            'properties': {
                'text_1': 'Blah, abc',
                'text_2': 'blubb blah'
            },
            'category': category
        })
        o.create_search_index()
        o.save()

        reference = Observation.objects.get(pk=o.id)
        self.assertEqual(
            reference.search_index.split(',').sort(),
            'blah,abc,blubb'.split(',').sort()
        )
开发者ID:Josh1billion,项目名称:geokey,代码行数:28,代码来源:test_model.py

示例12: test_single_lookup

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory 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

示例13: test_filters

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_filters(self):
        category = CategoryFactory.create()
        TextFieldFactory.create(**{'category': category, 'key': 'text'})
        NumericFieldFactory.create(**{'category': category, 'key': 'number'})
        DateFieldFactory.create(**{'category': category, 'key': 'date'})
        DateTimeFieldFactory.create(
            **{'category': category, 'key': 'datetime'})
        TimeFieldFactory.create(**{'category': category, 'key': 'time'})
        lookup = LookupFieldFactory.create(
            **{'category': category, 'key': 'lookup'})
        val_1 = LookupValueFactory.create(**{'field': lookup})
        multiple = MultipleLookupFieldFactory.create(
            **{'category': category, 'key': 'multiple'})
        mul_1 = MultipleLookupValueFactory.create(**{'field': multiple})

        rule = RuleFactory.create(**{
            'category': category,
            'min_date': datetime.datetime(2007, 12, 5, 12, 00),
            'max_date': datetime.datetime(2012, 12, 5, 15, 00),
            'constraints': {
                'text': 'blah',
                'number': {'minval': 0, 'maxval': 10},
                'date': {'minval': 0, 'maxval': 10},
                'datetime': {'minval': 0, 'maxval': 10},
                'time': {'minval': 0, 'maxval': 10},
                'lookup': [val_1.id],
                'multiple': [mul_1.id]
            }
        })

        result = filters(rule)
        self.assertEqual(result.count('<li>'), 8)
开发者ID:tainita01,项目名称:geokey,代码行数:34,代码来源:test_template_tags.py

示例14: test_log_create

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import create [as 别名]
    def test_log_create(self):
        """Test when category gets created."""
        log_count_init = LoggerHistory.objects.count()
        category = CategoryFactory.create(**{
            'creator': self.user,
            'project': self.project})

        log = LoggerHistory.objects.last()
        log_count = LoggerHistory.objects.count()

        self.assertNotEqual(log.user, {
            'id': str(self.user.id),
            'display_name': self.user.display_name})
        self.assertEqual(log.project, {
            'id': str(self.project.id),
            'name': self.project.name})
        self.assertEqual(log.usergroup, None)
        self.assertEqual(log.category, {
            'id': str(category.id),
            'name': category.name})
        self.assertEqual(log.field, None)
        self.assertEqual(log.location, None)
        self.assertEqual(log.observation, None)
        self.assertEqual(log.comment, None)
        self.assertEqual(log.subset, None)
        self.assertEqual(log.action, {
            'id': 'created',
            'class': 'Category'})
        self.assertEqual(log_count, log_count_init + 1)
        self.assertEqual(log.historical, None)
开发者ID:ExCiteS,项目名称:geokey,代码行数:32,代码来源:test_log_category.py

示例15: test_post_with_admin_no_rules

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory 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


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