def test_serves(self): whitenoise = static.WhiteNoise(None, autorefresh=True) whitenoise.add_files( static.resolver.resolve("warehouse:/static/dist/").abspath(), prefix="/static/", ) path, headers = (whitenoise.find_file("/static/manifest.json") .get_path_and_headers({})) headers = dict(headers) response = pretend.stub() handler = pretend.call_recorder(lambda request: response) registry = pretend.stub(whitenoise=whitenoise) request = pretend.stub( method="GET", environ={}, path_info="/static/manifest.json", registry=registry, ) tween = static.whitenoise_tween_factory(handler, registry) resp = tween(request) assert resp.status_code == 200 assert resp.headers["Content-Type"] == "application/json" assert ( set(i.strip() for i in resp.headers["Cache-Control"].split(",")) == {"public", "max-age=60"} ) assert resp.headers["Vary"] == "Accept-Encoding" with open(path, "rb") as fp: assert resp.body == fp.read()
def test_serves(self): whitenoise = WhiteNoise(None, autorefresh=True) whitenoise.add_files( static.resolver.resolve("warehouse:/static/dist/").abspath(), prefix="/static/", ) path, headers = ( whitenoise.find_file("/static/manifest.json").get_path_and_headers( {})) headers = dict(headers) response = pretend.stub() handler = pretend.call_recorder(lambda request: response) registry = pretend.stub(whitenoise=whitenoise) request = pretend.stub( method="GET", environ={}, path_info="/static/manifest.json", registry=registry, ) tween = static.whitenoise_tween_factory(handler, registry) resp = tween(request) assert resp.status_code == 200 assert resp.headers["Content-Type"] == "application/json" assert resp.headers["Cache-Control"] == "public, max-age=60" assert resp.headers["Vary"] == "Accept-Encoding" with open(path, "rb") as fp: assert resp.body == fp.read()
def test_bypasses(self, autorefresh): whitenoise = static.WhiteNoise(None, autorefresh=autorefresh) whitenoise.add_files( static.resolver.resolve("warehouse:/static/dist/").abspath(), prefix="/static/", ) response = pretend.stub() handler = pretend.call_recorder(lambda request: response) registry = pretend.stub(whitenoise=whitenoise) request = pretend.stub(path_info="/other/", registry=registry) tween = static.whitenoise_tween_factory(handler, registry) resp = tween(request) assert resp is response
def test_method_not_allowed(self, autorefresh): whitenoise = static.WhiteNoise(None, autorefresh=autorefresh) whitenoise.add_files( static.resolver.resolve("warehouse:/static/dist/").abspath(), prefix="/static/", ) response = pretend.stub() handler = pretend.call_recorder(lambda request: response) registry = pretend.stub(whitenoise=whitenoise) request = pretend.stub( method="POST", environ={"HTTP_ACCEPT_ENCODING": "gzip"}, path_info="/static/manifest.json", registry=registry, ) tween = static.whitenoise_tween_factory(handler, registry) resp = tween(request) assert resp.status_code == 405