def test_json_by_qs(self): request = FakeRequest('/hiihoo', '{"a": 1}', format='json') self.assertEquals({'a': 1}, datamapper.parse('{"a": 1}', request, self.foores)) request = FakeRequest('/hiihoo.yaml', '{"a": 1}', format='json') self.assertEquals({'a': 1}, datamapper.parse('{"a": 1}', request, self.foores))
def test_no_data(self): request = FakeRequest('/hiihoo.json') self.assertRaises(TypeError, datamapper.parse, request, self.foores) request = FakeRequest('/hiihoo.json', '') self.assertRaises(errors.BadRequest, datamapper.parse, 'hiihoo', request, self.foores) request = FakeRequest('/hiihoo.json', '{}') self.assertEquals({}, datamapper.parse('{}', request, self.foores)) request = FakeRequest('/hiihoo.json', '[]') self.assertEquals([], datamapper.parse('[]', request, self.foores))
def test_json_by_content_type(self): request = FakeRequest('/hiihoo', '{"a": 1}', 'application/json') self.assertEquals({'a': 1}, datamapper.parse('{"a": 1}', request, self.foores)) request = FakeRequest('/hiihoo.yaml', '{"a": 1}', 'application/json') self.assertEquals({'a': 1}, datamapper.parse('{"a": 1}', request, self.foores)) request = FakeRequest('/hiihoo.yaml', '{"a": 1}', 'application/json', format='yaml') self.assertEquals({'a': 1}, datamapper.parse('{"a": 1}', request, self.foores))
def test_no_data(self): request = FakeRequest('/hiihoo.json') self.assertRaises( TypeError, datamapper.parse, request, self.foores) request = FakeRequest('/hiihoo.json', '') self.assertRaises( errors.BadRequest, datamapper.parse, 'hiihoo', request, self.foores) request = FakeRequest('/hiihoo.json', '{}') self.assertEquals({}, datamapper.parse('{}', request, self.foores)) request = FakeRequest('/hiihoo.json', '[]') self.assertEquals([], datamapper.parse('[]', request, self.foores))
def test_json_by_extension(self): request = FakeRequest('/hiihoo.json', '{"a": 3, "b": 4}') self.assertEquals( datamapper.parse('{"a": 3, "b": 4}', request, self.foores), { 'a': 3, 'b': 4 })
def test_default_parser(self): request = FakeRequest('/hiihoo', '{"a": 1}') self.assertEquals('{"a": 1}', datamapper.parse('{"a": 1}', request, self.foores))
def test_json_by_extension(self): request = FakeRequest('/hiihoo.json', '{"a": 3, "b": 4}') self.assertEquals(datamapper.parse('{"a": 3, "b": 4}', request, self.foores), {'a': 3, 'b': 4})