Ejemplo n.º 1
0
 def set_header__content_type(self) -> None:
     request = create_request("GET", "/foo/bar")
     request.set_header("Content-Type", "text/html")
     assert_equal("text/html", request.content_type)
     environ = request.to_environment()
     assert_dict_superset({"CONTENT_TYPE": "text/html"}, environ)
     assert_not_in("HTTP_CONTENT_TYPE", environ)
Ejemplo n.º 2
0
 def to_environment__post(self) -> None:
     request = create_request("POST", "/foo/bar")
     environ = request.to_environment()
     assert_dict_superset(
         {
             "REQUEST_METHOD": "POST",
             "PATH_INFO": "/foo/bar",
             "SERVER_NAME": "www.example.com",
             "SERVER_PORT": "80",
             "SERVER_PROTOCOL": "HTTP/1.1",
             "REMOTE_ADDR": "127.0.0.1",
             "wsgi.version": (1, 0),
             "wsgi.url_scheme": "http",
             "wsgi.multithread": False,
             "wsgi.multiprocess": False,
             "wsgi.run_once": True,
             "wsgi.errors": request.error_stream,
         },
         environ,
     )
     assert_wsgi_input_stream(environ["wsgi.input"])
     assert_equal(b"", environ["wsgi.input"].read())
     assert_not_in("CONTENT_TYPE", environ)
     assert_not_in("CONTENT_LENGTH", environ)
     assert_not_in("QUERY_STRING", environ)
Ejemplo n.º 3
0
 def arguments__get_request(self) -> None:
     request = create_request("GET", "/foo")
     request.add_argument("foo", "bar")
     request.add_argument("abc", ["def", "ghi"])
     environ = request.to_environment()
     assert_dict_superset(
         {"QUERY_STRING": "foo=bar&abc=def&abc=ghi"}, environ
     )
Ejemplo n.º 4
0
 def set_env_var__priority(self) -> None:
     request = create_request("GET", "/foo/bar")
     request.set_env_var("SERVER_PORT", "8888")
     request.set_env_var("HTTP_X_FOO", "Set by env var")
     request.set_header("X-Foo", "Set by header")
     environ = request.to_environment()
     assert_dict_superset(
         {"SERVER_PORT": "8888", "HTTP_X_FOO": "Set by env var"}, environ
     )
Ejemplo n.º 5
0
    def add_file_argument__content_type(self) -> None:
        request = create_request("POST", "/foo/bar")
        assert_is_none(request.content_type)
        request.add_file_argument("foo", b"", "text/plain")
        assert_is_none(request.content_type)
        environ = request.to_environment()
        content_type, boundary = environ["CONTENT_TYPE"].split(";")
        assert_equal("multipart/form-data", content_type)

        request = create_request("POST", "/foo/bar")
        request.content_type = "image/png"
        request.add_file_argument("abc", b"", "text/plain")
        assert_equal("image/png", request.content_type)
        environ = request.to_environment()
        assert_dict_superset({"CONTENT_TYPE": "image/png"}, environ)
Ejemplo n.º 6
0
 def to_environment__post_urlencoded(self) -> None:
     request = create_request("POST", "/foo/bar")
     request.add_argument("arg", "value")
     environ = request.to_environment()
     assert_dict_superset(
         {
             "REQUEST_METHOD": "POST",
             "CONTENT_TYPE": "application/x-www-form-urlencoded",
             "CONTENT_LENGTH": "9",
         },
         environ,
     )
     assert_wsgi_input_stream(environ["wsgi.input"])
     assert_equal(b"arg=value", environ["wsgi.input"].read())
     assert_not_in("QUERY_STRING", environ)
Ejemplo n.º 7
0
    def add_argument__content_type(self) -> None:
        request = create_request("POST", "/foo/bar")
        assert_is_none(request.content_type)
        request.add_argument("foo", "bar")
        assert_is_none(request.content_type)
        environ = request.to_environment()
        assert_dict_superset(
            {"CONTENT_TYPE": "application/x-www-form-urlencoded"}, environ
        )

        request = create_request("POST", "/foo/bar")
        request.content_type = "image/png"
        request.add_argument("abc", "def")
        assert_equal("image/png", request.content_type)
        environ = request.to_environment()
        assert_dict_superset({"CONTENT_TYPE": "image/png"}, environ)

        request = create_request("GET", "/foo/bar")
        assert_is_none(request.content_type)
        request.add_argument("foo", "bar")
        assert_is_none(request.content_type)
        environ = request.to_environment()
        assert_not_in("CONTENT_TYPE", environ)
Ejemplo n.º 8
0
 def arguments__quote(self) -> None:
     request = create_request("GET", "/foo")
     request.add_argument("föo", "bär")
     environ = request.to_environment()
     assert_dict_superset({"QUERY_STRING": "f%C3%B6o=b%C3%A4r"}, environ)
Ejemplo n.º 9
0
 def to_environment__content_type(self) -> None:
     request = create_request("GET", "/foo/bar")
     request.content_type = "image/png"
     environ = request.to_environment()
     assert_dict_superset({"CONTENT_TYPE": "image/png"}, environ)
Ejemplo n.º 10
0
 def set_header(self) -> None:
     request = create_request("GET", "/foo/bar")
     request.set_header("X-Foobar", "Baz")
     environ = request.to_environment()
     assert_dict_superset({"HTTP_X_FOOBAR": "Baz"}, environ)
Ejemplo n.º 11
0
 def set_env_var(self) -> None:
     request = create_request("GET", "/foo/bar")
     request.set_env_var("foo.bar", "baz")
     environ = request.to_environment()
     assert_dict_superset({"foo.bar": "baz"}, environ)