diff --git a/tests/test_parser.py b/tests/test_parser.py index 5b9f365..1ccb4ff 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -12,6 +12,7 @@ DirectoryTarget, SHA256Target, ValueTarget, + MultipleTargets, ) from streaming_form_data.validators import MaxSizeValidator, ValidationError @@ -126,44 +127,6 @@ def test_basic_multiple(): assert third.value == b"baz" -def test_multiple_inputs(): - data = b"""\ ------------------------------111217161535371856203688828 -Content-Disposition: form-data; name="files"; filename="first.txt" -Content-Type: text/plain - -first - ------------------------------111217161535371856203688828 -Content-Disposition: form-data; name="files"; filename="second.txt" -Content-Type: text/plain - -second - ------------------------------111217161535371856203688828 -Content-Disposition: form-data; name="files"; filename="third.txt" -Content-Type: text/plain - -third - ------------------------------111217161535371856203688828-- -""".replace(b"\n", b"\r\n") - - target = ValueTarget() - - parser = StreamingFormDataParser( - headers={ - "Content-Type": "multipart/form-data; boundary=111217161535371856203688828" - } - ) - parser.register("files") - - parser.data_received(data) - - breakpoint() - assert target.multipart_filename == "ab.txt" - - def test_chunked_single(): expected_value = "hello world" @@ -878,6 +841,47 @@ def test_extra_headers(): assert target.value == b"Joe owes =80100." +def test_multiple_inputs(tmp_path): + data = b"""\ +--111217161535371856203688828 +Content-Disposition: form-data; name="files"; filename="first.txt" +Content-Type: text/plain + +first +--111217161535371856203688828 +Content-Disposition: form-data; name="files"; filename="second.txt" +Content-Type: text/plain + +second +--111217161535371856203688828 +Content-Disposition: form-data; name="files"; filename="third.txt" +Content-Type: text/plain + +third +--111217161535371856203688828-- +""".replace(b"\n", b"\r\n") + + class next_target: + def __init__(self): + self._index = 0 + + def __call__(self): + return FileTarget(tmp_path / f"{self._index}.txt") + + target = MultipleTargets(next_target()) + + parser = StreamingFormDataParser( + headers={ + "Content-Type": "multipart/form-data; boundary=111217161535371856203688828" + } + ) + parser.register("files", target) + + parser.data_received(data) + + assert len(target._targets) == 3 + + def test_case_insensitive_content_disposition_header(): content_disposition_header = "Content-Disposition"