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