mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
A few more mocks
This commit is contained in:
parent
cad5a128ac
commit
309d289a65
2 changed files with 6 additions and 29 deletions
|
@ -84,24 +84,6 @@ class LibrarythingImport(TestCase):
|
||||||
self.assertEqual(retry_items[1].index, 1)
|
self.assertEqual(retry_items[1].index, 1)
|
||||||
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
|
self.assertEqual(retry_items[1].data["Book Id"], "5015319")
|
||||||
|
|
||||||
@responses.activate
|
|
||||||
def test_start_import_task(self, *_):
|
|
||||||
"""resolve entry"""
|
|
||||||
import_job = self.importer.create_job(
|
|
||||||
self.local_user, self.csv, False, "unlisted"
|
|
||||||
)
|
|
||||||
book = models.Edition.objects.create(title="Test Book")
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
|
||||||
) as resolve:
|
|
||||||
resolve.return_value = book
|
|
||||||
with patch("bookwyrm.importers.importer.handle_imported_book"):
|
|
||||||
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)
|
|
||||||
|
|
||||||
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="read").first()
|
||||||
|
|
|
@ -362,19 +362,15 @@ class Status(TestCase):
|
||||||
|
|
||||||
def test_favorite(self, *_):
|
def test_favorite(self, *_):
|
||||||
"""fav a status"""
|
"""fav a status"""
|
||||||
real_broadcast = models.Favorite.broadcast
|
|
||||||
|
|
||||||
def fav_broadcast_mock(_, activity, user):
|
|
||||||
"""ok"""
|
|
||||||
self.assertEqual(user.remote_id, self.local_user.remote_id)
|
|
||||||
self.assertEqual(activity["type"], "Like")
|
|
||||||
|
|
||||||
models.Favorite.broadcast = fav_broadcast_mock
|
|
||||||
|
|
||||||
status = models.Status.objects.create(
|
status = models.Status.objects.create(
|
||||||
content="test content", user=self.local_user
|
content="test content", user=self.local_user
|
||||||
)
|
)
|
||||||
fav = models.Favorite.objects.create(status=status, user=self.local_user)
|
|
||||||
|
with patch("bookwyrm.models.Favorite.broadcast") as mock:
|
||||||
|
fav = models.Favorite.objects.create(status=status, user=self.local_user)
|
||||||
|
args = mock.call_args[0]
|
||||||
|
self.assertEqual(args[1].remote_id, self.local_user.remote_id)
|
||||||
|
self.assertEqual(args[0]["type"], "Like")
|
||||||
|
|
||||||
# can't fav a status twice
|
# can't fav a status twice
|
||||||
with self.assertRaises(IntegrityError):
|
with self.assertRaises(IntegrityError):
|
||||||
|
@ -384,7 +380,6 @@ class Status(TestCase):
|
||||||
self.assertEqual(activity["type"], "Like")
|
self.assertEqual(activity["type"], "Like")
|
||||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||||
self.assertEqual(activity["object"], status.remote_id)
|
self.assertEqual(activity["object"], status.remote_id)
|
||||||
models.Favorite.broadcast = real_broadcast
|
|
||||||
|
|
||||||
def test_boost(self, *_):
|
def test_boost(self, *_):
|
||||||
"""boosting, this one's a bit fussy"""
|
"""boosting, this one's a bit fussy"""
|
||||||
|
|
Loading…
Reference in a new issue