mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Refactor hard-coded strings with a reference to a static property
Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
parent
eeb1cc7197
commit
6bd9b725e2
6 changed files with 16 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue