@@ -24,17 +24,28 @@ def setUp(self):
2424 def mock_get (key ):
2525 return self .storage_dict .get (key )
2626
27- def mock_set (key , value ):
27+ def mock_setItems (key , value ):
2828 self .storage_dict [key ] = value
2929
30+ def mock_set_flat (access_token ):
31+ self .storage_dict ["_flat_access_token" ] = access_token
32+
3033 def mock_delete (key ):
3134 if key in self .storage_dict :
3235 del self .storage_dict [key ]
33-
34- # Configure the mock
36+
37+ def mock_clear_device_data ():
38+ # This would clear all device-specific data
39+ # For test simplicity, let's just remove the user_id we're testing with
40+ if self .user_id in self .storage_dict :
41+ del self .storage_dict [self .user_id ]
42+
43+ # Configure the mock with the correct method names
3544 self .mock_storage_manager .get .side_effect = mock_get
36- self .mock_storage_manager .set .side_effect = mock_set
45+ self .mock_storage_manager .setItems .side_effect = mock_setItems
46+ self .mock_storage_manager .set .side_effect = mock_set_flat
3747 self .mock_storage_manager .delete .side_effect = mock_delete
48+ self .mock_storage_manager .clear_device_data .side_effect = mock_clear_device_data
3849
3950 # Patch the StorageManager's __new__ method to return our mock
4051 patcher = patch ('kinde_sdk.auth.user_session.StorageManager' )
@@ -70,10 +81,10 @@ def test_set_user_data(self):
7081 self .user_session .set_user_data (self .user_id , self .user_info , self .token_data )
7182
7283 # Check storage was set correctly
73- self .mock_storage_manager .set .assert_called ()
84+ self .mock_storage_manager .setItems .assert_called ()
7485
7586 # Check the key and ensure at least some of the data was stored
76- args , kwargs = self .mock_storage_manager .set .call_args
87+ args , kwargs = self .mock_storage_manager .setItems .call_args
7788 self .assertEqual (args [0 ], self .user_id ) # First arg should be the key (user_id)
7889
7990 # Check memory state
@@ -183,7 +194,7 @@ def test_logout(self):
183194 self .user_session .set_user_data (self .user_id , self .user_info , self .token_data )
184195
185196 # Reset the mock count
186- self .mock_storage_manager .delete .reset_mock ()
197+ self .mock_storage_manager .clear_device_data .reset_mock ()
187198
188199 # Mock token revocation
189200 with patch .object (TokenManager , 'revoke_token' ) as mock_revoke :
@@ -196,8 +207,8 @@ def test_logout(self):
196207 # Check memory was cleaned
197208 self .assertNotIn (self .user_id , self .user_session .user_sessions )
198209
199- # Check storage delete was called with correct user_id
200- self .mock_storage_manager .delete . assert_called_once_with ( self . user_id )
210+ # Check clear_device_data was called instead of delete
211+ self .mock_storage_manager .clear_device_data . assert_called_once ( )
201212
202213 # Check storage dict was updated
203214 self .assertNotIn (self .user_id , self .storage_dict )
@@ -262,47 +273,4 @@ def test_cleanup_expired_sessions(self):
262273
263274
264275if __name__ == "__main__" :
265- pytest .main (["-xvs" , __file__ ])
266-
267-
268- # @pytest.mark.timeout(5) # 5 second timeout
269- # def test_is_authenticated_expired(self):
270- # """Test is_authenticated with expired token"""
271- # # Set token data with expired token
272- # expired_token_data = {
273- # "access_token": "expired_token",
274- # "expires_in": -100 # Expired
275- # }
276-
277- # # Set up with JWT decode mock
278- # with patch('jwt.decode') as mock_decode, \
279- # patch('requests.post', side_effect=Exception("Network requests disabled in tests")), \
280- # patch('kinde_sdk.auth.token_manager.TokenManager.get_access_token',
281- # side_effect=ValueError("Token expired")):
282-
283- # mock_decode.return_value = {"sub": "user123"}
284- # self.user_session.set_user_data(self.user_id, self.user_info, expired_token_data)
285-
286- # # Check authentication - should fail
287- # self.assertFalse(self.user_session.is_authenticated(self.user_id))
288-
289- # @pytest.mark.timeout(5) # 5 second timeout
290- # def test_is_authenticated_valid(self):
291- # """Test is_authenticated with valid token"""
292- # # Set up with valid token
293- # valid_token_data = {
294- # "access_token": "valid_access_token",
295- # "expires_in": 3600
296- # }
297-
298- # # Set up with JWT decode mock
299- # with patch('jwt.decode') as mock_decode, \
300- # patch('requests.post', side_effect=Exception("Network requests disabled in tests")), \
301- # patch('kinde_sdk.auth.token_manager.TokenManager.get_access_token',
302- # return_value="valid_access_token"):
303-
304- # mock_decode.return_value = {"sub": "user123"}
305- # self.user_session.set_user_data(self.user_id, self.user_info, valid_token_data)
306-
307- # # Check authentication - should succeed
308- # self.assertTrue(self.user_session.is_authenticated(self.user_id))
276+ pytest .main (["-xvs" , __file__ ])
0 commit comments