forked from mirrors/bookwyrm
Fix tests
This commit is contained in:
parent
b8bff8a882
commit
b7965ce2ae
31 changed files with 380 additions and 367 deletions
|
@ -20,6 +20,7 @@ class Person(TestCase):
|
|||
|
||||
def test_user_to_model(self):
|
||||
activity = activitypub.Person(**self.user_data)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
user = activity.to_model(model=models.User)
|
||||
self.assertEqual(user.username, "mouse@example.com")
|
||||
|
|
|
@ -12,6 +12,7 @@ class Quotation(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""model objects we'll need"""
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.user = models.User.objects.create_user(
|
||||
"mouse",
|
||||
|
|
|
@ -82,7 +82,7 @@ class SelfConnector(TestCase):
|
|||
|
||||
def test_search_multiple_editions(self):
|
||||
"""it should get rid of duplicate editions for the same work"""
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
work = models.Work.objects.create(title="Work Title")
|
||||
edition_1 = models.Edition.objects.create(
|
||||
title="Edition 1 Title", parent_work=work
|
||||
|
|
|
@ -143,6 +143,7 @@ class ActivitypubMixins(TestCase):
|
|||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
another_remote_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
|
@ -166,6 +167,7 @@ class ActivitypubMixins(TestCase):
|
|||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
another_remote_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
|
@ -187,6 +189,7 @@ class ActivitypubMixins(TestCase):
|
|||
"""should combine users with the same shared_inbox"""
|
||||
self.remote_user.shared_inbox = "http://example.com/inbox"
|
||||
self.remote_user.save(broadcast=False)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
another_remote_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
|
@ -209,6 +212,7 @@ class ActivitypubMixins(TestCase):
|
|||
|
||||
def test_get_recipients_software(self, _):
|
||||
"""should differentiate between bookwyrm and other remote users"""
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
another_remote_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
|
|
|
@ -11,6 +11,7 @@ class FederatedServer(TestCase):
|
|||
def setUp(self):
|
||||
"""we'll need a user"""
|
||||
self.server = models.FederatedServer.objects.create(server_name="test.server")
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -10,6 +10,7 @@ class Relationship(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""we need some users for this"""
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -20,7 +21,6 @@ class Relationship(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
|
|
@ -356,6 +356,7 @@ class Status(TestCase):
|
|||
status = models.Status.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
fav = models.Favorite.objects.create(status=status, user=self.local_user)
|
||||
|
||||
# can't fav a status twice
|
||||
|
|
|
@ -35,6 +35,7 @@ class User(TestCase):
|
|||
self.assertIsNotNone(self.user.key_pair.public_key)
|
||||
|
||||
def test_remote_user(self):
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -119,6 +119,7 @@ class Signature(TestCase):
|
|||
status=200,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
||||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -142,6 +143,7 @@ class Signature(TestCase):
|
|||
data["publicKey"]["publicKeyPem"] = key_pair.public_key
|
||||
responses.add(responses.GET, self.fake_remote.remote_id, json=data, status=200)
|
||||
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
||||
# Key correct:
|
||||
response = self.send_test_request(sender=self.fake_remote)
|
||||
|
|
|
@ -146,6 +146,7 @@ class TemplateTags(TestCase):
|
|||
|
||||
def test_get_book_description(self, _):
|
||||
"""grab it from the edition or the parent"""
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book.parent_work = work
|
||||
self.book.save()
|
||||
|
|
|
@ -25,13 +25,6 @@ class InboxCreate(TestCase):
|
|||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -42,6 +35,13 @@ class InboxCreate(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
|
|
|
@ -119,6 +119,7 @@ class InboxActivities(TestCase):
|
|||
"object": self.remote_user.remote_id,
|
||||
}
|
||||
|
||||
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertFalse(models.User.objects.get(username="rat@example.com").is_active)
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ class InboxRelationships(TestCase):
|
|||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -34,6 +33,7 @@ class InboxRelationships(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -29,13 +29,6 @@ class ViewsHelpers(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -47,6 +40,13 @@ class ViewsHelpers(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
self.userdata = json.loads(datafile.read_bytes())
|
||||
del self.userdata["icon"]
|
||||
|
|
|
@ -24,13 +24,6 @@ class ReadingViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -41,6 +34,13 @@ class ReadingViews(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
|
||||
def test_start_reading(self, _):
|
||||
"""begin a book"""
|
||||
|
|
Loading…
Reference in a new issue