def test_env_cleared(self): app = middleware.AutoMimeMiddleware(FakeApp(), {}) req = Request.blank('/v1/a/c/obj.txt', environ={ 'REQUEST_METHOD': 'PUT', 'CONTENT_TYPE': 'something' }) res = req.get_response(app) self.assertEqual(res.environ.get('CONTENT_TYPE'), None) self.assertEqual(res.status_int, 200)
def test_unknown_type_encoding(self): app = middleware.AutoMimeMiddleware(FakeApp(), {}) req = Request.blank('/v1/a/c/obj.bla', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': self.cache }) res = req.get_response(app) self.assertFalse(res.environ.get('HTTP_CONTENT_TYPE', False)) self.assertFalse(res.environ.get('HTTP_CONTENT_ENCODING', False)) self.assertEqual(res.status_int, 200)
def test_set_type_and_encoding(self): app = middleware.AutoMimeMiddleware(FakeApp(), {}) req = Request.blank('/v1/a/c/obj.txt.gz', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': self.cache }) res = req.get_response(app) self.assertEqual(res.environ.get('HTTP_CONTENT_TYPE'), 'text/plain') self.assertEqual(res.environ.get('HTTP_CONTENT_ENCODING'), 'gzip') self.assertEqual(res.status_int, 200)
def test_meta_not_set(self): app = middleware.AutoMimeMiddleware(FakeApp(), {}) req = Request.blank('/v1/a/c/obj.txt', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': FakeCache({'meta': {}}) }) res = req.get_response(app) self.assertEqual(res.environ.get('HTTP_CONTENT_TYPE'), None) self.assertFalse(res.environ.get('HTTP_CONTENT_ENCODING', None)) self.assertEqual(res.status_int, 200)