Exemple #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)
Exemple #2
0
 def arguments__put_request(self) -> None:
     request = create_request("PUT", "/foo")
     request.add_argument("foo", "bar")
     request.add_argument("abc", ["def", "ghi"])
     environ = request.to_environment()
     assert_not_in("QUERY_STRING", environ)
     assert_equal(
         "application/x-www-form-urlencoded", environ["CONTENT_TYPE"]
     )
     content = environ["wsgi.input"].read()
     assert_equal(b"foo=bar&abc=def&abc=ghi", content)
Exemple #3
0
 def empty_delete__optional(self) -> None:
     self.env["REQUEST_METHOD"] = "DELETE"
     self.setup_empty_urlencoded_request()
     args = parse_args(
         self.env,
         [
             ("opt", str, Multiplicity.OPTIONAL),
             ("any", str, Multiplicity.ANY),
         ],
     )
     assert_not_in("opt", args)
     assert_equal([], args["any"])
Exemple #4
0
    def clear_arguments(self) -> None:
        request = create_request("GET", "/foo")
        request.add_argument("foo", "bar")
        request.clear_arguments()
        environ = request.to_environment()
        assert_not_in("QUERY_STRING", environ)

        request = create_request("POST", "/foo")
        request.add_argument("foo", "bar")
        request.clear_arguments()
        environ = request.to_environment()
        content = environ["wsgi.input"].read()
        assert_equal(b"", content)
Exemple #5
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)
Exemple #6
0
 def file_arguments__umlauts(self) -> None:
     request = create_request("PUT", "/foo")
     request.add_argument('f"öo', "bär")
     request.add_file_argument(
         'f"öle', b"", "text/plain", filename="ä\"'bc"
     )
     environ = request.to_environment()
     assert_not_in("QUERY_STRING", environ)
     content_type, boundary = environ["CONTENT_TYPE"].split(";")
     assert_equal("multipart/form-data", content_type)
     _, args, files = parse_form_data(environ)
     assert_equal(1, len(args))
     assert_equal(args["f%22%C3%B6o"], "bär")
     assert_equal(1, len(files))
     file = files["f%22%C3%B6le"]
     assert_equal("text/plain", file.mimetype)
     assert_equal("ä\"'bc", file.filename)
     assert_equal(b"", file.stream.read())
Exemple #7
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)
Exemple #8
0
 def file_arguments(self) -> None:
     request = create_request("PUT", "/foo")
     request.add_argument("foo", "bar")
     request.add_file_argument("file1", b"content1", "text/plain")
     request.add_file_argument(
         "file2", b"content2", "image/png", filename="foobar"
     )
     environ = request.to_environment()
     assert_not_in("QUERY_STRING", environ)
     content_type, boundary = environ["CONTENT_TYPE"].split(";")
     assert_equal("multipart/form-data", content_type)
     _, args, files = parse_form_data(environ)
     assert_equal(1, len(args))
     assert_equal(args["foo"], "bar")
     assert_equal(2, len(files))
     file1 = files["file1"]
     assert_equal("text/plain", file1.mimetype)
     assert_equal("", file1.filename)
     assert_equal(b"content1", file1.stream.read())
     file2 = files["file2"]
     assert_equal("image/png", file2.mimetype)
     assert_equal("foobar", file2.filename)
     assert_equal(b"content2", file2.stream.read())
Exemple #9
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)
Exemple #10
0
def assertNotIn(content, res):
    try:
        asserts.assert_not_in(content, res)
    except Exception as e:
        logger.error(e)
def check_does_not_reference(context):
    """Check the filename reference."""
    assert_not_in("/", context.next_action())