From 6bd9b725e27d4ca850275b111b280c8530aa88c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Jaenisch?= Date: Thu, 5 May 2022 13:07:25 +0200 Subject: [PATCH] Refactor hard-coded strings with a reference to a static property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Jaenisch --- bookwyrm/importers/librarything_import.py | 9 ++++++--- bookwyrm/tests/importers/test_goodreads_import.py | 2 +- bookwyrm/tests/importers/test_importer.py | 8 ++++---- bookwyrm/tests/importers/test_librarything_import.py | 6 +++--- bookwyrm/tests/importers/test_openlibrary_import.py | 2 +- bookwyrm/tests/importers/test_storygraph_import.py | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bookwyrm/importers/librarything_import.py b/bookwyrm/importers/librarything_import.py index 37730dee..c6833547 100644 --- a/bookwyrm/importers/librarything_import.py +++ b/bookwyrm/importers/librarything_import.py @@ -1,5 +1,8 @@ """ handle reading a tsv from librarything """ import re + +from bookwyrm.models import Shelf + from . import Importer @@ -21,7 +24,7 @@ class LibrarythingImporter(Importer): def get_shelf(self, normalized_row): if normalized_row["date_finished"]: - return "read" + return Shelf.READ_FINISHED if normalized_row["date_started"]: - return "reading" - return "to-read" + return Shelf.READING + return Shelf.TO_READ diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 04fb886b..00c8b981 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -84,7 +84,7 @@ class GoodreadsImport(TestCase): def test_handle_imported_book(self, *_): """goodreads import added a book, this adds related connections""" - shelf = self.local_user.shelf_set.filter(identifier="read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.READ_FINISHED).first() self.assertIsNone(shelf.books.first()) import_job = self.importer.create_job( diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index c8da8a27..5d0b9b00 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -174,7 +174,7 @@ class GenericImporter(TestCase): def test_handle_imported_book(self, *_): """import added a book, this adds related connections""" - shelf = self.local_user.shelf_set.filter(identifier="read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.READ_FINISHED).first() self.assertIsNone(shelf.books.first()) import_job = self.importer.create_job( @@ -193,7 +193,7 @@ class GenericImporter(TestCase): def test_handle_imported_book_already_shelved(self, *_): """import added a book, this adds related connections""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - shelf = self.local_user.shelf_set.filter(identifier="to-read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.TO_READ).first() models.ShelfBook.objects.create( shelf=shelf, user=self.local_user, @@ -217,12 +217,12 @@ class GenericImporter(TestCase): shelf.shelfbook_set.first().shelved_date, make_date(2020, 2, 2) ) self.assertIsNone( - self.local_user.shelf_set.get(identifier="read").books.first() + self.local_user.shelf_set.get(identifier=models.Shelf.READ_FINISHED).books.first() ) def test_handle_import_twice(self, *_): """re-importing books""" - shelf = self.local_user.shelf_set.filter(identifier="read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.READ_FINISHED).first() import_job = self.importer.create_job( self.local_user, self.csv, False, "public" ) diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 57d55520..e976027c 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -93,7 +93,7 @@ class LibrarythingImport(TestCase): def test_handle_imported_book(self, *_): """librarything import added a book, this adds related connections""" - shelf = self.local_user.shelf_set.filter(identifier="read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.READ_FINISHED).first() self.assertIsNone(shelf.books.first()) import_job = self.importer.create_job( @@ -117,7 +117,7 @@ class LibrarythingImport(TestCase): def test_handle_imported_book_already_shelved(self, *_): """librarything import added a book, this adds related connections""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - shelf = self.local_user.shelf_set.filter(identifier="to-read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.TO_READ).first() models.ShelfBook.objects.create( shelf=shelf, user=self.local_user, book=self.book ) @@ -135,7 +135,7 @@ class LibrarythingImport(TestCase): shelf.refresh_from_db() self.assertEqual(shelf.books.first(), self.book) self.assertIsNone( - self.local_user.shelf_set.get(identifier="read").books.first() + self.local_user.shelf_set.get(identifier=models.Shelf.READ_FINISHED).books.first() ) readthrough = models.ReadThrough.objects.get(user=self.local_user) diff --git a/bookwyrm/tests/importers/test_openlibrary_import.py b/bookwyrm/tests/importers/test_openlibrary_import.py index a775c596..dbd177b8 100644 --- a/bookwyrm/tests/importers/test_openlibrary_import.py +++ b/bookwyrm/tests/importers/test_openlibrary_import.py @@ -70,7 +70,7 @@ class OpenLibraryImport(TestCase): def test_handle_imported_book(self, *_): """openlibrary import added a book, this adds related connections""" - shelf = self.local_user.shelf_set.filter(identifier="reading").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.READING).first() self.assertIsNone(shelf.books.first()) import_job = self.importer.create_job( diff --git a/bookwyrm/tests/importers/test_storygraph_import.py b/bookwyrm/tests/importers/test_storygraph_import.py index 670c6e5e..69788d60 100644 --- a/bookwyrm/tests/importers/test_storygraph_import.py +++ b/bookwyrm/tests/importers/test_storygraph_import.py @@ -62,7 +62,7 @@ class StorygraphImport(TestCase): def test_handle_imported_book(self, *_): """storygraph import added a book, this adds related connections""" - shelf = self.local_user.shelf_set.filter(identifier="to-read").first() + shelf = self.local_user.shelf_set.filter(identifier=models.Shelf.TO_READ).first() self.assertIsNone(shelf.books.first()) import_job = self.importer.create_job(