• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python fields.SerializedObjectField类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_serialize_of_object

    def test_serialize_of_object(self):
        """Test if object is propertly serialized to json"""

        json_field = SerializedObjectField()
        
        self.assertEqual(json_field._serialize(self.profile),
                    '[{"pk": 1, "model": "test_app.userprofile", "fields": '\
                    '{"url": "http://www.google.com", "user": 1, '\
                    '"description": "Profile description"}}]',
                         )
开发者ID:bx2,项目名称:django-moderation,代码行数:10,代码来源:test_models.py


示例2: test_deserialize

    def test_deserialize(self):
        value = '[{"pk": 1, "model": "test_app1.userprofile", "fields": '\
                '{"url": "http://www.google.com", "user": 1, '\
                '"description": "Profile description"}}]'
        json_field = SerializedObjectField()
        object = json_field._deserialize(value)

        self.assertEqual(repr(object),
                         '<UserProfile: moderator - http://www.google.com>')
        self.assertTrue(isinstance(object, UserProfile))
开发者ID:EBNull,项目名称:django-moderation,代码行数:10,代码来源:models.py


示例3: test_deserialize_proxy_model

    def test_deserialize_proxy_model(self):
        "Correctly restore a proxy model."
        value = '[{"pk": 2, "model": "tests.proxyprofile", "fields": '\
            '{"url": "http://example.com", "user": 2, '\
            '"description": "I\'m a proxy."}}]'

        json_field = SerializedObjectField()
        profile = json_field._deserialize(value)
        self.assertTrue(isinstance(profile, ProxyProfile))
        self.assertEqual(profile.url, "http://example.com")
        self.assertEqual(profile.description, "I\'m a proxy.")
        self.assertEqual(profile.user_id, 2)
开发者ID:SamTShaw,项目名称:django-moderation,代码行数:12,代码来源:models.py


示例4: test_serialize_of_object

    def test_serialize_of_object(self):
        """Test if object is properly serialized to json"""

        json_field = SerializedObjectField()

        serialized_str = json_field._serialize(self.profile)

        self.assertIn('"pk": 1', serialized_str)
        self.assertIn('"model": "tests.userprofile"', serialized_str)
        self.assertIn('"fields": {', serialized_str)
        self.assertIn('"url": "http://www.google.com"', serialized_str)
        self.assertIn('"user": 1', serialized_str)
        self.assertIn('"description": "Old description"', serialized_str)
开发者ID:SamTShaw,项目名称:django-moderation,代码行数:13,代码来源:models.py


示例5: test_deserialize_with_inheritance

    def test_deserialize_with_inheritance(self):
        value = '[{"pk": 2, "model": "test_app1.superuserprofile",'\
                ' "fields": {"super_power": "invisibility"}}, '\
                '{"pk": 2, "model": "test_app1.userprofile", "fields":'\
                ' {"url": "http://www.test.com", "user": 2,'\
                ' "description": "Profile for new super user"}}]'

        json_field = SerializedObjectField()
        object = json_field._deserialize(value)

        self.assertTrue(isinstance(object, SuperUserProfile))
        self.assertEqual(repr(object),
                '<SuperUserProfile: user1 - http://www.test.com - invisibility>')
开发者ID:Inkvi,项目名称:django-moderation,代码行数:13,代码来源:models.py


示例6: test_serialize_proxy_model

    def test_serialize_proxy_model(self):
        "Handle proxy models in the serialization."
        profile = ProxyProfile(description="I'm a proxy.",
                               url="http://example.com",
                               user=User.objects.get(username='user1'))
        profile.save()
        json_field = SerializedObjectField()

        self.assertEqual(
            json_field._serialize(profile),
            '[{"pk": 2, "model": "tests.proxyprofile", "fields": '
            '{"url": "http://example.com", "user": 2, '
            '"description": "I\'m a proxy."}}]',)
开发者ID:adityar7,项目名称:django-moderation,代码行数:13,代码来源:models.py


示例7: test_serialize_proxy_model

    def test_serialize_proxy_model(self):
        "Handle proxy models in the serialization."
        profile = ProxyProfile(description="I'm a proxy.",
                               url="http://example.com",
                               user=User.objects.get(username='user1'))
        profile.save()
        json_field = SerializedObjectField()

        serialized_str = json_field._serialize(profile)

        self.assertIn('"pk": 2', serialized_str)
        self.assertIn('"model": "tests.proxyprofile"', serialized_str)
        self.assertIn('"url": "http://example.com"', serialized_str)
        self.assertIn('"user": 2', serialized_str)
        self.assertIn('"description": "I\'m a proxy."', serialized_str)
        self.assertIn('"fields": {', serialized_str)
开发者ID:SamTShaw,项目名称:django-moderation,代码行数:16,代码来源:models.py


示例8: test_serialize_of_many_objects

    def test_serialize_of_many_objects(self):
        """Test if object is propertly serialized to json"""

        profile = UserProfile(description='Profile for new user',
                    url='http://www.test.com',
                    user=User.objects.get(username='user1'))
        profile.save()
        json_field = SerializedObjectField()
        
        self.assertEqual(json_field._serialize(UserProfile.objects.all()),
                       '[{"pk": 1, "model": "test_app.userprofile", '\
                       '"fields": {"url": "http://www.google.com",'\
                       ' "user": 1, "description": "Profile description"}},'\
                       ' {"pk": 2, "model": "test_app.userprofile", "fields":'\
                       ' {"url": "http://www.test.com", "user": 2, '\
                       '"description": "Profile for new user"}}]')
开发者ID:bx2,项目名称:django-moderation,代码行数:16,代码来源:test_models.py


示例9: test_serialize_with_inheritance

    def test_serialize_with_inheritance(self):
        """Test if object is properly serialized to json"""

        profile = SuperUserProfile(description='Profile for new super user',
                    url='http://www.test.com',
                    user=User.objects.get(username='user1'),
                    super_power='invisibility')
        profile.save()
        json_field = SerializedObjectField()
        
        self.assertEqual(json_field._serialize(profile),
                        '[{"pk": 2, "model": "test_app1.superuserprofile",'\
                        ' "fields": {"super_power": "invisibility"}}, '\
                        '{"pk": 2, "model": "test_app1.userprofile", "fields":'\
                        ' {"url": "http://www.test.com", "user": 2,'\
                        ' "description": "Profile for new super user"}}]')
开发者ID:Inkvi,项目名称:django-moderation,代码行数:16,代码来源:models.py


示例10: test_deserialize_many_objects

    def test_deserialize_many_objects(self):
        value = '[{"pk": 1, "model": "test_app.userprofile", '\
                '"fields": {"url": "http://www.google.com",'\
                ' "user": 1, "description": "Profile description"}},'\
                ' {"pk": 2, "model": "test_app.userprofile", "fields":'\
                ' {"url": "http://www.yahoo.com", "user": 2, '\
                '"description": "Profile description 2"}}]'

        json_field = SerializedObjectField()
        objects = json_field._deserialize(value)

        self.assertTrue(isinstance(objects, list))

        self.assertTrue(isinstance(objects[0], UserProfile))
        self.assertEqual(repr(objects[0]),
                         '<UserProfile: moderator - http://www.google.com>')

        self.assertTrue(isinstance(objects[1], UserProfile))
        self.assertEqual(repr(objects[1]),
                         '<UserProfile: user1 - http://www.yahoo.com>')
开发者ID:bx2,项目名称:django-moderation,代码行数:20,代码来源:test_models.py


示例11: test_serialize_with_inheritance

    def test_serialize_with_inheritance(self):
        """Test if object is properly serialized to json"""

        profile = SuperUserProfile(description='Profile for new super user',
                                   url='http://www.test.com',
                                   user=User.objects.get(username='user1'),
                                   super_power='invisibility')
        profile.save()
        json_field = SerializedObjectField()

        serialized_str = json_field._serialize(profile)

        self.assertIn('"pk": 2', serialized_str)
        self.assertIn('"model": "tests.superuserprofile"', serialized_str)
        self.assertIn('"fields": {"super_power": "invisibility"}',
                      serialized_str)
        self.assertIn('"pk": 2', serialized_str)
        self.assertIn('"model": "tests.userprofile"', serialized_str)
        self.assertIn('"url": "http://www.test.com"', serialized_str)
        self.assertIn('"user": 2', serialized_str)
        self.assertIn('"description": "Profile for new super user"',
                      serialized_str)
        self.assertIn('"fields": {', serialized_str)
开发者ID:SamTShaw,项目名称:django-moderation,代码行数:23,代码来源:models.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.ModeratedObject类代码示例发布时间:2022-05-27
下一篇:
Python diff.get_changes_between_models函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap