RED: test for message and status_code

This commit is contained in:
Colin Goutte 2023-08-26 17:19:32 +02:00
parent 2a02a839b7
commit c058c7513c
1 changed files with 60 additions and 0 deletions

View File

@ -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,