1
- import time
1
+ import json
2
2
import os
3
+ import time
3
4
import unittest
4
- import json
5
-
6
- from typing import Optional , Union , Callable
7
-
5
+ from typing import Union
8
6
from unittest .mock import patch
7
+
9
8
from gzip_helpers import GzipHelpers
10
9
from network_stub import NetworkStub
11
- from statsig import statsig , StatsigUser , StatsigOptions , StatsigEvent , StatsigEnvironmentTier , DynamicConfig , Layer , FeatureGate
10
+ from statsig import statsig , StatsigUser , StatsigOptions , StatsigEnvironmentTier , DynamicConfig , Layer , \
11
+ FeatureGate
12
12
13
13
with open (os .path .join (os .path .abspath (os .path .dirname (__file__ )), '../testdata/download_config_specs.json' )) as r :
14
14
CONFIG_SPECS_RESPONSE = r .read ()
@@ -22,6 +22,7 @@ class TestEvalCallback(unittest.TestCase):
22
22
_gateName = ""
23
23
_configName = ""
24
24
_layerName = ""
25
+ _spec_match = False
25
26
26
27
@classmethod
27
28
@patch ('requests.request' , side_effect = _network_stub .mock )
@@ -47,19 +48,24 @@ def log_event_callback(url: str, **kwargs):
47
48
"regular_user_id" ,
email = "[email protected] " ,
private_attributes = {
"test" :
123 })
48
49
cls .random_user = StatsigUser ("random" )
49
50
cls ._logs = {}
51
+
50
52
def callback_func (config : Union [DynamicConfig , FeatureGate , Layer ]):
51
53
if isinstance (config , FeatureGate ):
52
54
cls ._gateName = config .get_name ()
53
55
if isinstance (config , DynamicConfig ):
54
56
cls ._configName = config .get_name ()
55
57
if isinstance (config , Layer ):
56
58
cls ._layerName = config .get_name ()
57
-
59
+
60
+ def specs_callback (specs : str ):
61
+ cls ._spec_match = json .loads (specs ) == json .loads (CONFIG_SPECS_RESPONSE )
62
+
58
63
options = StatsigOptions (
59
64
api = _network_stub .host ,
60
65
tier = StatsigEnvironmentTier .development ,
61
66
disable_diagnostics = True ,
62
- evaluation_callback = callback_func )
67
+ evaluation_callback = callback_func ,
68
+ rules_updated_callback = specs_callback , )
63
69
64
70
statsig .initialize ("secret-key" , options )
65
71
cls .initTime = round (time .time () * 1000 )
@@ -102,5 +108,9 @@ def test_c_experiment(self, mock_request):
102
108
"a_layer"
103
109
)
104
110
111
+ def test_d_spec_match (self , mock_request ):
112
+ self .assertTrue (self ._spec_match )
113
+
114
+
105
115
if __name__ == '__main__' :
106
116
unittest .main ()
0 commit comments