mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 12:01:14 +00:00
More test fixes
This commit is contained in:
parent
ef71da7ef0
commit
c3a09a6331
3 changed files with 27 additions and 26 deletions
|
@ -16,6 +16,7 @@ from bookwyrm import activitypub, models, settings
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
@patch("bookwyrm.models.Status.broadcast")
|
@patch("bookwyrm.models.Status.broadcast")
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
class Status(TestCase):
|
class Status(TestCase):
|
||||||
"""lotta types of statuses"""
|
"""lotta types of statuses"""
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ from bookwyrm.templatetags import (
|
||||||
|
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
class TemplateTags(TestCase):
|
class TemplateTags(TestCase):
|
||||||
"""lotta different things here"""
|
"""lotta different things here"""
|
||||||
|
|
||||||
|
@ -38,28 +39,28 @@ class TemplateTags(TestCase):
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(title="Test Book")
|
self.book = models.Edition.objects.create(title="Test Book")
|
||||||
|
|
||||||
def test_get_user_rating(self, _):
|
def test_get_user_rating(self, *_):
|
||||||
"""get a user's most recent rating of a book"""
|
"""get a user's most recent rating of a book"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
models.Review.objects.create(user=self.user, book=self.book, rating=3)
|
models.Review.objects.create(user=self.user, book=self.book, rating=3)
|
||||||
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
|
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
|
||||||
|
|
||||||
def test_get_user_rating_doesnt_exist(self, _):
|
def test_get_user_rating_doesnt_exist(self, *_):
|
||||||
"""there is no rating available"""
|
"""there is no rating available"""
|
||||||
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 0)
|
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 0)
|
||||||
|
|
||||||
def test_get_user_identifer_local(self, _):
|
def test_get_user_identifer_local(self, *_):
|
||||||
"""fall back to the simplest uid available"""
|
"""fall back to the simplest uid available"""
|
||||||
self.assertNotEqual(self.user.username, self.user.localname)
|
self.assertNotEqual(self.user.username, self.user.localname)
|
||||||
self.assertEqual(utilities.get_user_identifier(self.user), "mouse")
|
self.assertEqual(utilities.get_user_identifier(self.user), "mouse")
|
||||||
|
|
||||||
def test_get_user_identifer_remote(self, _):
|
def test_get_user_identifer_remote(self, *_):
|
||||||
"""for a remote user, should be their full username"""
|
"""for a remote user, should be their full username"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
utilities.get_user_identifier(self.remote_user), "rat@example.com"
|
utilities.get_user_identifier(self.remote_user), "rat@example.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_replies(self, _):
|
def test_get_replies(self, *_):
|
||||||
"""direct replies to a status"""
|
"""direct replies to a status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
parent = models.Review.objects.create(
|
parent = models.Review.objects.create(
|
||||||
|
@ -87,7 +88,7 @@ class TemplateTags(TestCase):
|
||||||
self.assertTrue(second_child in replies)
|
self.assertTrue(second_child in replies)
|
||||||
self.assertFalse(third_child in replies)
|
self.assertFalse(third_child in replies)
|
||||||
|
|
||||||
def test_get_parent(self, _):
|
def test_get_parent(self, *_):
|
||||||
"""get the reply parent of a status"""
|
"""get the reply parent of a status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
parent = models.Review.objects.create(
|
parent = models.Review.objects.create(
|
||||||
|
@ -101,7 +102,7 @@ class TemplateTags(TestCase):
|
||||||
self.assertEqual(result, parent)
|
self.assertEqual(result, parent)
|
||||||
self.assertIsInstance(result, models.Review)
|
self.assertIsInstance(result, models.Review)
|
||||||
|
|
||||||
def test_get_user_liked(self, _):
|
def test_get_user_liked(self, *_):
|
||||||
"""did a user like a status"""
|
"""did a user like a status"""
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ class TemplateTags(TestCase):
|
||||||
models.Favorite.objects.create(user=self.user, status=status)
|
models.Favorite.objects.create(user=self.user, status=status)
|
||||||
self.assertTrue(interaction.get_user_liked(self.user, status))
|
self.assertTrue(interaction.get_user_liked(self.user, status))
|
||||||
|
|
||||||
def test_get_user_boosted(self, _):
|
def test_get_user_boosted(self, *_):
|
||||||
"""did a user boost a status"""
|
"""did a user boost a status"""
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ class TemplateTags(TestCase):
|
||||||
models.Boost.objects.create(user=self.user, boosted_status=status)
|
models.Boost.objects.create(user=self.user, boosted_status=status)
|
||||||
self.assertTrue(interaction.get_user_boosted(self.user, status))
|
self.assertTrue(interaction.get_user_boosted(self.user, status))
|
||||||
|
|
||||||
def test_get_boosted(self, _):
|
def test_get_boosted(self, *_):
|
||||||
"""load a boosted status"""
|
"""load a boosted status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
||||||
|
@ -128,7 +129,7 @@ class TemplateTags(TestCase):
|
||||||
self.assertIsInstance(boosted, models.Review)
|
self.assertIsInstance(boosted, models.Review)
|
||||||
self.assertEqual(boosted, status)
|
self.assertEqual(boosted, status)
|
||||||
|
|
||||||
def test_get_book_description(self, _):
|
def test_get_book_description(self, *_):
|
||||||
"""grab it from the edition or the parent"""
|
"""grab it from the edition or the parent"""
|
||||||
work = models.Work.objects.create(title="Test Work")
|
work = models.Work.objects.create(title="Test Work")
|
||||||
self.book.parent_work = work
|
self.book.parent_work = work
|
||||||
|
@ -144,12 +145,12 @@ class TemplateTags(TestCase):
|
||||||
self.book.save()
|
self.book.save()
|
||||||
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
|
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
|
||||||
|
|
||||||
def test_get_uuid(self, _):
|
def test_get_uuid(self, *_):
|
||||||
"""uuid functionality"""
|
"""uuid functionality"""
|
||||||
uuid = utilities.get_uuid("hi")
|
uuid = utilities.get_uuid("hi")
|
||||||
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
|
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
|
||||||
|
|
||||||
def test_get_markdown(self, _):
|
def test_get_markdown(self, *_):
|
||||||
"""mardown format data"""
|
"""mardown format data"""
|
||||||
result = markdown.get_markdown("_hi_")
|
result = markdown.get_markdown("_hi_")
|
||||||
self.assertEqual(result, "<p><em>hi</em></p>")
|
self.assertEqual(result, "<p><em>hi</em></p>")
|
||||||
|
@ -157,13 +158,13 @@ class TemplateTags(TestCase):
|
||||||
result = markdown.get_markdown("<marquee>_hi_</marquee>")
|
result = markdown.get_markdown("<marquee>_hi_</marquee>")
|
||||||
self.assertEqual(result, "<p><em>hi</em></p>")
|
self.assertEqual(result, "<p><em>hi</em></p>")
|
||||||
|
|
||||||
def test_get_mentions(self, _):
|
def test_get_mentions(self, *_):
|
||||||
"""list of people mentioned"""
|
"""list of people mentioned"""
|
||||||
status = models.Status.objects.create(content="hi", user=self.remote_user)
|
status = models.Status.objects.create(content="hi", user=self.remote_user)
|
||||||
result = status_display.get_mentions(status, self.user)
|
result = status_display.get_mentions(status, self.user)
|
||||||
self.assertEqual(result, "@rat@example.com ")
|
self.assertEqual(result, "@rat@example.com ")
|
||||||
|
|
||||||
def test_related_status(self, _):
|
def test_related_status(self, *_):
|
||||||
"""gets the subclass model for a notification status"""
|
"""gets the subclass model for a notification status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
status = models.Status.objects.create(content="hi", user=self.user)
|
status = models.Status.objects.create(content="hi", user=self.user)
|
||||||
|
|
|
@ -51,7 +51,8 @@ class InboxActivities(TestCase):
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
def test_boost(self, redis_mock):
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
|
def test_boost(self, redis_mock, _):
|
||||||
"""boost a status"""
|
"""boost a status"""
|
||||||
self.assertEqual(models.Notification.objects.count(), 0)
|
self.assertEqual(models.Notification.objects.count(), 0)
|
||||||
activity = {
|
activity = {
|
||||||
|
@ -81,7 +82,8 @@ class InboxActivities(TestCase):
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
def test_boost_remote_status(self, redis_mock):
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
|
def test_boost_remote_status(self, redis_mock, _):
|
||||||
"""boost a status from a remote server"""
|
"""boost a status from a remote server"""
|
||||||
work = models.Work.objects.create(title="work title")
|
work = models.Work.objects.create(title="work title")
|
||||||
book = models.Edition.objects.create(
|
book = models.Edition.objects.create(
|
||||||
|
@ -153,12 +155,13 @@ class InboxActivities(TestCase):
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
self.assertEqual(models.Boost.objects.count(), 0)
|
self.assertEqual(models.Boost.objects.count(), 0)
|
||||||
|
|
||||||
def test_unboost(self):
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
|
def test_unboost(self, *_):
|
||||||
"""undo a boost"""
|
"""undo a boost"""
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
boost = models.Boost.objects.create(
|
||||||
boost = models.Boost.objects.create(
|
boosted_status=self.status, user=self.remote_user
|
||||||
boosted_status=self.status, user=self.remote_user
|
)
|
||||||
)
|
|
||||||
activity = {
|
activity = {
|
||||||
"type": "Undo",
|
"type": "Undo",
|
||||||
"actor": "hi",
|
"actor": "hi",
|
||||||
|
@ -175,11 +178,7 @@ class InboxActivities(TestCase):
|
||||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
with patch(
|
views.inbox.activity_task(activity)
|
||||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
|
||||||
) as redis_mock:
|
|
||||||
views.inbox.activity_task(activity)
|
|
||||||
self.assertTrue(redis_mock.called)
|
|
||||||
self.assertFalse(models.Boost.objects.exists())
|
self.assertFalse(models.Boost.objects.exists())
|
||||||
|
|
||||||
def test_unboost_unknown_boost(self):
|
def test_unboost_unknown_boost(self):
|
||||||
|
|
Loading…
Reference in a new issue