From 574c1db7325e38cd693046bcef4ef47e2d0d2753 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Jul 2022 10:50:50 -0700 Subject: [PATCH] Adds more templatetag tests --- bookwyrm/templatetags/utilities.py | 2 +- bookwyrm/tests/templatetags/test_utilities.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 00fa4035c..834d39a14 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -53,7 +53,7 @@ def comparison_bool(str1, str2, reverse=False): @register.filter(is_safe=True) def truncatepath(value, arg): - """Truncate a path by removing all directories except the first and truncating .""" + """Truncate a path by removing all directories except the first and truncating""" path = os.path.normpath(value.name) path_list = path.split(os.sep) try: diff --git a/bookwyrm/tests/templatetags/test_utilities.py b/bookwyrm/tests/templatetags/test_utilities.py index 0136ca8cd..7738a51d9 100644 --- a/bookwyrm/tests/templatetags/test_utilities.py +++ b/bookwyrm/tests/templatetags/test_utilities.py @@ -1,4 +1,5 @@ """ style fixes and lookups for templates """ +from collections import namedtuple import re from unittest.mock import patch @@ -61,3 +62,18 @@ class UtilitiesTags(TestCase): self.assertEqual(utilities.get_title(self.book), "Test Book") book = models.Edition.objects.create(title="Oh", subtitle="oh my") self.assertEqual(utilities.get_title(book), "Oh: oh my") + + def test_comparison_bool(self, *_): + """just a simple comparison""" + self.assertTrue(utilities.comparison_bool("a", "a")) + self.assertFalse(utilities.comparison_bool("a", "b")) + + self.assertFalse(utilities.comparison_bool("a", "a", reverse=True)) + self.assertTrue(utilities.comparison_bool("a", "b", reverse=True)) + + def test_truncatepath(self, *_): + """truncate a path""" + ValueMock = namedtuple("Value", ("name")) + value = ValueMock("home/one/two/three/four") + self.assertEqual(utilities.truncatepath(value, 2), "home/…ur") + self.assertEqual(utilities.truncatepath(value, "a"), "four")