From 930f70cb5c4d942c0eb4b26bf1244d2a9e01fb26 Mon Sep 17 00:00:00 2001 From: indhumitha Date: Sat, 6 Jun 2026 21:24:26 +0530 Subject: [PATCH] add unit tests for request_context --- backend/data/.api_key | 1 + testing/backend/unit/test_request_context.py | 33 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 backend/data/.api_key create mode 100644 testing/backend/unit/test_request_context.py diff --git a/backend/data/.api_key b/backend/data/.api_key new file mode 100644 index 00000000..b5346601 --- /dev/null +++ b/backend/data/.api_key @@ -0,0 +1 @@ +064fe8d7a9ceac7bc053699eab08e7fc9e2d21742664e5af7e572a60597aed5b \ No newline at end of file diff --git a/testing/backend/unit/test_request_context.py b/testing/backend/unit/test_request_context.py new file mode 100644 index 00000000..247314fd --- /dev/null +++ b/testing/backend/unit/test_request_context.py @@ -0,0 +1,33 @@ +from backend.secuscan.request_context import ( + get_request_id, + request_id_context, + set_request_id, +) + + +def test_set_request_id_override(): + request_id = set_request_id("custom-id") + + assert request_id == "custom-id" + assert get_request_id() == "custom-id" + + +def test_set_request_id_generates_id(monkeypatch): + monkeypatch.setattr( + "backend.secuscan.request_context.uuid4", + lambda: "fixed-uuid", + ) + + request_id = set_request_id() + + assert request_id == "fixed-uuid" + assert get_request_id() == "fixed-uuid" + + +def test_get_request_id_default(): + token = request_id_context.set("") + + try: + assert get_request_id() == "" + finally: + request_id_context.reset(token) \ No newline at end of file