Use OAuth sessions for web API requests
This commit is contained in:
parent
e022872767
commit
118ec9fc9b
4 changed files with 125 additions and 7 deletions
14
test_api.py
14
test_api.py
|
|
@ -3,6 +3,7 @@ from unittest.mock import Mock, patch
|
|||
|
||||
from simplejson.scanner import JSONDecodeError
|
||||
|
||||
import web_view
|
||||
from add_links import api
|
||||
|
||||
|
||||
|
|
@ -25,6 +26,19 @@ class ApiGetTests(unittest.TestCase):
|
|||
|
||||
self.assertEqual(str(ctx.exception), response.text)
|
||||
|
||||
def test_active_session_uses_logged_in_request_session(self) -> None:
|
||||
oauth_session = Mock()
|
||||
|
||||
with web_view.app.test_request_context("/"):
|
||||
with patch(
|
||||
"add_links.mediawiki_oauth.get_oauth_session",
|
||||
return_value=oauth_session,
|
||||
):
|
||||
session, auth_mode = api._get_active_session()
|
||||
|
||||
self.assertIs(session, oauth_session)
|
||||
self.assertEqual(auth_mode, "oauth")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue