@@ -410,47 +410,71 @@ def test_uc_metrics(unleash_client):
410410
411411
412412@responses .activate
413- def test_uc_disabled_registration (unleash_client_toggle_only ):
414- unleash_client = unleash_client_toggle_only
415- # Set up APIs
416- responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 401 )
413+ def test_uc_registers_metrics_for_nonexistent_features (unleash_client ):
414+ # Set up API
415+ responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 202 )
417416 responses .add (
418417 responses .GET , URL + FEATURES_URL , json = MOCK_FEATURE_RESPONSE , status = 200
419418 )
420- responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 401 )
419+ responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 202 )
421420
421+ # Create Unleash client and check initial load
422422 unleash_client .initialize_client ()
423- unleash_client .is_enabled ("testFlag" )
424- time .sleep (20 )
425- assert unleash_client .is_enabled ("testFlag" )
423+ time .sleep (1 )
426424
427- for api_call in responses . calls :
428- assert "/api/client/features" in api_call . request . url
425+ # Check a flag that doesn't exist
426+ unleash_client . is_enabled ( "nonexistent-flag" )
429427
428+ # Verify that the metrics are serialized
429+ time .sleep (12 )
430+ request = json .loads (responses .calls [- 1 ].request .body )
431+ assert request ["bucket" ]["toggles" ]["nonexistent-flag" ]["no" ] == 1
430432
431- @responses .activate
432- def test_uc_server_error (unleash_client ):
433- # Verify that Unleash Client will still fall back gracefully if SERVER ANGRY RAWR, and then recover gracefully.
434433
435- unleash_client = unleash_client
436- # Set up APIs
437- responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 401 )
438- responses .add (responses .GET , URL + FEATURES_URL , status = 500 )
439- responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 401 )
434+ @responses .activate
435+ def test_uc_registers_variant_metrics_for_nonexistent_features (unleash_client ):
436+ # Set up API
437+ responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 202 )
438+ responses .add (
439+ responses .GET , URL + FEATURES_URL , json = MOCK_FEATURE_RESPONSE , status = 200
440+ )
441+ responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 202 )
440442
443+ # Create Unleash client and check initial load
441444 unleash_client .initialize_client ()
442- assert not unleash_client . is_enabled ( "testFlag" )
445+ time . sleep ( 1 )
443446
444- responses .remove (responses .GET , URL + FEATURES_URL )
447+ # Check a flag that doesn't exist
448+ unleash_client .get_variant ("nonexistent-flag" )
449+
450+ # Verify that the metrics are serialized
451+ time .sleep (12 )
452+ request = json .loads (responses .calls [- 1 ].request .body )
453+ assert request ["bucket" ]["toggles" ]["nonexistent-flag" ]["no" ] == 1
454+ assert request ["bucket" ]["toggles" ]["nonexistent-flag" ]["variants" ]["disabled" ] == 1
455+
456+
457+ @responses .activate
458+ def test_uc_disabled_registration (unleash_client_toggle_only ):
459+ unleash_client = unleash_client_toggle_only
460+ # Set up APIs
461+ responses .add (responses .POST , URL + REGISTER_URL , json = {}, status = 401 )
445462 responses .add (
446463 responses .GET , URL + FEATURES_URL , json = MOCK_FEATURE_RESPONSE , status = 200
447464 )
465+ responses .add (responses .POST , URL + METRICS_URL , json = {}, status = 401 )
466+
467+ unleash_client .initialize_client ()
468+ unleash_client .is_enabled ("testFlag" )
448469 time .sleep (20 )
449470 assert unleash_client .is_enabled ("testFlag" )
450471
472+ for api_call in responses .calls :
473+ assert "/api/client/features" in api_call .request .url
474+
451475
452476@responses .activate
453- def test_uc_server_error_recovery (unleash_client ):
477+ def test_uc_server_error (unleash_client ):
454478 # Verify that Unleash Client will still fall back gracefully if SERVER ANGRY RAWR, and then recover gracefully.
455479
456480 unleash_client = unleash_client
@@ -682,7 +706,7 @@ def test_multiple_instances_no_warnings_or_errors_with_different_client_configs(
682706 UnleashClient (
683707 URL , "some-probably-unique-but-different-app-name" , refresh_interval = "60"
684708 )
685- assert not all (
709+ assert not any (
686710 ["Multiple instances has been disabled" in r .msg for r in caplog .records ]
687711 )
688712
@@ -698,7 +722,7 @@ def test_multiple_instances_are_unique_on_api_key(caplog):
698722 "some-probably-unique-app-name" ,
699723 custom_headers = {"Authorization" : "hamsters" },
700724 )
701- assert not all (
725+ assert not any (
702726 ["Multiple instances has been disabled" in r .msg for r in caplog .records ]
703727 )
704728
0 commit comments