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}')
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')
def test_parse_scandic_json(self): m = JsonMapper() result = m.parse('{"key": "lähtö"}', 'utf-8') self.assertTrue(isinstance(result['key'], unicode))
def tearDown(self): manager.register_mapper(JsonMapper(), 'application/json', 'json')
def setUp(self): manager.register_mapper(JsonMapper(use_decimal=True), 'application/json', 'json')
def test_parse_scandic_json(self): m = JsonMapper() result = m.parse('{"key": "lähtö"}', 'utf-8') self.assertTrue(isinstance (result['key'], unicode))