From 7b94c95c9db339302f58de9b35b1cc2c0be312b8 Mon Sep 17 00:00:00 2001 From: Shanin Roman Date: Thu, 13 Jun 2024 12:10:09 +0300 Subject: [PATCH] fix: adjust torii pytests Signed-off-by: Shanin Roman --- .../configuration/test_post_configuration.py | 41 +++++++++++++++++-- .../test/general/test_200_status_codes.py | 2 +- .../test/general/test_400_status_codes.py | 14 +++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/torii/pytests/test/configuration/test_post_configuration.py b/torii/pytests/test/configuration/test_post_configuration.py index f4e8281b036..6c74c9ed216 100644 --- a/torii/pytests/test/configuration/test_post_configuration.py +++ b/torii/pytests/test/configuration/test_post_configuration.py @@ -17,14 +17,49 @@ def setup_configuration(): @allure.id("1552") -@allure.label("status_code", "400") +@allure.label("status_code", "422") def test_post_configuration_invalid_data(): - with allure.step("WHEN I send POST request with invalid data to /configuration"): + with allure.step( + "WHEN I send POST request with valid json with invalid data to /configuration" + ): + response = requests.post( + f"{BASE_URL}/configuration", + json={"logger": {"level": "invalid"}}, + ) + + with allure.step("THEN the response status code should be a client error"): + assert ( + 422 == response.status_code + ), "Response status code is not a client or server error for invalid data" + + +@allure.id("1553") +@allure.label("status_code", "415") +def test_post_configuration_no_header(): + with allure.step( + "WHEN I send POST request without content type json header to /configuration" + ): response = requests.post( f"{BASE_URL}/configuration", data=json.dumps({"logger": {"level": "invalid"}}), ) + with allure.step("THEN the response status code should be a client error"): + assert ( + 415 == response.status_code + ), "Response status code is not a client or server error for invalid data" + + +@allure.id("1554") +@allure.label("status_code", "400") +def test_post_configuration_invalid_json(): + with allure.step("WHEN I send POST request with invalid json to /configuration"): + response = requests.post( + f"{BASE_URL}/configuration", + data="i'm not json", + headers={"Content-type": "application/json"}, + ) + with allure.step("THEN the response status code should be a client error"): assert ( 400 == response.status_code @@ -39,7 +74,7 @@ def test_post_configuration_valid_logger_level(log_level): ): requests.post( f"{BASE_URL}/configuration", - data=json.dumps({"logger": {"level": log_level}}), + json={"logger": {"level": log_level}}, ) with allure.step(f"THEN the log level should be {log_level}"): diff --git a/torii/pytests/test/general/test_200_status_codes.py b/torii/pytests/test/general/test_200_status_codes.py index 72d118b69e8..2b5db7c0d2a 100644 --- a/torii/pytests/test/general/test_200_status_codes.py +++ b/torii/pytests/test/general/test_200_status_codes.py @@ -24,7 +24,7 @@ def test_post_configuration_logger_level(log_level): ): response = requests.post( f"{BASE_URL}/configuration", - data=json.dumps({"logger": {"level": log_level}}), + json={"logger": {"level": log_level}}, ) with allure.step("THEN the response should be accepted"): diff --git a/torii/pytests/test/general/test_400_status_codes.py b/torii/pytests/test/general/test_400_status_codes.py index 863e9dac276..7fa72b4cbe1 100644 --- a/torii/pytests/test/general/test_400_status_codes.py +++ b/torii/pytests/test/general/test_400_status_codes.py @@ -12,14 +12,14 @@ def status_codes_400(): @allure.id("1255") @allure.label("method", "GET") -@allure.label("status_code", "405") -def test_method_not_allowed(): - with allure.step("WHEN I send GET request to /method_not_allowed"): - response = requests.get(f"{BASE_URL}/method_not_allowed") - with allure.step("THEN the response status code should be 405"): +@allure.label("status_code", "404") +def test_method_not_found(): + with allure.step("WHEN I send GET request to /method_not_found"): + response = requests.get(f"{BASE_URL}/method_not_found") + with allure.step("THEN the response status code should be 404"): assert ( - response.status_code == 405 - ), "Status code is not 405 for /method_not_allowed" + response.status_code == 404 + ), "Status code is not 404 for /method_not_found" @allure.id("1288")