From 0ec2bcd8979bbf190cb1204aa4ecf19f6a8ebada Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 30 Jul 2021 09:25:08 +0200 Subject: [PATCH 01/10] Fixes from testrun --- CONTRIBUTING.md | 4 +- cps/__init__.py | 5 +- cps/converter.py | 4 +- cps/templates/config_db.html | 2 +- cps/templates/logviewer.html | 4 +- cps/web.py | 4 + test/Calibre-Web TestSummary_Linux.html | 2827 ++++++++++++++++++----- 7 files changed, 2321 insertions(+), 529 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ce2bd780..c6006ad1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,6 +41,6 @@ Open a new GitHub pull request with the patch. Ensure the PR description clearly In case your code enhances features of Calibre-Web: Create your pull request for the development branch if your enhancement consists of more than some lines of code in a local section of Calibre-Webs code. This makes it easier to test it and check all implication before it's made public. -Please check if your code runs on Python 2.7 (still necessary in 2020) and mainly on python 3. If possible and the feature is related to operating system functions, try to check it on Windows and Linux. -Calibre-Web is automatically tested on Linux in combination with python 3.7. The code for testing is in a [separate repo](https://github.com/OzzieIsaacs/calibre-web-test) on Github. It uses unit tests and performs real system tests with selenium; it would be great if you could consider also writing some tests. +Please check if your code runs with python 3, python 2 is no longer supported. If possible and the feature is related to operating system functions, try to check it on Windows and Linux. +Calibre-Web is automatically tested on Linux in combination with python 3.8. The code for testing is in a [separate repo](https://github.com/OzzieIsaacs/calibre-web-test) on Github. It uses unit tests and performs real system tests with selenium; it would be great if you could consider also writing some tests. A static code analysis is done by Codacy, but it's partly broken and doesn't run automatically. You could check your code with ESLint before contributing, a configuration file can be found in the projects root folder. diff --git a/cps/__init__.py b/cps/__init__.py index 3266a4e9..9b004640 100644 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -102,8 +102,9 @@ def create_app(): log.info('Starting Calibre Web...') if sys.version_info < (3, 0): - log.info('Python2 is EOL since end of 2019, this version of Calibre-Web is no longer supporting Python2 please consider upgrading to Python3') - print('Python2 is EOL since end of 2019, this version of Calibre-Web is no longer supporting Python2 please consider upgrading to Python3') + log.info('*** Python2 is EOL since end of 2019, this version of Calibre-Web is no longer supporting Python2, please update your installation to Python3 ***') + print('*** Python2 is EOL since end of 2019, this version of Calibre-Web is no longer supporting Python2, please update your installation to Python3 ***') + sys.exit(5) Principal(app) lm.init_app(app) app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.session)) diff --git a/cps/converter.py b/cps/converter.py index f37168c7..6b0f22e4 100644 --- a/cps/converter.py +++ b/cps/converter.py @@ -39,7 +39,9 @@ def _get_command_version(path, pattern, argument=None): if argument: command.append(argument) try: - return process_wait(command, pattern=pattern).string + match = process_wait(command, pattern=pattern) + if isinstance(match, re.Match): + return match.string except Exception as ex: log.warning("%s: %s", path, ex) return _EXECUTION_ERROR diff --git a/cps/templates/config_db.html b/cps/templates/config_db.html index 0d1d1bce..e0e1bfd1 100644 --- a/cps/templates/config_db.html +++ b/cps/templates/config_db.html @@ -20,7 +20,7 @@ - {% if not gdriveError %} + {% if not gdriveError and config.config_use_google_drive %} {% if show_authenticate_google_drive and config.config_use_google_drive %}
{{_('Authenticate Google Drive')}} diff --git a/cps/templates/logviewer.html b/cps/templates/logviewer.html index db27bdf4..6c26a5b6 100644 --- a/cps/templates/logviewer.html +++ b/cps/templates/logviewer.html @@ -15,10 +15,10 @@
{% if log_enable %} - {{_('Download Calibre-Web Log')}} + {{_('Download Calibre-Web Log')}} {% endif %} {% if accesslog_enable %} - {{_('Download Access Log')}} + {{_('Download Access Log')}} {% endif %}
diff --git a/cps/web.py b/cps/web.py index d9f634a4..871a3de3 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1523,6 +1523,7 @@ def login(): login_result, error = services.ldap.bind_user(form['username'], form['password']) if login_result: login_user(user, remember=bool(form.get('remember_me'))) + ub.store_user_session() log.debug(u"You are now logged in as: '%s'", user.name) flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.name), category="success") @@ -1530,6 +1531,7 @@ def login(): elif login_result is None and user and check_password_hash(str(user.password), form['password']) \ and user.name != "Guest": login_user(user, remember=bool(form.get('remember_me'))) + ub.store_user_session() log.info("Local Fallback Login as: '%s'", user.name) flash(_(u"Fallback Login as: '%(nickname)s', LDAP Server not reachable, or user not known", nickname=user.name), @@ -1559,6 +1561,7 @@ def login(): else: if user and check_password_hash(str(user.password), form['password']) and user.name != "Guest": login_user(user, remember=bool(form.get('remember_me'))) + ub.store_user_session() log.debug(u"You are now logged in as: '%s'", user.name) flash(_(u"You are now logged in as: '%(nickname)s'", nickname=user.name), category="success") config.config_is_initial = False @@ -1582,6 +1585,7 @@ def login(): @login_required def logout(): if current_user is not None and current_user.is_authenticated: + ub.delete_user_session(current_user.id, flask_session.get('_id',"")) logout_user() if feature_support['oauth'] and (config.config_login_type == 2 or config.config_login_type == 3): logout_oauth_user() diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index b4ef6efa..f9a9218a 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2021-05-27 20:44:36

+

Start Time: 2021-07-29 20:37:20

-

Stop Time: 2021-05-28 00:00:32

+

Stop Time: 2021-07-30 00:10:27

-

Duration: 2h 37 min

+

Duration: 2h 47 min

@@ -234,12 +234,12 @@ - + TestCli 8 - 8 - 0 - 0 + 4 + 3 + 1 0 Detail @@ -266,20 +266,68 @@ - +
TestCli - test_change_password
- PASS + +
+ FAIL +
+ + + + - +
TestCli - test_cli_SSL_files
- PASS + +
+ FAIL +
+ + + + @@ -293,11 +341,41 @@ - +
TestCli - test_cli_different_settings_database
- PASS + +
+ ERROR +
+ + + + @@ -311,22 +389,50 @@ - +
TestCli - test_settingsdb_not_writeable
- PASS + +
+ FAIL +
+ + + + - + TestCliGdrivedb 2 - 2 - 0 0 + 1 + 1 0 Detail @@ -335,20 +441,72 @@ - +
TestCliGdrivedb - test_cli_gdrive_location
- PASS + +
+ FAIL +
+ + + + - +
TestCliGdrivedb - test_gdrive_db_nonwrite
- PASS + +
+ ERROR +
+ + + + @@ -402,11 +560,11 @@ - + TestEbookConvertCalibre 11 - 11 - 0 + 9 + 2 0 0 @@ -461,11 +619,33 @@ - +
TestEbookConvertCalibre - test_convert_wrong_excecutable
- PASS + +
+ FAIL +
+ + + + @@ -479,11 +659,33 @@ - +
TestEbookConvertCalibre - test_email_only
- PASS + +
+ FAIL +
+ + + + @@ -669,12 +871,12 @@ - + TestEditAdditionalBooks 13 - 12 - 0 + 8 0 + 4 1 Detail @@ -755,29 +957,159 @@ - +
TestEditAdditionalBooks - test_upload_edit_role
- PASS + +
+ ERROR +
+ + + + - +
TestEditAdditionalBooks - test_upload_metadata_cbr
- PASS + +
+ ERROR +
+ + + + - +
TestEditAdditionalBooks - test_upload_metadata_cbt
- PASS + +
+ ERROR +
+ + + + @@ -808,31 +1140,111 @@ - +
TestEditAdditionalBooks - test_writeonly_path
- PASS + +
+ ERROR +
+ + + + - - TestEditBooks - 35 - 34 + + _ErrorHolder + 1 0 0 1 + 0 - Detail + Detail - + + +
tearDownClass (test_edit_additional_books)
+ + +
+ ERROR +
+ + + + + + + + + + + TestEditBooks + 35 + 25 + 0 + 9 + 1 + + Detail + + + + + +
TestEditBooks - test_download_book
@@ -841,7 +1253,7 @@ - +
TestEditBooks - test_edit_author
@@ -850,7 +1262,7 @@ - +
TestEditBooks - test_edit_category
@@ -859,7 +1271,7 @@ - +
TestEditBooks - test_edit_comments
@@ -868,7 +1280,7 @@ - +
TestEditBooks - test_edit_custom_bool
@@ -877,7 +1289,7 @@ - +
TestEditBooks - test_edit_custom_categories
@@ -886,7 +1298,7 @@ - +
TestEditBooks - test_edit_custom_comment
@@ -895,7 +1307,7 @@ - +
TestEditBooks - test_edit_custom_date
@@ -904,7 +1316,7 @@ - +
TestEditBooks - test_edit_custom_float
@@ -913,7 +1325,7 @@ - +
TestEditBooks - test_edit_custom_int
@@ -922,7 +1334,7 @@ - +
TestEditBooks - test_edit_custom_rating
@@ -931,7 +1343,7 @@ - +
TestEditBooks - test_edit_custom_single_select
@@ -940,7 +1352,7 @@ - +
TestEditBooks - test_edit_custom_text
@@ -949,7 +1361,7 @@ - +
TestEditBooks - test_edit_language
@@ -958,7 +1370,7 @@ - +
TestEditBooks - test_edit_publisher
@@ -967,7 +1379,7 @@ - +
TestEditBooks - test_edit_publishing_date
@@ -976,7 +1388,7 @@ - +
TestEditBooks - test_edit_rating
@@ -985,7 +1397,7 @@ - +
TestEditBooks - test_edit_series
@@ -994,7 +1406,7 @@ - +
TestEditBooks - test_edit_title
@@ -1003,19 +1415,19 @@ - +
TestEditBooks - test_rename_uppercase_lowercase
- SKIP + SKIP
-