def test_as_app_iter(self, filedepot, image_asset): from pyramid.response import FileIter data = image_asset.read() f = self._create_file(data) resp = StoredFileResponse(f.data.file, DummyRequest()) assert isinstance(resp.app_iter, FileIter) assert ''.join(resp.app_iter) == data
def test_redirect(self, filedepot): class PublicFile(object): public_url = 'http://example.com' with pytest.raises(HTTPMovedPermanently) as e: StoredFileResponse(PublicFile(), DummyRequest()) response = e.value assert response.headers['Location'] == 'http://example.com'
def test_redirect(self, filedepot, dummy_request): class PublicFile(object): public_url = "http://example.com" with pytest.raises(HTTPMovedPermanently) as e: StoredFileResponse(PublicFile(), dummy_request) response = e.value assert response.headers["Location"] == "http://example.com"
def test_caching(self, filedepot, monkeypatch): import datetime import webob.response f = self._create_file() d = datetime.datetime(2012, 12, 31, 13) class mockdatetime: @staticmethod def utcnow(): return d monkeypatch.setattr(webob.response, 'datetime', mockdatetime) resp = StoredFileResponse(f.data.file, DummyRequest(), cache_max_age=10) # this is set by filedepot fixture assert resp.headers['Last-Modified'] == 'Sun, 30 Dec 2012 00:00:00 GMT' assert resp.headers['Expires'] == 'Mon, 31 Dec 2012 13:00:10 GMT'
def test_guess_content_type(self, filedepot, image_asset): f = self._create_file(image_asset.read(), "file.png", None) resp = StoredFileResponse(f.data.file, DummyRequest()) assert resp.headers['Content-Type'] == 'image/png'
def test_unknown_filename(self, filedepot, image_asset2): f = self._create_file(b'foo', "file.bar", None) resp = StoredFileResponse(f.data.file, DummyRequest()) assert resp.headers['Content-Type'] == 'application/octet-stream'
def test_as_body(self, filedepot, image_asset): data = image_asset.read() f = self._create_file(data) resp = StoredFileResponse(f.data.file, DummyRequest()) assert resp.body == data
def test_guess_content_type(self, filedepot, image_asset, dummy_request): f = self._create_file(image_asset.read(), "file.png", None) resp = StoredFileResponse(f.data.file, dummy_request) assert resp.headers["Content-Type"] == "image/png"
def test_unknown_filename(self, filedepot, image_asset2, dummy_request): f = self._create_file(b"foo", "file.bar", None) resp = StoredFileResponse(f.data.file, dummy_request) assert resp.headers["Content-Type"] == "application/octet-stream"