def test_request_id_can_be_set_on_error(client): # Given that I have an existing request id # When I make a request to the app response = client.get("/fail", headers={"x-request-id": "a-request-id"}) # Then that same request id should appear in the response headers assert response.headers["x-request-id"] == "a-request-id" # And the request id for the current thread should be cleared assert RequestId.get_request_id() is None
def test_request_id_can_be_autogenerated(client): # Given that I don't have an existing request id # When I make a request to the app response = client.get("/") # Then my response should contain an autogenerated request id assert response.headers["x-request-id"] # And the request id for the current thread should be cleared assert RequestId.get_request_id() is None