mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Adds more templatetag tests
This commit is contained in:
parent
87434fbb9d
commit
574c1db732
2 changed files with 17 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue