From 162ac73beed3f97c41511dff65c297103e15e0f4 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 22 Feb 2023 18:59:11 +0100 Subject: [PATCH] Bugfixes from testrun --- cps/epub.py | 2 +- cps/web.py | 20 +- test/Calibre-Web TestSummary_Linux.html | 300 +++++++++++++++++++----- 3 files changed, 248 insertions(+), 74 deletions(-) diff --git a/cps/epub.py b/cps/epub.py index 3350e721..3eb317a4 100644 --- a/cps/epub.py +++ b/cps/epub.py @@ -151,7 +151,7 @@ def parse_epub_cover(ns, tree, epub_zip, cover_path, tmp_file_path): cover_file = None for cs in cover_section: - if cs.endswith('.xhtml') or s.endswith('.html'): + if cs.endswith('.xhtml') or cs.endswith('.html'): markup = epub_zip.read(os.path.join(cover_path, cs)) markup_tree = etree.fromstring(markup) # no matter xhtml or html with no namespace diff --git a/cps/web.py b/cps/web.py index 0f925300..f1f5bf6d 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1161,18 +1161,15 @@ def serve_book(book_id, book_format, anyname): data = calibre_db.get_book_format(book_id, book_format.upper()) if not data: return "File not in Database" - range_header = request.headers.get('Range', None) - if not range_header: - log.info('Serving book: %s', data.name) - response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)) - response.headers['Accept-Ranges'] = 'bytes' - return response - + if config.config_use_google_drive: try: headers = Headers() headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream") + if not range_header: + log.info('Serving book: %s', data.name) + headers['Accept-Ranges'] = 'bytes' df = getFileFromEbooksFolder(book.path, data.name + "." + book_format) return do_gdrive_download(df, headers, (book_format.upper() == 'TXT')) except AttributeError as ex: @@ -1180,6 +1177,7 @@ def serve_book(book_id, book_format, anyname): return "File Not Found" else: if book_format.upper() == 'TXT': + log.info('Serving book: %s', data.name) try: rawdata = open(os.path.join(config.config_calibre_dir, book.path, data.name + "." + book_format), "rb").read() @@ -1189,7 +1187,13 @@ def serve_book(book_id, book_format, anyname): except FileNotFoundError: log.error("File Not Found") return "File Not Found" - return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format) + # enable byte range read of pdf + response = make_response( + send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)) + if not range_header: + log.info('Serving book: %s', data.name) + response.headers['Accept-Ranges'] = 'bytes' + return response @web.route("/download//", defaults={'anyname': 'None'}) diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 4e3ed7ed..0daf4ca3 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2023-02-19 19:38:02

+

Start Time: 2023-02-21 20:53:24

-

Stop Time: 2023-02-20 01:56:35

+

Stop Time: 2023-02-22 03:08:32

-

Duration: 5h 23 min

+

Duration: 5h 18 min

@@ -936,11 +936,11 @@ - + TestEditBooks 36 - 35 - 0 + 34 + 1 0 1 @@ -1228,11 +1228,34 @@ - +
TestEditBooks - test_upload_book_epub
- PASS + +
+ FAIL +
+ + + + @@ -1607,12 +1630,12 @@ - + TestLoadMetadata 1 0 - 1 0 + 1 0 Detail @@ -1621,26 +1644,26 @@ - +
TestLoadMetadata - test_load_metadata
- FAIL + ERROR
-
Traceback (most recent call last):
-  File "/home/ozzie/Development/calibre-web-test/test/test_edit_ebooks_gdrive.py", line 230, in test_edit_title
-    self.assertEqual(ele.text, u'Very long extra super turbo cool title without any issue of displaying including ö utf-8 characters')
-AttributeError: 'bool' object has no attribute 'text'
+ File "/home/ozzie/Development/calibre-web-test/test/test_edit_ebooks_gdrive.py", line 185, in test_edit_title + self.assertEqual('The camicdemo', books[1][8]['title']) +IndexError: list index out of range
@@ -2174,11 +2197,11 @@ AttributeError: 'bool' object has no attribute 'text' - + TestKoboSync 11 - 11 - 0 + 10 + 1 0 0 @@ -2278,11 +2301,38 @@ AttributeError: 'bool' object has no attribute 'text' - +
TestKoboSync - test_sync_upload
- PASS + +
+ FAIL +
+ + + + @@ -3220,11 +3270,11 @@ AttributeError: 'bool' object has no attribute 'text' - + TestReader 5 - 5 - 0 + 3 + 2 0 0 @@ -3234,11 +3284,31 @@ AttributeError: 'bool' object has no attribute 'text' - +
TestReader - test_comic_reader
- PASS + +
+ FAIL +
+ + + + @@ -3270,11 +3340,31 @@ AttributeError: 'bool' object has no attribute 'text' - +
TestReader - test_txt_reader
- PASS + +
+ FAIL +
+ + + + @@ -3636,8 +3726,8 @@ AttributeError: 'bool' object has no attribute 'text' TestThumbnails 8 - 5 - 2 + 3 + 4 0 1 @@ -3656,11 +3746,31 @@ AttributeError: 'bool' object has no attribute 'text' - +
TestThumbnails - test_cache_of_deleted_book
- PASS + +
+ FAIL +
+ + + + @@ -3693,7 +3803,7 @@ AttributeError: 'bool' object has no attribute 'text'
Traceback (most recent call last):
   File "/home/ozzie/Development/calibre-web-test/test/test_thumbnails.py", line 135, in test_cover_change_on_upload_new_cover
     self.assertGreaterEqual(diff(BytesIO(updated_cover), BytesIO(original_cover), delete_diff_file=True), 0.03)
-AssertionError: 0.029520666495068845 not greater than or equal to 0.03
+AssertionError: 0.02977373520222651 not greater than or equal to 0.03
@@ -3712,11 +3822,31 @@ AssertionError: 0.029520666495068845 not greater than or equal to 0.03 - +
TestThumbnails - test_cover_on_upload_book
- PASS + +
+ FAIL +
+ + + + @@ -3747,9 +3877,9 @@ AssertionError: 0.029520666495068845 not greater than or equal to 0.03
Traceback (most recent call last):
-  File "/home/ozzie/Development/calibre-web-test/test/test_thumbnails.py", line 310, in test_sideloaded_book
-    self.assertAlmostEqual(diff(BytesIO(list_cover), BytesIO(old_list_cover), delete_diff_file=True), 0.0,
-AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.006835200746965453 difference)
+ File "/home/ozzie/Development/calibre-web-test/test/test_thumbnails.py", line 320, in test_sideloaded_book + self.assertGreaterEqual(diff(BytesIO(list_cover), BytesIO(new_list_cover), delete_diff_file=True), 0.04) +AssertionError: 0.0 not greater than or equal to 0.04
@@ -3873,11 +4003,11 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 - + TestUploadEPubs 5 - 5 - 0 + 3 + 2 0 0 @@ -3887,20 +4017,60 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 - +
TestUploadEPubs - test_upload_epub_cover
- PASS + +
+ FAIL +
+ + + + - +
TestUploadEPubs - test_upload_epub_cover_formats
- PASS + +
+ FAIL +
+ + + + @@ -4829,9 +4999,9 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 Total 425 - 414 - 3 - 1 + 406 + 10 + 2 7   @@ -5010,7 +5180,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestCliGdrivedb @@ -5028,7 +5198,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestCliGdrivedb @@ -5040,7 +5210,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestEbookConvertCalibreGDrive @@ -5058,7 +5228,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestEbookConvertCalibreGDrive @@ -5070,7 +5240,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestEbookConvertGDriveKepubify @@ -5088,7 +5258,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestEbookConvertGDriveKepubify @@ -5112,7 +5282,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestEditAuthorsGdrive @@ -5130,7 +5300,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestEditAuthorsGdrive @@ -5148,7 +5318,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestEditBooksOnGdrive @@ -5166,7 +5336,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestEditBooksOnGdrive @@ -5190,7 +5360,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 google-api-python-client - 2.78.0 + 2.79.0 TestSetupGdrive @@ -5208,7 +5378,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469 PyDrive2 - 1.15.0 + 1.15.1 TestSetupGdrive @@ -5280,7 +5450,7 @@ AssertionError: 0.006835200746965453 != 0.0 within 0.0001 delta (0.0068352007469