Пример #1
0
    def test_to_json(self):
        serializer = Serializer()

        sample_1 = self.get_sample1()
        self.assertEqual(
            serializer.to_json(sample_1),
            '{"age": 27, "date_joined": "2010-03-27", "name": "Daniel"}')
Пример #2
0
 def test_to_json_single(self):
     serializer = Serializer()
     resource = self.obj_list[0]
     self.assertEqual(
         serializer.to_json(resource),
         '{"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}'
     )
Пример #3
0
 def test_to_json_nested(self):
     serializer = Serializer()
     resource = self.obj_list[0]
     data = {
         'stuff': {
             'foo': 'bar',
             'object': resource,
         }
     }
     self.assertEqual(serializer.to_json(data), '{"stuff": {"foo": "bar", "object": {"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}}}')
Пример #4
0
 def test_to_json_nested(self):
     serializer = Serializer()
     resource = self.obj_list[0]
     data = {
         'stuff': {
             'foo': 'bar',
             'object': resource,
         }
     }
     self.assertEqual(
         serializer.to_json(data),
         '{"stuff": {"foo": "bar", "object": {"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}}}'
     )
Пример #5
0
 def test_to_json_multirepr(self):
     serializer = Serializer()
     self.assertEqual(
         serializer.to_json(self.obj_list),
         '[{"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}, {"content": "The dog ate my cat today. He looks seriously uncomfortable.", "created": "2010-03-31T20:05:00", "id": "2", "is_active": true, "resource_uri": "", "slug": "another-post", "title": "Another Post", "updated": "2010-03-31T20:05:00"}, {"content": "My neighborhood\'s been kinda weird lately, especially after the lava flow took out the corner store. Granny can hardly outrun the magma with her walker.", "created": "2010-04-01T20:05:00", "id": "4", "is_active": true, "resource_uri": "", "slug": "recent-volcanic-activity", "title": "Recent Volcanic Activity.", "updated": "2010-04-01T20:05:00"}, {"content": "Man, the second eruption came on fast. Granny didn\'t have a chance. On the upshot, I was able to save her walker and I got a cool shawl out of the deal!", "created": "2010-04-02T10:05:00", "id": "6", "is_active": true, "resource_uri": "", "slug": "grannys-gone", "title": "Granny\'s Gone", "updated": "2010-04-02T10:05:00"}]'
     )
Пример #6
0
 def test_round_trip_json(self):
     serializer = Serializer()
     sample_data = self.get_sample2()
     serialized = serializer.to_json(sample_data)
     unserialized = serializer.from_json(serialized)
     self.assertEqual(sample_data, unserialized)
Пример #7
0
 def test_to_json_single(self):
     serializer = Serializer()
     resource = self.obj_list[0]
     self.assertEqual(serializer.to_json(resource), '{"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}')
Пример #8
0
 def test_to_json_multirepr(self):
     serializer = Serializer()
     self.assertEqual(serializer.to_json(self.obj_list), '[{"content": "This is my very first post using my shiny new API. Pretty sweet, huh?", "created": "2010-03-30T20:05:00", "id": "1", "is_active": true, "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}, {"content": "The dog ate my cat today. He looks seriously uncomfortable.", "created": "2010-03-31T20:05:00", "id": "2", "is_active": true, "resource_uri": "", "slug": "another-post", "title": "Another Post", "updated": "2010-03-31T20:05:00"}, {"content": "My neighborhood\'s been kinda weird lately, especially after the lava flow took out the corner store. Granny can hardly outrun the magma with her walker.", "created": "2010-04-01T20:05:00", "id": "4", "is_active": true, "resource_uri": "", "slug": "recent-volcanic-activity", "title": "Recent Volcanic Activity.", "updated": "2010-04-01T20:05:00"}, {"content": "Man, the second eruption came on fast. Granny didn\'t have a chance. On the upshot, I was able to save her walker and I got a cool shawl out of the deal!", "created": "2010-04-02T10:05:00", "id": "6", "is_active": true, "resource_uri": "", "slug": "grannys-gone", "title": "Granny\'s Gone", "updated": "2010-04-02T10:05:00"}]')
Пример #9
0
 def test_round_trip_json(self):
     serializer = Serializer()
     sample_data = self.get_sample2()
     serialized = serializer.to_json(sample_data)
     unserialized = serializer.from_json(serialized)
     self.assertEqual(sample_data, unserialized)
Пример #10
0
 def test_to_json(self):
     serializer = Serializer()
     
     sample_1 = self.get_sample1()
     self.assertEqual(serializer.to_json(sample_1), '{"age": 27, "date_joined": "2010-03-27", "name": "Daniel"}')