File tree Expand file tree Collapse file tree
atlassian_jwt_auth/frameworks/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import unittest
2+
3+ from atlassian_jwt_auth .frameworks .common import utils
4+
5+
6+ class SettingsDictTest (unittest .TestCase ):
7+ """ Tests for the SettingsDict class. """
8+
9+ def test_hash (self ):
10+ """ Test that SettingsDict instances can be hashed. """
11+ dictionary_one = {'a' : 'b' , '3' : set ([1 ]), 'f' : None }
12+ dictionary_two = {'a' : 'b' , '3' : set ([1 ]), 'f' : None }
13+ dictionary_three = {'a' : 'b' , '3' : set ([1 ]), 'diff' : '333' }
14+ settings_one = utils .SettingsDict (dictionary_one )
15+ settings_two = utils .SettingsDict (dictionary_two )
16+ settings_three = utils .SettingsDict (dictionary_three )
17+ self .assertEqual (settings_one , settings_two )
18+ self .assertEqual (hash (settings_one ), hash (settings_two ))
19+ self .assertNotEqual (settings_one , settings_three )
20+ self .assertNotEqual (hash (settings_one ), hash (settings_three ))
Original file line number Diff line number Diff line change @@ -7,3 +7,17 @@ def __getattr__(self, name):
77
88 def __setitem__ (self , key , value ):
99 raise AttributeError ('SettingsDict properties are immutable' )
10+
11+ def _hash_key (self ):
12+ keys_and_values = []
13+ for key , value in self .items ():
14+ if isinstance (value , set ):
15+ value = frozenset (value )
16+ keys_and_values .append ("%s %s" % (key , hash (value )))
17+ return frozenset (keys_and_values )
18+
19+ def __hash__ (self ):
20+ return hash (self ._hash_key ())
21+
22+ def __eq__ (self , other ):
23+ return hash (self ) == hash (other )
You can’t perform that action at this time.
0 commit comments