Skip to content

Commit

Permalink
chore: update multiple targets test
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantgoel committed Nov 5, 2024
1 parent 310c34a commit cbdf4e9
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DirectoryTarget,
SHA256Target,
ValueTarget,
MultipleTargets,
)
from streaming_form_data.validators import MaxSizeValidator, ValidationError

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit cbdf4e9

Please sign in to comment.