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


Python CategoryFactory.save方法代码示例

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


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

示例1: test_update_expiry_field

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import save [as 别名]
    def test_update_expiry_field(self):
        category = CategoryFactory()
        field = DateTimeFieldFactory(**{
            'key': 'expires_at',
            'category': category
        })
        category.expiry_field = field
        category.save()

        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'expiry_field': None,
            'properties': {
                'expires_at': '2016-09-19T15:51:32.804Z'
            }
        })

        observation.update_expiry_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertEqual(
            ref.expiry_field,
            datetime.datetime(2016, 9, 19, 15, 51, 32, 804000, tzinfo=pytz.utc)
        )
开发者ID:ExCiteS,项目名称:geokey,代码行数:28,代码来源:test_models.py

示例2: test_update_expiry_field_empty_properties

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import save [as 别名]
    def test_update_expiry_field_empty_properties(self):
        category = CategoryFactory()
        field = DateTimeFieldFactory(**{
            'key': 'expires_at',
            'category': category
        })
        category.expiry_field = field
        category.save()

        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'expiry_field': None,
            'properties': {}
        })

        observation.update_expiry_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertEqual(ref.expiry_field, None)
开发者ID:ExCiteS,项目名称:geokey,代码行数:23,代码来源:test_models.py

示例3: test_update_display_field_empty_properties

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import save [as 别名]
    def test_update_display_field_empty_properties(self):
        category = CategoryFactory()
        field = TextFieldFactory(**{
            'key': 'text',
            'category': category,
            'order': 0
        })
        category.display_field = field
        category.save()

        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'display_field': None,
            'properties': None
        })

        observation.update_display_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertEqual(ref.display_field, 'text:None')
开发者ID:nagyistoce,项目名称:geokey,代码行数:24,代码来源:test_model.py

示例4: ContributionSerializerIntegrationTests

# 需要导入模块: from geokey.categories.tests.model_factories import CategoryFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.CategoryFactory import save [as 别名]
class ContributionSerializerIntegrationTests(TestCase):
    def setUp(self):
        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.category = CategoryFactory(**{
            'status': 'active',
            'project': self.project
        })

        TextFieldFactory.create(**{
            'key': 'key_1',
            'category': self.category,
            'order': 0
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'order': 1
        })

    def test_create_observation(self):
        data = {
            "properties": {
                "key_1": "value 1",
                "key_2": 12
            },
            "meta": {
                "category": self.category.id
            },
            "location": {
                "name": "UCL",
                "description": "UCL's main quad",
                "private": True,
                "geometry": '{ "type": "Point", "coordinates": ['
                            '-0.134046077728271, 51.52439200896907] }',
            }
        }

        serializer = ContributionSerializer(
            data=data,
            context={'user': self.contributor, 'project': self.project}
        )
        serializer.is_valid()
        serializer.save()

        result = serializer.data

        self.assertEqual(
            result.get('properties').get('key_1'),
            'value 1'
        )
        self.assertEqual(
            result.get('properties').get('key_2'),
            12
        )
        self.assertEqual(
            result.get('meta').get('category').get('id'),
            self.category.id)
        self.assertEqual(
            result.get('location').get('name'), 'UCL')
        self.assertEqual(
            result.get('location').get('description'),
            "UCL's main quad")
        self.assertEqual(
            json.loads(data['location']['geometry']),
            json.loads(result['location']['geometry'])
        )

    def test_create_without_speficfied_location(self):
        data = {
            "properties": {
                "key_1": "value 1",
                "key_2": 12
            },
            "meta": {
                "category": self.category.id
            },
            "location": {
                "geometry": '{ "type": "Point", "coordinates": ['
                            '-0.134046077728271, 51.52439200896907] }',
            }
        }

        serializer = ContributionSerializer(
            data=data,
            context={'user': self.contributor, 'project': self.project}
        )
        serializer.is_valid()
        serializer.save()
        result = serializer.data

        self.assertEqual(
#.........这里部分代码省略.........
开发者ID:tainita01,项目名称:geokey,代码行数:103,代码来源:test_serializers.py


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