Updates mocks

This commit is contained in:
Mouse Reeve 2021-11-12 08:55:47 -08:00
parent 3190ef4346
commit f71ef286b6
4 changed files with 21 additions and 15 deletions

View file

@ -151,9 +151,9 @@ def handle_imported_book(source, user, item, include_reviews, privacy):
if item.shelf and not existing_shelf:
desired_shelf = models.Shelf.objects.get(identifier=item.shelf, user=user)
shelved_date = item.date_added or timezone.now()
models.ShelfBook.objects.create(
models.ShelfBook(
book=item.book, shelf=desired_shelf, user=user, shelved_date=shelved_date
)
).save(priority=LOW)
for read in item.reads:
# check for an existing readthrough with the same dates

View file

@ -136,7 +136,13 @@ class GenericImporter(TestCase):
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
) as resolve:
resolve.return_value = self.book
with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
import_item_task(self.importer.service, import_item.id)
kwargs = mock.call_args.kwargs
self.assertEqual(kwargs["queue"], "low_priority")
import_item.refresh_from_db()
self.assertEqual(import_item.book.id, self.book.id)
@ -153,7 +159,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public"
)
@ -163,7 +169,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.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = self.local_user.shelf_set.filter(identifier="to-read").first()
models.ShelfBook.objects.create(
shelf=shelf,
@ -179,7 +185,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public"
)
@ -203,7 +209,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public"
)
@ -223,7 +229,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
with patch("bookwyrm.models.Status.broadcast") as broadcast_mock:
handle_imported_book(
self.importer.service,
@ -249,7 +255,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book(
self.importer.service, self.local_user, import_item, True, "unlisted"
)
@ -267,7 +273,7 @@ class GenericImporter(TestCase):
import_item.book = self.book
import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book(
self.importer.service, self.local_user, import_item, False, "unlisted"
)

View file

@ -9,7 +9,7 @@ import responses
from bookwyrm import models
from bookwyrm.importers import LibrarythingImporter
from bookwyrm.importers.importer import import_data, handle_imported_book
from bookwyrm.importers.importer import start_import_task, handle_imported_book
def make_date(*args):
@ -85,7 +85,7 @@ class LibrarythingImport(TestCase):
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
@responses.activate
def test_import_data(self, *_):
def test_start_import_task(self, *_):
"""resolve entry"""
import_job = self.importer.create_job(
self.local_user, self.csv, False, "unlisted"
@ -97,7 +97,7 @@ class LibrarythingImport(TestCase):
) as resolve:
resolve.return_value = book
with patch("bookwyrm.importers.importer.handle_imported_book"):
import_data(self.importer.service, import_job.id)
start_import_task(self.importer.service, import_job.id)
import_item = models.ImportItem.objects.get(job=import_job, index=0)
self.assertEqual(import_item.book.id, book.id)