Example #1
0
 def test_format_scandic_json(self):
     m = JsonMapper()
     data = {'key': 'lähtö'}
     resp = m.format(data)
     self.assertEquals(resp['Content-Type'],
                       'application/json; charset=utf-8')
     self.assertEquals(resp.content, '{\n    "key": "lähtö"\n}')
Example #2
0
    def test_wildcard_mappers(self):
        self.manager.register_mapper(JsonMapper(), 'application/json', 'json')
        self.assertEquals(4, len(self.manager._datamappers.items()))
        self.assertEquals(self.manager._datamappers['*/*'].content_type,
                          'text/plain')
        self.assertEquals(
            self.manager._datamappers['application/*'].content_type,
            'application/json')
        self.assertEquals(
            self.manager._datamappers['application/json'].content_type,
            'application/json')
        self.assertEquals(self.manager._datamappers['json'].content_type,
                          'application/json')

        # now override application/* with xml
        self.manager.register_mapper(XmlMapper(), 'application/xml', 'xml')
        self.assertEquals(6, len(self.manager._datamappers.items()))
        self.assertEquals(
            self.manager._datamappers['application/*'].content_type,
            'text/xml')

        # now override application/* with json
        self.manager.register_mapper(JsonMapper(), 'application/*')
        self.assertEquals(6, len(self.manager._datamappers.items()))
        self.assertEquals(
            self.manager._datamappers['application/*'].content_type,
            'application/json')

        # now set default mapper to xml
        self.manager.set_default_mapper(XmlMapper())
        self.assertEquals(6, len(self.manager._datamappers.items()))
        self.assertEquals(self.manager._datamappers['*/*'].content_type,
                          'text/xml')
Example #3
0
 def test_parse_scandic_json(self):
     m = JsonMapper()
     result = m.parse('{"key": "lähtö"}', 'utf-8')
     self.assertTrue(isinstance(result['key'], unicode))
Example #4
0
 def tearDown(self):
     manager.register_mapper(JsonMapper(), 'application/json', 'json')
Example #5
0
 def setUp(self):
     manager.register_mapper(JsonMapper(use_decimal=True),
                             'application/json', 'json')
Example #6
0
File: tests.py Project: pdh/devil
 def test_format_scandic_json(self):
     m = JsonMapper()
     data = {'key': 'lähtö'}
     resp = m.format(data)
     self.assertEquals(resp['Content-Type'], 'application/json; charset=utf-8')
     self.assertEquals(resp.content, '{\n    "key": "lähtö"\n}')
Example #7
0
File: tests.py Project: pdh/devil
 def test_parse_scandic_json(self):
     m = JsonMapper()
     result = m.parse('{"key": "lähtö"}', 'utf-8')
     self.assertTrue(isinstance (result['key'], unicode))