Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d752efd

Browse files
committed
Add test for handling various Content-Type headers
1 parent 6ecfba9 commit d752efd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_tutorial/test_body/test_tutorial001.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,37 @@ def test_post_broken_body():
188188
response = client.post("/items/", json={"test": "test2"})
189189
assert response.status_code == 400, response.text
190190
assert response.json() == {"detail": "There was an error parsing the body"}
191+
192+
193+
def test_explicit_content_type():
194+
data = '{"name": "Foo", "price": 50.5}'
195+
response = client.post(
196+
"/items/", data=data, headers={"Content-Type": "applications/json"}
197+
)
198+
assert response.status_code == 200, response.text
199+
200+
data = '{"name": "Foo", "price": 50.5}'
201+
response = client.post(
202+
"/items/", data=data, headers={"Content-Type": "applications/geo+json"}
203+
)
204+
assert response.status_code == 200, response.text
205+
206+
invalid_dict = {
207+
"detail": [
208+
{
209+
"loc": ["body"],
210+
"msg": "value is not a valid dict",
211+
"type": "type_error.dict",
212+
}
213+
]
214+
}
215+
216+
response = client.post("/items/", data=data, headers={"Content-Type": "text/plain"})
217+
assert response.status_code == 422, response.text
218+
assert response.json() == invalid_dict
219+
220+
response = client.post(
221+
"/items/", data=data, headers={"Content-Type": "application/geo+json-seq"}
222+
)
223+
assert response.status_code == 422, response.text
224+
assert response.json() == invalid_dict

0 commit comments

Comments
 (0)