From 986d4c99bd5b069d7b068ad6aaa4d4a1795fb808 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Tue, 8 Dec 2020 11:24:07 +0100 Subject: [PATCH] Fix oauth ub session --- cps/gdriveutils.py | 2 +- cps/oauth_bb.py | 27 +- test/Calibre-Web TestSummary_Linux.html | 13538 ++++++++++++++++++++-- 3 files changed, 12707 insertions(+), 860 deletions(-) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 489bc6f5..1c5dec05 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -89,7 +89,7 @@ class Singleton: except AttributeError: self._instance = self._decorated() return self._instance - except ImportError as e: + except (ImportError, NameError) as e: log.debug(e) return None diff --git a/cps/oauth_bb.py b/cps/oauth_bb.py index 000a7376..620ff10e 100644 --- a/cps/oauth_bb.py +++ b/cps/oauth_bb.py @@ -100,25 +100,26 @@ def logout_oauth_user(): if ub.oauth_support: oauthblueprints = [] - if not g.ubsession.query(ub.OAuthProvider).count(): + oauth_session = ub.Scoped_Session() + if not oauth_session.query(ub.OAuthProvider).count(): oauthProvider = ub.OAuthProvider() oauthProvider.provider_name = "github" oauthProvider.active = False - g.ubsession.add(oauthProvider) + oauth_session.add(oauthProvider) try: - g.ubsession.commit() + oauth_session.commit() except OperationalError: - g.ubsession.rollback() + oauth_session.rollback() oauthProvider = ub.OAuthProvider() oauthProvider.provider_name = "google" oauthProvider.active = False - g.ubsession.add(oauthProvider) + oauth_session.add(oauthProvider) try: - g.ubsession.commit() + oauth_session.commit() except OperationalError: - g.ubsession.rollback() + oauth_session.rollback() - oauth_ids = g.ubsession.query(ub.OAuthProvider).all() + oauth_ids = oauth_session.query(ub.OAuthProvider).all() ele1 = dict(provider_name='github', id=oauth_ids[0].id, active=oauth_ids[0].active, @@ -148,7 +149,7 @@ if ub.oauth_support: scope=element['scope'] ) element['blueprint'] = blueprint - element['blueprint'].backend = OAuthBackend(ub.OAuth, g.ubsession, str(element['id']), + element['blueprint'].backend = OAuthBackend(ub.OAuth, oauth_session, str(element['id']), user=current_user, user_required=True) app.register_blueprint(blueprint, url_prefix="/login") if element['active']: @@ -192,7 +193,7 @@ if ub.oauth_support: session[provider_id + "_oauth_token"] = token # Find this OAuth token in the database, or create it - query = g.ubsession.query(ub.OAuth).filter_by( + query = oauth_session.query(ub.OAuth).filter_by( provider=provider_id, provider_user_id=provider_user_id, ) @@ -207,11 +208,11 @@ if ub.oauth_support: token=token, ) try: - g.ubsession.add(oauth_entry) - g.ubsession.commit() + oauth_session.add(oauth_entry) + oauth_session.commit() except Exception as e: log.exception(e) - g.ubsession.rollback() + oauth_session.rollback() # Disable Flask-Dance's default behavior for saving the OAuth token # Value differrs depending on flask-dance version diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index e96fa1ac..4133a3ff 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2020-12-02 15:51:36

+

Start Time: 2020-12-08 08:19:58

-

Stop Time: 2020-12-02 18:01:04

+

Stop Time: 2020-12-08 10:00:52

-

Duration: 1h 41 min

+

Duration: 1h 15 min

@@ -511,80 +511,1030 @@ AssertionError: False is not true : BMP file is not detected - + TestEbookConvertCalibreGDrive - 6 - 6 + 12 0 0 + 12 0 - Detail + Detail - +
TestEbookConvertCalibreGDrive - test_convert_email
- PASS + +
+ ERROR +
+ + + + - + + +
TestEbookConvertCalibreGDrive - test_convert_email
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertCalibreGDrive - test_convert_failed_and_email
- PASS + +
+ ERROR +
+ + + + - + + +
TestEbookConvertCalibreGDrive - test_convert_failed_and_email
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertCalibreGDrive - test_convert_only
- PASS + +
+ ERROR +
+ + + + - + + +
TestEbookConvertCalibreGDrive - test_convert_only
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertCalibreGDrive - test_convert_parameter
- PASS + +
+ ERROR +
+ + + + - + + +
TestEbookConvertCalibreGDrive - test_convert_parameter
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertCalibreGDrive - test_email_failed
- PASS + +
+ ERROR +
+ + + + - + + +
TestEbookConvertCalibreGDrive - test_email_failed
+ + +
+ ERROR +
+ + + + + + + + +
TestEbookConvertCalibreGDrive - test_email_only
- PASS + +
+ ERROR +
+ + + + + + + + + + +
TestEbookConvertCalibreGDrive - test_email_only
+ + +
+ ERROR +
+ + + + - + TestEbookConvertKepubify 3 - 3 - 0 + 2 + 1 0 0 @@ -603,11 +1553,33 @@ AssertionError: False is not true : BMP file is not detected - +
TestEbookConvertKepubify - test_convert_only
- PASS + +
+ FAIL +
+ + + + @@ -622,13 +1594,13 @@ AssertionError: False is not true : BMP file is not detected - + TestEbookConvertGDriveKepubify 3 - 2 - 1 0 0 + 3 + 0 Detail @@ -636,37 +1608,32 @@ AssertionError: False is not true : BMP file is not detected - +
TestEbookConvertGDriveKepubify - test_convert_deactivate
- PASS - - - - - - -
TestEbookConvertGDriveKepubify - test_convert_only
-
- FAIL + ERROR
-