forked from mirrors/bookwyrm
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
|
@ -1,5 +1,8 @@
|
||||||
""" handle reading a tsv from librarything """
|
""" handle reading a tsv from librarything """
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from bookwyrm.models import Shelf
|
||||||
|
|
||||||
from . import Importer
|
from . import Importer
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +24,7 @@ class LibrarythingImporter(Importer):
|
||||||
|
|
||||||
def get_shelf(self, normalized_row):
|
def get_shelf(self, normalized_row):
|
||||||
if normalized_row["date_finished"]:
|
if normalized_row["date_finished"]:
|
||||||
return "read"
|
return Shelf.READ_FINISHED
|
||||||
if normalized_row["date_started"]:
|
if normalized_row["date_started"]:
|
||||||
return "reading"
|
return Shelf.READING
|
||||||
return "to-read"
|
return Shelf.TO_READ
|
||||||
|
|
|
@ -84,7 +84,7 @@ class GoodreadsImport(TestCase):
|
||||||
|
|
||||||
def test_handle_imported_book(self, *_):
|
def test_handle_imported_book(self, *_):
|
||||||
"""goodreads import added a book, this adds related connections"""
|
"""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())
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
|
|
|
@ -174,7 +174,7 @@ class GenericImporter(TestCase):
|
||||||
|
|
||||||
def test_handle_imported_book(self, *_):
|
def test_handle_imported_book(self, *_):
|
||||||
"""import added a book, this adds related connections"""
|
"""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())
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
|
@ -193,7 +193,7 @@ class GenericImporter(TestCase):
|
||||||
def test_handle_imported_book_already_shelved(self, *_):
|
def test_handle_imported_book_already_shelved(self, *_):
|
||||||
"""import added a book, this adds related connections"""
|
"""import added a book, this adds related connections"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
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(
|
models.ShelfBook.objects.create(
|
||||||
shelf=shelf,
|
shelf=shelf,
|
||||||
user=self.local_user,
|
user=self.local_user,
|
||||||
|
@ -217,12 +217,12 @@ class GenericImporter(TestCase):
|
||||||
shelf.shelfbook_set.first().shelved_date, make_date(2020, 2, 2)
|
shelf.shelfbook_set.first().shelved_date, make_date(2020, 2, 2)
|
||||||
)
|
)
|
||||||
self.assertIsNone(
|
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, *_):
|
def test_handle_import_twice(self, *_):
|
||||||
"""re-importing books"""
|
"""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(
|
import_job = self.importer.create_job(
|
||||||
self.local_user, self.csv, False, "public"
|
self.local_user, self.csv, False, "public"
|
||||||
)
|
)
|
||||||
|
|
|
@ -93,7 +93,7 @@ class LibrarythingImport(TestCase):
|
||||||
|
|
||||||
def test_handle_imported_book(self, *_):
|
def test_handle_imported_book(self, *_):
|
||||||
"""librarything import added a book, this adds related connections"""
|
"""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())
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
|
@ -117,7 +117,7 @@ class LibrarythingImport(TestCase):
|
||||||
def test_handle_imported_book_already_shelved(self, *_):
|
def test_handle_imported_book_already_shelved(self, *_):
|
||||||
"""librarything import added a book, this adds related connections"""
|
"""librarything import added a book, this adds related connections"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
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(
|
models.ShelfBook.objects.create(
|
||||||
shelf=shelf, user=self.local_user, book=self.book
|
shelf=shelf, user=self.local_user, book=self.book
|
||||||
)
|
)
|
||||||
|
@ -135,7 +135,7 @@ class LibrarythingImport(TestCase):
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
self.assertIsNone(
|
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)
|
readthrough = models.ReadThrough.objects.get(user=self.local_user)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class OpenLibraryImport(TestCase):
|
||||||
|
|
||||||
def test_handle_imported_book(self, *_):
|
def test_handle_imported_book(self, *_):
|
||||||
"""openlibrary import added a book, this adds related connections"""
|
"""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())
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
|
|
|
@ -62,7 +62,7 @@ class StorygraphImport(TestCase):
|
||||||
|
|
||||||
def test_handle_imported_book(self, *_):
|
def test_handle_imported_book(self, *_):
|
||||||
"""storygraph import added a book, this adds related connections"""
|
"""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())
|
self.assertIsNone(shelf.books.first())
|
||||||
|
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
|
|
Loading…
Reference in a new issue