Updates tests to catch decimal/float/int errors in status serialization

This commit is contained in:
Mouse Reeve 2021-03-24 10:17:45 -07:00
parent e3350e58d0
commit 4ca76ec58d
2 changed files with 26 additions and 4 deletions

View file

@ -1,3 +1,3 @@
{% load i18n %}{% load humanize %}
{% blocktrans with title=book.title path=book.remote_id rating=rating|floatformat:"0" count counter=rating %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ rating }} star{% plural %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ rating }} stars{% endblocktrans %}
{% blocktrans with title=book.title path=book.remote_id display_rating=rating|floatformat:"0" count counter=rating %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ display_rating }} star{% plural %}Rated <em><a href="{{ path }}">{{ title }}</a></em>: {{ display_rating }} stars{% endblocktrans %}

View file

@ -250,7 +250,7 @@ class Status(TestCase):
status = models.Review.objects.create(
name="Review name",
content="test content",
rating=3,
rating=3.0,
user=self.local_user,
book=self.book,
)
@ -267,7 +267,7 @@ class Status(TestCase):
status = models.Review.objects.create(
name="Review name",
content="test content",
rating=3,
rating=3.0,
user=self.local_user,
book=self.book,
)
@ -308,7 +308,29 @@ class Status(TestCase):
)
self.assertEqual(activity["attachment"][0].name, "Test Edition")
def test_favorite(self, _):
def test_reviewrating_to_pure_activity(self, *_):
""" subclass of the base model version with a "pure" serializer """
status = models.ReviewRating.objects.create(
rating=3.0,
user=self.local_user,
book=self.book,
)
activity = status.to_activity(pure=True)
self.assertEqual(activity["id"], status.remote_id)
self.assertEqual(activity["type"], "Note")
self.assertEqual(
activity["content"],
'Rated <em><a href="%s">%s</a></em>: 3 stars'
% (self.book.remote_id, self.book.title),
)
self.assertEqual(activity["attachment"][0].type, "Document")
self.assertEqual(
activity["attachment"][0].url,
"https://%s%s" % (settings.DOMAIN, self.book.cover.url),
)
self.assertEqual(activity["attachment"][0].name, "Test Edition")
def test_favorite(self, *_):
""" fav a status """
real_broadcast = models.Favorite.broadcast