Adds more tests

This commit is contained in:
Mouse Reeve 2022-01-18 13:15:25 -08:00
parent ffaeb3381a
commit 3f487328e2
5 changed files with 34 additions and 22 deletions

View file

@ -9,7 +9,7 @@ from bookwyrm.templatetags import feed_page_tags
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
class BookWyrmTags(TestCase):
class FeedPageTags(TestCase):
"""lotta different things here"""
def setUp(self):

View file

@ -9,7 +9,7 @@ from bookwyrm.templatetags import notification_page_tags
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
class BookWyrmTags(TestCase):
class NotificationPageTags(TestCase):
"""lotta different things here"""
def setUp(self):

View file

@ -48,9 +48,7 @@ class RatingTags(TestCase):
book=self.book,
privacy="followers",
)
self.assertEqual(
rating_tags.get_rating(self.book, self.local_user), 0
)
self.assertEqual(rating_tags.get_rating(self.book, self.local_user), 0)
# public: included
models.ReviewRating.objects.create(
@ -59,9 +57,7 @@ class RatingTags(TestCase):
book=self.book,
privacy="public",
)
self.assertEqual(
rating_tags.get_rating(self.book, self.local_user), 5
)
self.assertEqual(rating_tags.get_rating(self.book, self.local_user), 5)
# rating unset: not included
models.Review.objects.create(
@ -71,10 +67,7 @@ class RatingTags(TestCase):
book=self.book,
privacy="public",
)
self.assertEqual(
rating_tags.get_rating(self.book, self.local_user), 5
)
self.assertEqual(rating_tags.get_rating(self.book, self.local_user), 5)
def test_get_user_rating(self, *_):
"""get a user's most recent rating of a book"""

View file

@ -1,4 +1,5 @@
""" style fixes and lookups for templates """
from datetime import datetime
from unittest.mock import patch
from django.test import TestCase
@ -35,6 +36,12 @@ class StatusDisplayTags(TestCase):
)
self.book = models.Edition.objects.create(title="Test Book")
def test_get_mentions(self, *_):
"""list of people mentioned"""
status = models.Status.objects.create(content="hi", user=self.remote_user)
result = status_display.get_mentions(status, self.user)
self.assertEqual(result, "@rat@example.com ")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_get_replies(self, *_):
"""direct replies to a status"""
@ -83,8 +90,16 @@ class StatusDisplayTags(TestCase):
self.assertIsInstance(boosted, models.Review)
self.assertEqual(boosted, status)
def test_get_mentions(self, *_):
"""list of people mentioned"""
status = models.Status.objects.create(content="hi", user=self.remote_user)
result = status_display.get_mentions(status, self.user)
self.assertEqual(result, "@rat@example.com ")
def test_get_published_date(self, *_):
"""date formatting"""
date = datetime(2020, 1, 1, 0, 0, tzinfo=timezone.utc)
with patch("django.utils.timezone.now") as timezone_mock:
timezone_mock.return_value = datetime(2022, 1, 1, 0, 0, tzinfo=timezone.utc)
result = status_display.get_published_date(date)
self.assertEqual(result, "Jan. 1, 2020")
date = datetime(2022, 1, 1, 0, 0, tzinfo=timezone.utc)
with patch("django.utils.timezone.now") as timezone_mock:
timezone_mock.return_value = datetime(2022, 1, 8, 0, 0, tzinfo=timezone.utc)
result = status_display.get_published_date(date)
self.assertEqual(result, "Jan 1")

View file

@ -35,6 +35,15 @@ class UtilitiesTags(TestCase):
)
self.book = models.Edition.objects.create(title="Test Book")
def test_get_uuid(self, *_):
"""uuid functionality"""
uuid = utilities.get_uuid("hi")
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
def test_join(self, *_):
"""concats things with underscores"""
self.assertEqual(utilities.join("hi", 5, "blah", 0.75), "hi_5_blah_0.75")
def test_get_user_identifer_local(self, *_):
"""fall back to the simplest uid available"""
self.assertNotEqual(self.user.username, self.user.localname)
@ -46,11 +55,6 @@ class UtilitiesTags(TestCase):
utilities.get_user_identifier(self.remote_user), "rat@example.com"
)
def test_get_uuid(self, *_):
"""uuid functionality"""
uuid = utilities.get_uuid("hi")
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
def test_get_title(self, *_):
"""the title of a book"""
self.assertEqual(utilities.get_title(None), "")