From c058c7513c2f83d95030da90030dcd417cba2240 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Sat, 26 Aug 2023 17:19:32 +0200 Subject: [PATCH] RED: test for message and status_code --- utests/test_api.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/utests/test_api.py b/utests/test_api.py index b6ccb71..64ed2ec 100644 --- a/utests/test_api.py +++ b/utests/test_api.py @@ -125,6 +125,66 @@ class ApiTestCase(unittest.TestCase): == be_the_fun_in_de_funes[attribute_name] ) + def test_payload_content_bad_format_status_code(self): + be_the_fun_in_de_funes = { + "id": 1, + "title": "La Grande Vadrouille", + "description": "During World War II, two French civilians and a downed English Bomber Crew set " + "out from Paris to cross the demarcation line between Nazi-occupied Northern France and the " + "South. From there they will be able to escape to England. First, they must avoid German troops -" + "and the consequences of their own blunders.", + "genres": ["Comedy", "War"], + "release_date": "1966-12-07", + "vote_average": 7.7, + "vote_count": 1123, + } + + domain_keys = sorted( + {k for k in be_the_fun_in_de_funes if k not in ["id"]} + ) # Make it deterministic + + payload = {k: be_the_fun_in_de_funes[k] for k in domain_keys} + + missing_key = "title" + + payload.pop(missing_key) + + response = client.post("/pydantic_movies/", json=payload) + + assert 400 <= response.status_code < 500 + + assert missing_key in response.text + + def test_payload_content_bad_format_detail(self): + be_the_fun_in_de_funes = { + "id": 1, + "title": "La Grande Vadrouille", + "description": "During World War II, two French civilians and a downed English Bomber Crew set " + "out from Paris to cross the demarcation line between Nazi-occupied Northern France and the " + "South. From there they will be able to escape to England. First, they must avoid German troops -" + "and the consequences of their own blunders.", + "genres": ["Comedy", "War"], + "release_date": "1966-12-07", + "vote_average": 7.7, + "vote_count": 1123, + } + + domain_keys = sorted( + {k for k in be_the_fun_in_de_funes if k not in ["id"]} + ) # Make it deterministic + + payload = {k: be_the_fun_in_de_funes[k] for k in domain_keys} + + missing_key = "title" + + payload.pop(missing_key) + + response = client.post("/pydantic_movies/", json=payload) + + assert 400 <= response.status_code < 500 + + assert response.status_code == 400 + def test_payload_content_in_and_out_loopback_pydantic(self): be_the_fun_in_de_funes = { "id": 1,