forked from mirrors/bookwyrm
Fix tests (for realz)
This commit is contained in:
parent
d9d34d8220
commit
f8df501239
13 changed files with 112 additions and 95 deletions
|
@ -98,6 +98,7 @@ class BaseActivity(TestCase):
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
result = resolve_remote_id(
|
result = resolve_remote_id(
|
||||||
"https://example.com/user/mouse", model=models.User
|
"https://example.com/user/mouse", model=models.User
|
||||||
|
|
|
@ -111,6 +111,7 @@ class AbstractConnector(TestCase):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET, "https://example.com/book/abcd", json=self.edition_data
|
responses.GET, "https://example.com/book/abcd", json=self.edition_data
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
|
with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
|
||||||
result = self.connector.get_or_create_book("https://example.com/book/abcd")
|
result = self.connector.get_or_create_book("https://example.com/book/abcd")
|
||||||
self.assertEqual(result, self.book)
|
self.assertEqual(result, self.book)
|
||||||
|
|
|
@ -230,6 +230,7 @@ class Openlibrary(TestCase):
|
||||||
json={"hi": "there"},
|
json={"hi": "there"},
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
||||||
) as mock:
|
) as mock:
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SelfConnector(TestCase):
|
||||||
def test_search_rank(self):
|
def test_search_rank(self):
|
||||||
"""prioritize certain results"""
|
"""prioritize certain results"""
|
||||||
author = models.Author.objects.create(name="Anonymous")
|
author = models.Author.objects.create(name="Anonymous")
|
||||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
edition = models.Edition.objects.create(
|
edition = models.Edition.objects.create(
|
||||||
title="Edition of Example Work",
|
title="Edition of Example Work",
|
||||||
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
||||||
|
|
|
@ -357,6 +357,7 @@ class ActivitypubFields(TestCase):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET, "https://example.com/user/mouse", json=userdata, status=200
|
responses.GET, "https://example.com/user/mouse", json=userdata, status=200
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
value = instance.field_from_activity(
|
value = instance.field_from_activity(
|
||||||
["https://example.com/user/mouse", "bleh"]
|
["https://example.com/user/mouse", "bleh"]
|
||||||
|
|
|
@ -175,6 +175,7 @@ class ImportJob(TestCase):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
||||||
):
|
):
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
book = self.item_1.get_book_from_isbn()
|
book = self.item_1.get_book_from_isbn()
|
||||||
|
|
||||||
self.assertEqual(book.title, "Sabriel")
|
self.assertEqual(book.title, "Sabriel")
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Status(TestCase):
|
||||||
child = models.Status.objects.create(
|
child = models.Status.objects.create(
|
||||||
content="hello", reply_parent=parent, user=self.local_user
|
content="hello", reply_parent=parent, user=self.local_user
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.preview_images.generate_edition_image_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
models.Review.objects.create(
|
models.Review.objects.create(
|
||||||
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
||||||
)
|
)
|
||||||
|
|
|
@ -162,6 +162,7 @@ class InboxCreate(TestCase):
|
||||||
"rating": 3,
|
"rating": 3,
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
}
|
}
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
self.assertTrue(redis_mock.called)
|
self.assertTrue(redis_mock.called)
|
||||||
|
|
|
@ -98,6 +98,8 @@ class InboxUpdate(TestCase):
|
||||||
del userdata["icon"]
|
del userdata["icon"]
|
||||||
self.assertIsNone(self.remote_user.name)
|
self.assertIsNone(self.remote_user.name)
|
||||||
self.assertFalse(self.remote_user.discoverable)
|
self.assertFalse(self.remote_user.discoverable)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
views.inbox.activity_task(
|
views.inbox.activity_task(
|
||||||
{
|
{
|
||||||
"type": "Update",
|
"type": "Update",
|
||||||
|
|
|
@ -74,6 +74,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
request.user.is_superuser = True
|
request.user.is_superuser = True
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
result = view(request, self.book.id)
|
result = view(request, self.book.id)
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
result.render()
|
result.render()
|
||||||
|
@ -89,7 +90,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
view(request, self.book.id)
|
view(request, self.book.id)
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
view(request, self.book.id)
|
view(request, self.book.id)
|
||||||
|
|
||||||
|
@ -149,6 +150,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
view(request, self.book.id)
|
view(request, self.book.id)
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
|
@ -165,6 +167,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
view(request)
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work.title, "New Title")
|
self.assertEqual(book.parent_work.title, "New Title")
|
||||||
|
@ -180,6 +183,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
view(request)
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work, self.work)
|
self.assertEqual(book.parent_work, self.work)
|
||||||
|
@ -196,6 +200,7 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
view(request)
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work.title, "New Title")
|
self.assertEqual(book.parent_work.title, "New Title")
|
||||||
|
|
|
@ -55,6 +55,7 @@ class GetStartedViews(TestCase):
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
self.assertIsNone(self.local_user.name)
|
self.assertIsNone(self.local_user.name)
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
) as delay_mock:
|
) as delay_mock:
|
||||||
|
|
|
@ -144,6 +144,7 @@ class ViewsHelpers(TestCase):
|
||||||
json=self.userdata,
|
json=self.userdata,
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
result = views.helpers.handle_remote_webfinger("@mouse@example.com")
|
result = views.helpers.handle_remote_webfinger("@mouse@example.com")
|
||||||
self.assertIsInstance(result, models.User)
|
self.assertIsInstance(result, models.User)
|
||||||
|
|
|
@ -162,6 +162,7 @@ class UserViews(TestCase):
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
self.assertIsNone(self.local_user.name)
|
self.assertIsNone(self.local_user.name)
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
) as delay_mock:
|
) as delay_mock:
|
||||||
|
@ -186,6 +187,7 @@ class UserViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
) as delay_mock:
|
) as delay_mock:
|
||||||
|
|
Loading…
Reference in a new issue