Skip to content

Commit

Permalink
Add test for handling various Content-Type headers
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkwang committed Apr 10, 2021
1 parent 6ecfba9 commit d752efd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_tutorial/test_body/test_tutorial001.py
Expand Up @@ -188,3 +188,37 @@ def test_post_broken_body():
response = client.post("/items/", json={"test": "test2"})
assert response.status_code == 400, response.text
assert response.json() == {"detail": "There was an error parsing the body"}


def test_explicit_content_type():
data = '{"name": "Foo", "price": 50.5}'
response = client.post(
"/items/", data=data, headers={"Content-Type": "applications/json"}
)
assert response.status_code == 200, response.text

data = '{"name": "Foo", "price": 50.5}'
response = client.post(
"/items/", data=data, headers={"Content-Type": "applications/geo+json"}
)
assert response.status_code == 200, response.text

invalid_dict = {
"detail": [
{
"loc": ["body"],
"msg": "value is not a valid dict",
"type": "type_error.dict",
}
]
}

response = client.post("/items/", data=data, headers={"Content-Type": "text/plain"})
assert response.status_code == 422, response.text
assert response.json() == invalid_dict

response = client.post(
"/items/", data=data, headers={"Content-Type": "application/geo+json-seq"}
)
assert response.status_code == 422, response.text
assert response.json() == invalid_dict

0 comments on commit d752efd

Please sign in to comment.