55from oauth2 .datatype import AccessToken , AuthorizationCode , Client
66from oauth2 .error import AccessTokenNotFound , AuthCodeNotFound ,\
77 ClientNotFoundError
8- from oauth2 .store import ClientStore
98
109class MongodbAccessTokenStoreTestCase (unittest .TestCase ):
1110 def setUp (self ):
@@ -25,10 +24,7 @@ def test_fetch_by_refresh_token(self):
2524 collection_mock = Mock (spec = ["find_one" ])
2625 collection_mock .find_one .return_value = self .access_token_data
2726
28- db_mock = {"access_tokens" : collection_mock }
29-
30- store = MongodbAccessTokenStore (collection = "access_tokens" ,
31- db = db_mock )
27+ store = MongodbAccessTokenStore (collection = collection_mock )
3228 token = store .fetch_by_refresh_token (refresh_token = refresh_token )
3329
3430 collection_mock .find_one .assert_called_with (
@@ -40,10 +36,7 @@ def test_fetch_by_refresh_token_no_data(self):
4036 collection_mock = Mock (spec = ["find_one" ])
4137 collection_mock .find_one .return_value = None
4238
43- db_mock = {"access_tokens" : collection_mock }
44-
45- store = MongodbAccessTokenStore (collection = "access_tokens" ,
46- db = db_mock )
39+ store = MongodbAccessTokenStore (collection = collection_mock )
4740
4841 with self .assertRaises (AccessTokenNotFound ):
4942 store .fetch_by_refresh_token (refresh_token = "abcd" )
@@ -53,10 +46,7 @@ def test_save_token(self):
5346
5447 collection_mock = Mock (spec = ["insert" ])
5548
56- db_mock = {"access_tokens" : collection_mock }
57-
58- store = MongodbAccessTokenStore (collection = "access_tokens" ,
59- db = db_mock )
49+ store = MongodbAccessTokenStore (collection = collection_mock )
6050 store .save_token (access_token )
6151
6252 collection_mock .insert .assert_called_with (self .access_token_data )
@@ -69,19 +59,14 @@ def setUp(self):
6959
7060 self .collection_mock = Mock (spec = ["find_one" , "insert" , "remove" ])
7161
72- self .collection_name = "auth_codes"
73-
74- self .db_mock = {self .collection_name : self .collection_mock }
75-
7662 def test_fetch_by_code (self ):
7763 code = "abcd"
7864
7965 self .collection_mock .find_one .return_value = self .auth_code_data
8066
8167 self .auth_code_data ["code" ] = "abcd"
8268
83- store = MongodbAuthCodeStore (collection = self .collection_name ,
84- db = self .db_mock )
69+ store = MongodbAuthCodeStore (collection = self .collection_mock )
8570 auth_code = store .fetch_by_code (code = code )
8671
8772 self .collection_mock .find_one .assert_called_with ({"code" : "abcd" })
@@ -91,8 +76,7 @@ def test_fetch_by_code(self):
9176 def test_fetch_by_code_no_data (self ):
9277 self .collection_mock .find_one .return_value = None
9378
94- store = MongodbAuthCodeStore (collection = self .collection_name ,
95- db = self .db_mock )
79+ store = MongodbAuthCodeStore (collection = self .collection_mock )
9680
9781 with self .assertRaises (AuthCodeNotFound ):
9882 store .fetch_by_code (code = "abcd" )
@@ -102,8 +86,7 @@ def test_save_code(self):
10286
10387 auth_code = AuthorizationCode (** self .auth_code_data )
10488
105- store = MongodbAuthCodeStore (collection = self .collection_name ,
106- db = self .db_mock )
89+ store = MongodbAuthCodeStore (collection = self .collection_mock )
10790 store .save_code (auth_code )
10891
10992 self .collection_mock .insert .assert_called_with (self .auth_code_data )
@@ -116,9 +99,7 @@ def test_fetch_by_client_id(self):
11699 collection_mock = Mock (spec = ["find_one" ])
117100 collection_mock .find_one .return_value = client_data
118101
119- db_mock = {"clients" : collection_mock }
120-
121- store = MongodbClientStore (collection = "clients" , db = db_mock )
102+ store = MongodbClientStore (collection = collection_mock )
122103 client = store .fetch_by_client_id (client_id = client_data ["identifier" ])
123104
124105 collection_mock .find_one .assert_called_with ({
@@ -130,9 +111,7 @@ def test_fetch_by_client_id_no_data(self):
130111 collection_mock = Mock (spec = ["find_one" ])
131112 collection_mock .find_one .return_value = None
132113
133- db_mock = {"clients" : collection_mock }
134-
135- store = MongodbClientStore (collection = "clients" , db = db_mock )
114+ store = MongodbClientStore (collection = collection_mock )
136115
137116 with self .assertRaises (ClientNotFoundError ):
138117 store .fetch_by_client_id (client_id = "testclient" )
0 commit comments