Пример #1
0
    def test_serialize(self):
        class JSONSerializer(object):
            def serialize(self, obj):
                return six.b('json')

        class XMLSerializer(object):
            def serialize(self, obj):
                return six.b('xml')

        class AtomSerializer(object):
            def serialize(self, obj):
                return six.b('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(six.b(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)