From: Swaraj Kumar Date: Wed, 12 Mar 2025 12:54:15 +0000 (+0530) Subject: Problem details test case X-Git-Tag: 4.0.0~19 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=c05187bd5c5bd704a4c5ff60d7e489540d54bf5f;p=aiml-fw%2Fawmf%2Ftm.git Problem details test case Change-Id: Ifc069d399a2c12e632b109e65a78b0533e8e7742 Signed-off-by: Swaraj Kumar --- diff --git a/tests/test_problemdetails.py b/tests/test_problemdetails.py index c44d5eb..dad3fa4 100644 --- a/tests/test_problemdetails.py +++ b/tests/test_problemdetails.py @@ -20,3 +20,33 @@ def test_problem_details_initialization(): assert problem.title == "Bad Request" assert problem.detail == "Invalid input data" +def test_problem_details_to_dict(): + """ + Test that ProblemDetails generates the correct dictionary representation. + """ + problem = ProblemDetails(404, "Not Found", "The requested resource does not exist.") + expected_dict = { + "title": "Not Found", + "status": 404, + "detail": "The requested resource does not exist." + } + assert problem.to_dict() == expected_dict + +def test_problem_details_to_json(test_app): + """ + Test that ProblemDetails generates the correct Flask JSON response. + """ + problem = ProblemDetails(500, "Internal Server Error", "Something went wrong") + with Flask(__name__).test_request_context(): + response, status, headers = problem.to_json() + assert status == 500 + assert headers["Content-Type"] == "application/problem+json" + # Convert response data to JSON and compare + response_data = json.loads(response.get_data(as_text=True)) + expected_json = { + "title": "Internal Server Error", + "status": 500, + "detail": "Something went wrong" + } + assert response_data == expected_json +