@@ -690,32 +690,40 @@ def test_build_response_include_values_that_are_not_null(client: FlaskClient):
690690
691691
692692@pytest .mark .parametrize (
693- ("headers" , "expected_log_msg " ),
693+ ("headers" , "expected_request_id " ),
694694 [
695+ ({"X-Request-ID" : "test-request-id-123" }, "test-request-id-123" ),
695696 (
696- {"X-Request-ID" : "test-request-id-123" , "X-Correlation-ID" : "test-correlation-id-456" },
697- "X-Request-ID: test-request-id-123, X-Correlation-ID: test-correlation-id-456" ,
698- ),
699- (
700- {"X-Request-ID" : "" , "X-Correlation-ID" : "" },
701- "X-Request-ID: , X-Correlation-ID: " ,
697+ {"X-Request-ID" : "" },
698+ "" ,
702699 ),
703700 (
704701 {}, # No headers provided
705- "X-Request-ID: None, X-Correlation-ID: None" ,
702+ None ,
706703 ),
707704 ],
708705)
709- def test_request_id_and_correlation_id_logging_variants (
710- app : Flask , client : FlaskClient , caplog , headers , expected_log_msg
706+ def test_request_id_from_header_logging_variants (
707+ app : Flask , client : FlaskClient , caplog , headers : dict [ str , str ], expected_request_id : str
711708):
709+ """
710+ This test checks that the x-request-ID is logged so that it can be used to correlate logs
711+ with that of the logs from api-gateway
712+ """
712713 with (
713714 get_app_container (app ).override .service (EligibilityService , new = FakeEligibilityService ()),
714715 get_app_container (app ).override .service (AuditService , new = FakeAuditService ()),
715716 ):
716717 with caplog .at_level (logging .INFO ):
717718 response = client .get ("/patient-check/12345" , headers = headers )
718719
719- log_messages = [record .getMessage () for record in caplog .records ]
720- assert any (expected_log_msg in message for message in log_messages )
720+ request_id_logged = False
721+ for record in caplog .records :
722+ request_id = getattr (record , "X-Request-ID" , None )
723+
724+ if request_id == expected_request_id :
725+ request_id_logged = True
726+ break
727+
728+ assert request_id_logged
721729 assert response .status_code == HTTPStatus .OK
0 commit comments