1+ from random import random
12from unittest .mock import patch
23
34import sentry_sdk
45from sentry_sdk .integrations .unleash import UnleashIntegration
5- from tests .integrations .unleash import MockUnleashClient
6+ from tests .integrations .unleash . testutils import MockUnleashClient
67
78original_is_enabled = MockUnleashClient .is_enabled
89original_get_variant = MockUnleashClient .get_variant
910
1011
1112@patch ("sentry_sdk.integrations.unleash.UnleashClient" , MockUnleashClient )
1213def test_is_enabled (sentry_init , capture_events , reset_integration ):
13- mock_unleash_client = MockUnleashClient ()
14+ client = MockUnleashClient ()
1415 reset_integration (UnleashIntegration .identifier )
1516 sentry_init (integrations = [UnleashIntegration ()])
1617
17- mock_unleash_client .is_enabled ("hello" )
18- mock_unleash_client .is_enabled ("world" )
19- mock_unleash_client .is_enabled ("other" )
18+ client .is_enabled ("hello" )
19+ client .is_enabled ("world" )
20+ client .is_enabled ("other" )
2021
2122 events = capture_events ()
2223 sentry_sdk .capture_exception (Exception ("something wrong!" ))
@@ -33,16 +34,16 @@ def test_is_enabled(sentry_init, capture_events, reset_integration):
3334
3435@patch ("sentry_sdk.integrations.unleash.UnleashClient" , MockUnleashClient )
3536def test_get_variant (sentry_init , capture_events , reset_integration ):
36- mock_unleash_client = MockUnleashClient ()
37+ client = MockUnleashClient ()
3738 reset_integration (UnleashIntegration .identifier )
3839 sentry_init (integrations = [UnleashIntegration ()])
3940
40- mock_unleash_client .get_variant ("toggle_feature" )
41- mock_unleash_client .get_variant ("string_feature" )
42- mock_unleash_client .get_variant ("json_feature" )
43- mock_unleash_client .get_variant ("csv_feature" )
44- mock_unleash_client .get_variant ("number_feature" )
45- mock_unleash_client .get_variant ("unknown_feature" )
41+ client .get_variant ("toggle_feature" )
42+ client .get_variant ("string_feature" )
43+ client .get_variant ("json_feature" )
44+ client .get_variant ("csv_feature" )
45+ client .get_variant ("number_feature" )
46+ client .get_variant ("unknown_feature" )
4647
4748 events = capture_events ()
4849 sentry_sdk .capture_exception (Exception ("something wrong!" ))
@@ -56,6 +57,37 @@ def test_get_variant(sentry_init, capture_events, reset_integration):
5657 }
5758
5859
60+ @patch ("sentry_sdk.integrations.unleash.UnleashClient" , MockUnleashClient )
61+ def test_wraps_original (sentry_init , reset_integration ):
62+ reset_integration (UnleashIntegration .identifier )
63+
64+ with patch (
65+ "sentry_sdk.integrations.unleash.UnleashClient.is_enabled"
66+ ) as mock_is_enabled :
67+ with patch (
68+ "sentry_sdk.integrations.unleash.UnleashClient.get_variant"
69+ ) as mock_get_variant :
70+ mock_is_enabled .return_value = random () < 0.5
71+ mock_get_variant .return_value = {"enabled" : random () < 0.5 }
72+ sentry_init (integrations = [UnleashIntegration ()])
73+ client = MockUnleashClient ()
74+
75+ res = client .is_enabled ("test-flag" , "arg" , kwarg = 1 )
76+ assert res == mock_is_enabled .return_value
77+ assert mock_is_enabled .call_args == (
78+ (client , "test-flag" , "arg" ),
79+ {"kwarg" : 1 },
80+ )
81+
82+ res = client .get_variant ("test-flag" , "arg" , kwarg = 1 )
83+ assert res == mock_get_variant .return_value
84+ assert mock_get_variant .call_args == (
85+ (client , "test-flag" , "arg" ),
86+ {"kwarg" : 1 },
87+ )
88+
89+
90+ @patch ("sentry_sdk.integrations.unleash.UnleashClient" , MockUnleashClient )
5991def test_wrapper_attributes (sentry_init , reset_integration ):
6092 reset_integration (UnleashIntegration .identifier )
6193 sentry_init (integrations = [UnleashIntegration ()])
0 commit comments