當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.SerializedObjectField類代碼示例

本文整理匯總了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;未經允許,請勿轉載。