def test_process_response(self): RequestTrack.set_request_track_id("test_request_track_id") self.middleware.process_response(req=None, res=falcon.Response(), resource=None, req_succeeded=None) self.assertIsNone(RequestTrack.get_request_track_id())
def process_request(self, req: Request, res: Response) -> NoReturn: new_request_track_id = req.get_header("request-track-id") if not new_request_track_id: new_request_track_id = str(uuid.uuid4()) logging.debug( f"New request-track-id generated: {new_request_track_id}") RequestTrack.set_request_track_id(new_request_track_id) logging.debug("Request Track ID loaded")
def test_process_request_with_headers(self): self.mock_wsgi_env["HTTP_REQUEST_TRACK_ID"] = "test_request_track_id" self.middleware.process_request( req=falcon.Request(env=self.mock_wsgi_env), res=None) self.assertEqual(RequestTrack.get_request_track_id(), "test_request_track_id")
def test_process_request_without_headers(self): self.middleware.process_request( req=falcon.Request(env=self.mock_wsgi_env), res=None) self.assertIsNotNone(RequestTrack.get_request_track_id())
def tearDown(self) -> None: RequestTrack.clear_request_track_id()
def test_set_request_track_id_life_cycle(self): expected = "request_track_id" RequestTrack.set_request_track_id(expected) self.assertEqual(RequestTrack.get_request_track_id(), expected) RequestTrack.clear_request_track_id() self.assertIsNone(RequestTrack.get_request_track_id())
def process_response(self, req: Request, res: Response, resource: BaseResource, req_succeeded: bool) -> NoReturn: res.set_headers( headers={"request-track-id": RequestTrack.get_request_track_id()}) RequestTrack.clear_request_track_id()