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 73e38f9050
commit 30cebc017f
2 changed files with 25 additions and 3 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

@ -252,7 +252,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,
)
@ -269,7 +269,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,
)
@ -310,6 +310,28 @@ class Status(TestCase):
)
self.assertEqual(activity["attachment"][0].name, "Test Edition")
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