def test_serialize(self): class JSONSerializer(object): def serialize(self, obj): return 'json' class XMLSerializer(object): def serialize(self, obj): return 'xml' class AtomSerializer(object): def serialize(self, obj): return 'atom' robj = wsgi.ResponseObject({}, code=202, json=JSONSerializer, xml=XMLSerializer, atom=AtomSerializer) robj['X-header1'] = 'header1' robj['X-header2'] = 'header2' for content_type, mtype in wsgi._MEDIA_TYPE_MAP.items(): request = wsgi.Request.blank('/tests/123') response = robj.serialize(request, content_type) self.assertEqual(content_type, response.headers['Content-Type']) self.assertEqual('header1', response.headers['X-header1']) self.assertEqual('header2', response.headers['X-header2']) self.assertEqual(202, response.status_int) self.assertEqual(mtype, response.body)
def test_get_serializer_defaults(self): robj = wsgi.ResponseObject({}) default_serializers = dict(json='json', xml='xml', atom='atom') for content_type, mtype in wsgi._MEDIA_TYPE_MAP.items(): self.assertRaises(exception.InvalidContentType, robj.get_serializer, content_type) _mtype, serializer = robj.get_serializer(content_type, default_serializers) self.assertEqual(mtype, serializer)
def test_get_serializer(self): robj = wsgi.ResponseObject({}, json='json', xml='xml', atom='atom') for content_type, mtype in wsgi._MEDIA_TYPE_MAP.items(): _mtype, serializer = robj.get_serializer(content_type) self.assertEqual(mtype, serializer)
def test_default_serializers(self): robj = wsgi.ResponseObject({}) self.assertEqual({}, robj.serializers)
def test_bind_serializers(self): robj = wsgi.ResponseObject({}, json='foo') robj._bind_method_serializers(dict(xml='bar', json='baz')) self.assertEqual(dict(xml='bar', json='foo'), robj.serializers)
def test_del_header(self): robj = wsgi.ResponseObject({}) robj['Header'] = 'foo' del robj['hEADER'] self.assertNotIn('header', robj.headers)
def test_header_isolation(self): robj = wsgi.ResponseObject({}) robj['Header'] = 'foo' hdrs = robj.headers hdrs['hEADER'] = 'bar' self.assertEqual('foo', robj['hEADER'])
def test_get_header(self): robj = wsgi.ResponseObject({}) robj['Header'] = 'foo' self.assertEqual('foo', robj['hEADER'])
def test_set_header(self): robj = wsgi.ResponseObject({}) robj['Header'] = 'foo' self.assertEqual({'header': 'foo'}, robj.headers)
def test_override_modified_code(self): robj = wsgi.ResponseObject({}, code=404) robj._default_code = 202 self.assertEqual(404, robj.code)
def test_modified_code(self): robj = wsgi.ResponseObject({}) robj._default_code = 202 self.assertEqual(202, robj.code)
def test_default_code(self): robj = wsgi.ResponseObject({}) self.assertEqual(200, robj.code)