示例#1
0
    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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 def test_default_serializers(self):
     robj = wsgi.ResponseObject({})
     self.assertEqual({}, robj.serializers)
示例#5
0
 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)
示例#6
0
 def test_del_header(self):
     robj = wsgi.ResponseObject({})
     robj['Header'] = 'foo'
     del robj['hEADER']
     self.assertNotIn('header', robj.headers)
示例#7
0
 def test_header_isolation(self):
     robj = wsgi.ResponseObject({})
     robj['Header'] = 'foo'
     hdrs = robj.headers
     hdrs['hEADER'] = 'bar'
     self.assertEqual('foo', robj['hEADER'])
示例#8
0
 def test_get_header(self):
     robj = wsgi.ResponseObject({})
     robj['Header'] = 'foo'
     self.assertEqual('foo', robj['hEADER'])
示例#9
0
 def test_set_header(self):
     robj = wsgi.ResponseObject({})
     robj['Header'] = 'foo'
     self.assertEqual({'header': 'foo'}, robj.headers)
示例#10
0
 def test_override_modified_code(self):
     robj = wsgi.ResponseObject({}, code=404)
     robj._default_code = 202
     self.assertEqual(404, robj.code)
示例#11
0
 def test_modified_code(self):
     robj = wsgi.ResponseObject({})
     robj._default_code = 202
     self.assertEqual(202, robj.code)
示例#12
0
 def test_default_code(self):
     robj = wsgi.ResponseObject({})
     self.assertEqual(200, robj.code)