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