forked from mirrors/bookwyrm
Updates mocks
This commit is contained in:
parent
3190ef4346
commit
f71ef286b6
4 changed files with 21 additions and 15 deletions
|
@ -277,12 +277,12 @@ def add_status_on_create(sender, instance, created, *args, **kwargs):
|
||||||
|
|
||||||
def add_status_on_create_command(sender, instance, created):
|
def add_status_on_create_command(sender, instance, created):
|
||||||
"""runs this code only after the database commit completes"""
|
"""runs this code only after the database commit completes"""
|
||||||
priority=HIGH
|
priority = HIGH
|
||||||
# check if this is an old status, de-prioritize if so
|
# check if this is an old status, de-prioritize if so
|
||||||
# (this will happen if federation is very slow, or, more expectedly, on csv import)
|
# (this will happen if federation is very slow, or, more expectedly, on csv import)
|
||||||
one_day = 60 * 60 * 24
|
one_day = 60 * 60 * 24
|
||||||
if (instance.created_date - instance.published_date).seconds > one_day:
|
if (instance.created_date - instance.published_date).seconds > one_day:
|
||||||
priority=LOW
|
priority = LOW
|
||||||
|
|
||||||
add_status_task.apply_async(
|
add_status_task.apply_async(
|
||||||
args=(instance.id,),
|
args=(instance.id,),
|
||||||
|
|
|
@ -151,9 +151,9 @@ def handle_imported_book(source, user, item, include_reviews, privacy):
|
||||||
if item.shelf and not existing_shelf:
|
if item.shelf and not existing_shelf:
|
||||||
desired_shelf = models.Shelf.objects.get(identifier=item.shelf, user=user)
|
desired_shelf = models.Shelf.objects.get(identifier=item.shelf, user=user)
|
||||||
shelved_date = item.date_added or timezone.now()
|
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
|
book=item.book, shelf=desired_shelf, user=user, shelved_date=shelved_date
|
||||||
)
|
).save(priority=LOW)
|
||||||
|
|
||||||
for read in item.reads:
|
for read in item.reads:
|
||||||
# check for an existing readthrough with the same dates
|
# check for an existing readthrough with the same dates
|
||||||
|
|
|
@ -136,7 +136,13 @@ class GenericImporter(TestCase):
|
||||||
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
||||||
) as resolve:
|
) as resolve:
|
||||||
resolve.return_value = self.book
|
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)
|
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()
|
import_item.refresh_from_db()
|
||||||
|
|
||||||
self.assertEqual(import_item.book.id, self.book.id)
|
self.assertEqual(import_item.book.id, self.book.id)
|
||||||
|
@ -153,7 +159,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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(
|
handle_imported_book(
|
||||||
self.importer.service, self.local_user, import_item, False, "public"
|
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, *_):
|
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.delay"):
|
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="to-read").first()
|
||||||
models.ShelfBook.objects.create(
|
models.ShelfBook.objects.create(
|
||||||
shelf=shelf,
|
shelf=shelf,
|
||||||
|
@ -179,7 +185,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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(
|
handle_imported_book(
|
||||||
self.importer.service, self.local_user, import_item, False, "public"
|
self.importer.service, self.local_user, import_item, False, "public"
|
||||||
)
|
)
|
||||||
|
@ -203,7 +209,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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(
|
handle_imported_book(
|
||||||
self.importer.service, self.local_user, import_item, False, "public"
|
self.importer.service, self.local_user, import_item, False, "public"
|
||||||
)
|
)
|
||||||
|
@ -223,7 +229,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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:
|
with patch("bookwyrm.models.Status.broadcast") as broadcast_mock:
|
||||||
handle_imported_book(
|
handle_imported_book(
|
||||||
self.importer.service,
|
self.importer.service,
|
||||||
|
@ -249,7 +255,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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(
|
handle_imported_book(
|
||||||
self.importer.service, self.local_user, import_item, True, "unlisted"
|
self.importer.service, self.local_user, import_item, True, "unlisted"
|
||||||
)
|
)
|
||||||
|
@ -267,7 +273,7 @@ class GenericImporter(TestCase):
|
||||||
import_item.book = self.book
|
import_item.book = self.book
|
||||||
import_item.save()
|
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(
|
handle_imported_book(
|
||||||
self.importer.service, self.local_user, import_item, False, "unlisted"
|
self.importer.service, self.local_user, import_item, False, "unlisted"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import responses
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
from bookwyrm.importers import LibrarythingImporter
|
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):
|
def make_date(*args):
|
||||||
|
@ -85,7 +85,7 @@ class LibrarythingImport(TestCase):
|
||||||
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
|
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_import_data(self, *_):
|
def test_start_import_task(self, *_):
|
||||||
"""resolve entry"""
|
"""resolve entry"""
|
||||||
import_job = self.importer.create_job(
|
import_job = self.importer.create_job(
|
||||||
self.local_user, self.csv, False, "unlisted"
|
self.local_user, self.csv, False, "unlisted"
|
||||||
|
@ -97,7 +97,7 @@ class LibrarythingImport(TestCase):
|
||||||
) as resolve:
|
) as resolve:
|
||||||
resolve.return_value = book
|
resolve.return_value = book
|
||||||
with patch("bookwyrm.importers.importer.handle_imported_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)
|
import_item = models.ImportItem.objects.get(job=import_job, index=0)
|
||||||
self.assertEqual(import_item.book.id, book.id)
|
self.assertEqual(import_item.book.id, book.id)
|
||||||
|
|
Loading…
Reference in a new issue