from wsgiref.validate import validator import pytest from paste import options from ..common_wsgi import call_app @pytest.fixture def app(): @validator @options @validator def app(_, start_response): start_response("200 OK", [("Content-Type", "text/plain")]) return [b"Hello, world!"] return app @pytest.mark.parametrize("method", ["GET", "HEAD", "POST", "PUT", "DELETE"]) def test_non_options(app, method): environ = {"REQUEST_METHOD": method} response = call_app(app, environ) assert response.data == b"Hello, world!" assert response.status == "200 OK" assert ("Content-Type", "text/plain") in response.headers def test_options(app): environ = {"REQUEST_METHOD": "OPTIONS"} response = call_app(app, environ) assert response.data == b"" assert response.status == "204 No Content" allow = None for k, v in response.headers: if k != "Allow": continue allow = v.split(", ") assert allow is not None, "Must contain an Allow header" assert len(set(allow)) == len(allow), "Allow header must not contain duplicates" assert set(allow) == {"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}