@@ -141,6 +141,21 @@ def test_client_is_cached_per_request(app, github):
141141 assert github .client () is github .client ()
142142
143143
144+ def test_clients_are_cached_per_extension_instance (app ):
145+ first = flask_githubkit .GitHub ()
146+ second = flask_githubkit .GitHub ()
147+
148+ with app .test_request_context ():
149+ flask .session ["flask_githubkit.token" ] = SAMPLE_TOKEN
150+
151+ first_client = first .client ()
152+ second_client = second .client ()
153+
154+ assert first_client is not second_client
155+ assert first .client () is first_client
156+ assert second .client () is second_client
157+
158+
144159def test_invalid_stored_token_is_cleared (app , github ):
145160 with app .test_request_context ():
146161 flask .session ["flask_githubkit.token" ] = {
@@ -186,6 +201,32 @@ def test_logout_removes_stored_token(app, github):
186201 assert "flask_githubkit.token" not in flask .session
187202
188203
204+ def test_logout_invalidates_cached_client_in_the_same_request (app , github ):
205+ with app .test_request_context ():
206+ flask .session ["flask_githubkit.token" ] = SAMPLE_TOKEN
207+ client = github .client ()
208+ assert client is not None
209+
210+ github .logout ()
211+
212+ assert github .client () is None
213+
214+
215+ def test_logout_invalidates_all_cached_clients (app ):
216+ first = flask_githubkit .GitHub ()
217+ second = flask_githubkit .GitHub ()
218+
219+ with app .test_request_context ():
220+ flask .session ["flask_githubkit.token" ] = SAMPLE_TOKEN
221+ assert first .client () is not None
222+ assert second .client () is not None
223+
224+ first .logout ()
225+
226+ assert first .client () is None
227+ assert second .client () is None
228+
229+
189230def test_expired_refresh_token_clears_session_and_redirects_to_login (
190231 app , http_client
191232):
0 commit comments