Adds more templatetag tests

This commit is contained in:
Mouse Reeve 2022-07-06 10:50:50 -07:00
parent 87434fbb9d
commit 574c1db732
2 changed files with 17 additions and 1 deletions

View file

@ -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:

View file

@ -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")