Coverage for tests/test_multipart_installation.py: 100%
63 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-06 16:22 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-06 16:22 +0000
1import pytest 1abcde
2from fastapi import FastAPI, File, Form, UploadFile 1abcde
3from fastapi.dependencies.utils import ( 1abcde
4 multipart_incorrect_install_error,
5 multipart_not_installed_error,
6)
9def test_incorrect_multipart_installed_form(monkeypatch): 1abcde
10 monkeypatch.delattr("multipart.multipart.parse_options_header", raising=False) 1fghij
11 with pytest.raises(RuntimeError, match=multipart_incorrect_install_error): 1fghij
12 app = FastAPI() 1fghij
14 @app.post("/") 1fghij
15 async def root(username: str = Form()): 1fghij
16 return username # pragma: nocover
19def test_incorrect_multipart_installed_file_upload(monkeypatch): 1abcde
20 monkeypatch.delattr("multipart.multipart.parse_options_header", raising=False) 1klmno
21 with pytest.raises(RuntimeError, match=multipart_incorrect_install_error): 1klmno
22 app = FastAPI() 1klmno
24 @app.post("/") 1klmno
25 async def root(f: UploadFile = File()): 1klmno
26 return f # pragma: nocover
29def test_incorrect_multipart_installed_file_bytes(monkeypatch): 1abcde
30 monkeypatch.delattr("multipart.multipart.parse_options_header", raising=False) 1pqrst
31 with pytest.raises(RuntimeError, match=multipart_incorrect_install_error): 1pqrst
32 app = FastAPI() 1pqrst
34 @app.post("/") 1pqrst
35 async def root(f: bytes = File()): 1pqrst
36 return f # pragma: nocover
39def test_incorrect_multipart_installed_multi_form(monkeypatch): 1abcde
40 monkeypatch.delattr("multipart.multipart.parse_options_header", raising=False) 1uvwxy
41 with pytest.raises(RuntimeError, match=multipart_incorrect_install_error): 1uvwxy
42 app = FastAPI() 1uvwxy
44 @app.post("/") 1uvwxy
45 async def root(username: str = Form(), password: str = Form()): 1uvwxy
46 return username # pragma: nocover
49def test_incorrect_multipart_installed_form_file(monkeypatch): 1abcde
50 monkeypatch.delattr("multipart.multipart.parse_options_header", raising=False) 1zABCD
51 with pytest.raises(RuntimeError, match=multipart_incorrect_install_error): 1zABCD
52 app = FastAPI() 1zABCD
54 @app.post("/") 1zABCD
55 async def root(username: str = Form(), f: UploadFile = File()): 1zABCD
56 return username # pragma: nocover
59def test_no_multipart_installed(monkeypatch): 1abcde
60 monkeypatch.delattr("multipart.__version__", raising=False) 1EFGHI
61 with pytest.raises(RuntimeError, match=multipart_not_installed_error): 1EFGHI
62 app = FastAPI() 1EFGHI
64 @app.post("/") 1EFGHI
65 async def root(username: str = Form()): 1EFGHI
66 return username # pragma: nocover
69def test_no_multipart_installed_file(monkeypatch): 1abcde
70 monkeypatch.delattr("multipart.__version__", raising=False) 1JKLMN
71 with pytest.raises(RuntimeError, match=multipart_not_installed_error): 1JKLMN
72 app = FastAPI() 1JKLMN
74 @app.post("/") 1JKLMN
75 async def root(f: UploadFile = File()): 1JKLMN
76 return f # pragma: nocover
79def test_no_multipart_installed_file_bytes(monkeypatch): 1abcde
80 monkeypatch.delattr("multipart.__version__", raising=False) 1OPQRS
81 with pytest.raises(RuntimeError, match=multipart_not_installed_error): 1OPQRS
82 app = FastAPI() 1OPQRS
84 @app.post("/") 1OPQRS
85 async def root(f: bytes = File()): 1OPQRS
86 return f # pragma: nocover
89def test_no_multipart_installed_multi_form(monkeypatch): 1abcde
90 monkeypatch.delattr("multipart.__version__", raising=False) 1TUVWX
91 with pytest.raises(RuntimeError, match=multipart_not_installed_error): 1TUVWX
92 app = FastAPI() 1TUVWX
94 @app.post("/") 1TUVWX
95 async def root(username: str = Form(), password: str = Form()): 1TUVWX
96 return username # pragma: nocover
99def test_no_multipart_installed_form_file(monkeypatch): 1abcde
100 monkeypatch.delattr("multipart.__version__", raising=False) 1YZ012
101 with pytest.raises(RuntimeError, match=multipart_not_installed_error): 1YZ012
102 app = FastAPI() 1YZ012
104 @app.post("/") 1YZ012
105 async def root(username: str = Form(), f: UploadFile = File()): 1YZ012
106 return username # pragma: nocover