summaryrefslogtreecommitdiffstats
path: root/activities/tests
diff options
context:
space:
mode:
authorMichael Manfre2022-11-20 13:14:49 -0500
committerGitHub2022-11-20 11:14:49 -0700
commitf8f4fa8665ef61caf5266c980046305f3b779c6d (patch)
treedb66d7e5e83b6d828db38f246b154e75a0d087b2 /activities/tests
parent6b7082a194a19579430e426ffc4bce52ffd336e9 (diff)
downloadtakahe-f8f4fa8665ef61caf5266c980046305f3b779c6d.tar.gz
takahe-f8f4fa8665ef61caf5266c980046305f3b779c6d.tar.bz2
takahe-f8f4fa8665ef61caf5266c980046305f3b779c6d.zip
Fix bug in timedeltashort and add tests
Diffstat (limited to 'activities/tests')
-rw-r--r--activities/tests/templatetags/__init__.py0
-rw-r--r--activities/tests/templatetags/test_activity_tags.py21
2 files changed, 21 insertions, 0 deletions
diff --git a/activities/tests/templatetags/__init__.py b/activities/tests/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/activities/tests/templatetags/__init__.py
diff --git a/activities/tests/templatetags/test_activity_tags.py b/activities/tests/templatetags/test_activity_tags.py
new file mode 100644
index 0000000..987c008
--- /dev/null
+++ b/activities/tests/templatetags/test_activity_tags.py
@@ -0,0 +1,21 @@
+from datetime import timedelta
+
+from django.utils import timezone
+
+from activities.templatetags.activity_tags import timedeltashort
+
+
+def test_timedeltashort_regress():
+ assert timedeltashort(None) == ""
+ assert timedeltashort("") == ""
+
+ value = timezone.now()
+
+ assert timedeltashort(value) == "0s"
+ assert timedeltashort(value - timedelta(seconds=2)) == "2s"
+ assert timedeltashort(value - timedelta(minutes=2)) == "2m"
+ assert timedeltashort(value - timedelta(hours=2)) == "2h"
+ assert timedeltashort(value - timedelta(days=2)) == "2d"
+ assert timedeltashort(value - timedelta(days=364)) == "364d"
+ assert timedeltashort(value - timedelta(days=365)) == "1y"
+ assert timedeltashort(value - timedelta(days=366)) == "1y"