def test_no_data(self): request = FakeRequest('/hiihoo.json') self.assertEquals('', (datamapper.format(request, None, self.foores)).content) request = FakeRequest('/hiihoo.json', '') self.assertEquals('', (datamapper.format(request, '', self.foores)).content) request = FakeRequest('/hiihoo.json', '{}') self.assertEquals('{}', (datamapper.format(request, {}, self.foores)).content) request = FakeRequest('/hiihoo.json', '[]') self.assertEquals('[]', (datamapper.format(request, [], self.foores)).content)
def test_none_data_json(self): request = FakeRequest('/hiihoo', format='json') response = datamapper.format(request, None, self.foores) self.assertEquals(response.content, '') self.assertEquals(response.status_code, 0) self.assertEquals(response['Content-Type'], 'application/json; charset=utf-8')
def test_none_data_default(self): request = FakeRequest('/hiihoo') response = datamapper.format(request, None, self.foores) self.assertEquals(response.content, '') self.assertEquals(response.status_code, 0) self.assertEquals(response['Content-Type'], 'text/plain; charset=utf-8')
def test_unknown_by_content_type(self): """ Test that request content-type doesn't affect anything. """ request = FakeRequest('/hiihoo.json', 'hiihootype') response = datamapper.format(request, {'a': 1}, self.foores) self.assertEquals(json.loads(response.content), {'a': 1}) self.assertEquals(response['Content-Type'], 'application/json; charset=utf-8')
def test_response_to_json(self): request = FakeRequest('/', format='json') response = datamapper.format( request, http.Response(0, {'a': 1}), self.foores) self.assertEquals(json.loads(response.content), {'a': 1}) self.assertEquals(response['Content-Type'], 'application/json; charset=utf-8') self.assertEquals(response.status_code, 0)
def test_response_to_json(self): request = FakeRequest('/', format='json') response = datamapper.format(request, http.Response(0, {'a': 1}), self.foores) self.assertEquals(json.loads(response.content), {'a': 1}) self.assertEquals(response['Content-Type'], 'application/json; charset=utf-8') self.assertEquals(response.status_code, 0)
def test_my_default_formatter(self): class MyDataMapper(datamapper.DataMapper): content_type = 'text/jedi' def _format_data(self, data, charset): return 'this is my data, i have nothing else' # install my own default mapper datamapper.manager.set_default_mapper(MyDataMapper()) request = FakeRequest('/hiihoo') response = datamapper.format(request, 'Hello, world!', self.foores) self.assertEquals(response.content, 'this is my data, i have nothing else') self.assertEquals(response['Content-Type'], 'text/jedi; charset=utf-8') # put the original default mapper back datamapper.manager.set_default_mapper(None) request = FakeRequest('/hiihoo') response = datamapper.format(request, 'Hello, world!', self.foores) self.assertEquals(response.content, 'Hello, world!') self.assertEquals(response['Content-Type'], 'text/plain; charset=utf-8')
def test_default_formatter(self): request = FakeRequest('/hiihoo') response = datamapper.format(request, 'Hello, world!', self.foores) self.assertEquals(response.content, 'Hello, world!') self.assertEquals(response['Content-Type'], 'text/plain; charset=utf-8')