Example #1
0
 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
Example #2
0
    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'
Example #3
0
    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"
Example #4
0
    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'
Example #5
0
 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'
Example #6
0
 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'
Example #7
0
 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
Example #8
0
 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"
Example #9
0
 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"