@@ -1032,3 +1032,49 @@ def test_is_enabled_works_with_properties_field_in_the_context_root():
10321032
10331033 context = {"myContext" : "1234" }
10341034 assert unleash_client .is_enabled ("customContextToggle" , context )
1035+
1036+
1037+ @responses .activate
1038+ def test_identification_headers_sent_and_consistent (unleash_client ):
1039+ responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 202 )
1040+ responses .add (
1041+ responses .GET , URL + FEATURES_URL , json = MOCK_FEATURE_RESPONSE , status = 200
1042+ )
1043+ responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 202 )
1044+ unleash_client .initialize_client ()
1045+
1046+ connection_id = responses .calls [0 ].request .headers ["X-UNLEASH-CONNECTION-ID" ]
1047+ app_name = responses .calls [0 ].request .headers ["X-UNLEASH-APPNAME" ]
1048+ sdk = responses .calls [0 ].request .headers ["X-UNLEASH-SDK" ]
1049+
1050+ for api_call in responses .calls :
1051+ assert api_call .request .headers ["X-UNLEASH-CONNECTION-ID" ] == connection_id
1052+ assert api_call .request .headers ["X-UNLEASH-APPNAME" ] == app_name
1053+ assert api_call .request .headers ["X-UNLEASH-SDK" ] == sdk
1054+
1055+
1056+ @responses .activate
1057+ def test_identification_headers_unique_connection_id ():
1058+ responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 202 )
1059+ responses .add (
1060+ responses .GET , URL + FEATURES_URL , json = MOCK_FEATURE_RESPONSE , status = 200
1061+ )
1062+ responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 202 )
1063+
1064+ unleash_client = UnleashClient (
1065+ URL , APP_NAME , disable_metrics = True , disable_registration = True
1066+ )
1067+ unleash_client .initialize_client ()
1068+ connection_id_first_client = responses .calls [0 ].request .headers [
1069+ "X-UNLEASH-CONNECTION-ID"
1070+ ]
1071+
1072+ other_unleash_client = UnleashClient (
1073+ URL , APP_NAME , disable_metrics = True , disable_registration = True
1074+ )
1075+ other_unleash_client .initialize_client ()
1076+
1077+ connection_id_second_client = responses .calls [1 ].request .headers [
1078+ "X-UNLEASH-CONNECTION-ID"
1079+ ]
1080+ assert connection_id_first_client != connection_id_second_client
0 commit comments