@@ -50,18 +50,27 @@ def setUp(self):
50
50
}
51
51
52
52
def test_returns_decision_from_cache_when_valid (self ):
53
+ expected_key = self .cmab_service ._get_cache_key ("user123" , "exp1" )
54
+ expected_attributes = {"age" : 25 , "location" : "USA" }
55
+ expected_hash = self .cmab_service ._hash_attributes (expected_attributes )
56
+
53
57
self .mock_cmab_cache .lookup .return_value = {
54
- "attributes_hash" : self . cmab_service . _hash_attributes ({ "age" : 25 , "location" : "USA" }) ,
58
+ "attributes_hash" : expected_hash ,
55
59
"variation_id" : "varA" ,
56
60
"cmab_uuid" : "uuid-123"
57
61
}
58
62
59
- decision = self .cmab_service .get_decision (self .mock_project_config , self .mock_user_context , "exp1" , [])
63
+ decision = self .cmab_service .get_decision (
64
+ self .mock_project_config , self .mock_user_context , "exp1" , []
65
+ )
66
+
67
+ self .mock_cmab_cache .lookup .assert_called_once_with (expected_key )
60
68
self .assertEqual (decision ["variation_id" ], "varA" )
61
69
self .assertEqual (decision ["cmab_uuid" ], "uuid-123" )
62
70
63
71
def test_ignores_cache_when_option_given (self ):
64
72
self .mock_cmab_client .fetch_decision .return_value = "varB"
73
+ expected_attributes = {"age" : 25 , "location" : "USA" }
65
74
66
75
decision = self .cmab_service .get_decision (
67
76
self .mock_project_config ,
@@ -72,11 +81,16 @@ def test_ignores_cache_when_option_given(self):
72
81
73
82
self .assertEqual (decision ["variation_id" ], "varB" )
74
83
self .assertIn ('cmab_uuid' , decision )
75
- self .mock_cmab_client .fetch_decision .assert_called_once ()
84
+ self .mock_cmab_client .fetch_decision .assert_called_once_with (
85
+ "exp1" ,
86
+ self .mock_user_context .user_id ,
87
+ expected_attributes ,
88
+ decision ["cmab_uuid" ]
89
+ )
76
90
77
91
def test_invalidates_user_cache_when_option_given (self ):
78
92
self .mock_cmab_client .fetch_decision .return_value = "varC"
79
-
93
+ self . mock_cmab_cache . lookup . return_value = None
80
94
self .cmab_service .get_decision (
81
95
self .mock_project_config ,
82
96
self .mock_user_context ,
0 commit comments