Updates mocks in tests

This commit is contained in:
Mouse Reeve 2022-11-07 09:50:05 -08:00
parent 493fd68af4
commit 141d3aa813
8 changed files with 26 additions and 11 deletions

View file

@ -6,7 +6,7 @@ from django.test import TestCase
from bookwyrm import models
from bookwyrm.importers import CalibreImporter
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import handle_imported_book
# pylint: disable=consider-using-with
@ -16,6 +16,7 @@ from bookwyrm.importers.importer import handle_imported_book
class CalibreImport(TestCase):
"""importing from Calibre csv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test csv"""
self.importer = CalibreImporter()

View file

@ -8,7 +8,7 @@ from django.test import TestCase
from bookwyrm import models
from bookwyrm.importers import GoodreadsImporter
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import handle_imported_book
def make_date(*args):
@ -23,6 +23,7 @@ def make_date(*args):
class GoodreadsImport(TestCase):
"""importing from goodreads csv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test csv"""
self.importer = GoodreadsImporter()

View file

@ -1,4 +1,5 @@
""" testing import """
from collections import namedtuple
import pathlib
from unittest.mock import patch
import datetime
@ -9,8 +10,8 @@ import responses
from bookwyrm import models
from bookwyrm.importers import Importer
from bookwyrm.importers.importer import start_import_task, import_item_task
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import start_import_task, import_item_task
from bookwyrm.models.import_job import handle_imported_book
def make_date(*args):
@ -25,6 +26,7 @@ def make_date(*args):
class GenericImporter(TestCase):
"""importing from csv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test csv"""
@ -103,9 +105,13 @@ class GenericImporter(TestCase):
import_job = self.importer.create_job(
self.local_user, self.csv, False, "unlisted"
)
with patch("bookwyrm.importers.importer.start_import_task.delay") as mock:
self.importer.start_import(import_job)
MockTask = namedtuple("Task", ("id"))
with patch("bookwyrm.models.import_job.start_import_task.delay") as mock:
mock.return_value = MockTask(123)
import_job.start_job()
self.assertEqual(mock.call_count, 1)
import_job.refresh_from_db()
self.assertEqual(import_job.task_id, "123")
@responses.activate
def test_start_import_task(self, *_):
@ -114,7 +120,9 @@ class GenericImporter(TestCase):
self.local_user, self.csv, False, "unlisted"
)
with patch("bookwyrm.importers.importer.import_item_task.delay") as mock:
MockTask = namedtuple("Task", ("id"))
with patch("bookwyrm.models.import_job.import_item_task.delay") as mock:
mock.return_value = MockTask(123)
start_import_task(import_job.id)
self.assertEqual(mock.call_count, 4)

View file

@ -8,7 +8,7 @@ from django.test import TestCase
from bookwyrm import models
from bookwyrm.importers import LibrarythingImporter
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import handle_imported_book
def make_date(*args):
@ -23,6 +23,7 @@ def make_date(*args):
class LibrarythingImport(TestCase):
"""importing from librarything tsv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test tsv"""
self.importer = LibrarythingImporter()

View file

@ -8,7 +8,7 @@ from django.test import TestCase
from bookwyrm import models
from bookwyrm.importers import OpenLibraryImporter
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import handle_imported_book
def make_date(*args):
@ -23,6 +23,7 @@ def make_date(*args):
class OpenLibraryImport(TestCase):
"""importing from openlibrary csv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test csv"""
self.importer = OpenLibraryImporter()

View file

@ -8,7 +8,7 @@ from django.test import TestCase
from bookwyrm import models
from bookwyrm.importers import StorygraphImporter
from bookwyrm.importers.importer import handle_imported_book
from bookwyrm.models.import_job import handle_imported_book
def make_date(*args):
@ -23,6 +23,7 @@ def make_date(*args):
class StorygraphImport(TestCase):
"""importing from storygraph csv"""
# pylint: disable=invalid-name
def setUp(self):
"""use a test csv"""
self.importer = StorygraphImporter()

View file

@ -11,6 +11,7 @@ from bookwyrm import models, views
class ImportManualReviewViews(TestCase):
"""goodreads import views"""
# pylint: disable=invalid-name
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()
@ -59,7 +60,7 @@ class ImportManualReviewViews(TestCase):
request = self.factory.post("")
request.user = self.local_user
with patch("bookwyrm.importers.importer.import_item_task.delay") as mock:
with patch("bookwyrm.models.import_job.import_item_task.delay") as mock:
views.approve_import_item(request, self.job.id, import_item.id)
self.assertEqual(mock.call_count, 1)
import_item.refresh_from_db()

View file

@ -11,6 +11,7 @@ from bookwyrm import models, views
class ImportTroubleshootViews(TestCase):
"""goodreads import views"""
# pylint: disable=invalid-name
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()