@@ -188,3 +188,37 @@ def test_post_broken_body():
188
188
response = client .post ("/items/" , json = {"test" : "test2" })
189
189
assert response .status_code == 400 , response .text
190
190
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