Пример #1
0
 def test_to_json_decimal_list_dict(self):
     serializer = Serializer()
     resource = self.another_obj_list[0]
     self.assertEqual(
         serializer.to_json(resource),
         '{"aliases": ["Mr. Smith", "John Doe"], "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, "meta": {"threat": "high"}, "owed": "102.57", "resource_uri": "", "slug": "first-post", "title": "First Post!", "updated": "2010-03-30T20:05:00"}'
     )
Пример #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_jsonp(self):
        serializer = Serializer()

        sample_1 = self.get_sample1()
        options = {'callback': 'myCallback'}
        serialized = serializer.to_jsonp(sample_1, options=options)
        serialized_json = serializer.to_json(sample_1)
        self.assertEqual('myCallback(%s)' % serialized_json, serialized)
Пример #4
0
    def test_to_json(self):
        serializer = Serializer()

        sample_1 = self.get_sample1()
        self.assertEqual(
            serializer.to_json(sample_1),
            u'{"age": 27, "date_joined": "2010-03-27", "name": "Daniel", "snowman": "☃"}'
        )
Пример #5
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"}}}'
     )
Пример #6
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"}]'
     )
Пример #7
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)