Skip to content

Commit fd71a46

Browse files
committed
Add test for MultiDict.from_multipart
1 parent a959dd6 commit fd71a46

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_multidict.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,34 @@ def test_repr_with_password(self):
275275
d = self._get_instance(password="pwd")
276276
assert repr(d) == "MultiDict([('password', '******')])"
277277

278+
def test_from_multipart(self):
279+
from io import BytesIO
280+
281+
from multipart import MultipartParser
282+
283+
data = (
284+
b"--foobar\r\n"
285+
b'Content-Disposition: form-data; name="foo"\r\n'
286+
b"\r\n"
287+
b"bar\r\n"
288+
b"--foobar\r\n"
289+
b'Content-Disposition: form-data; name="fizz"; filename="fizz.txt"\r\n'
290+
b"Content-type: application/octet-stream\r\n"
291+
b"\r\n"
292+
b"buzz\r\n"
293+
b"\r\n"
294+
b"--foobar--\r\n"
295+
)
296+
body = BytesIO(data)
297+
body.seek(0)
298+
mp = MultipartParser(body, b"foobar")
299+
inst = self.klass.from_multipart(mp)
300+
assert inst["foo"] == "bar"
301+
fizz = inst["fizz"]
302+
assert isinstance(fizz, multidict.MultiDictFile)
303+
assert fizz.filename == "fizz.txt"
304+
assert fizz.value == b"buzz\r\n"
305+
278306

279307
class TestNestedMultiDict(BaseDictTests):
280308
klass = multidict.NestedMultiDict

0 commit comments

Comments
 (0)