summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorjelle van der Waa <jelle@vdwaa.nl>2018-01-29 20:10:10 +0100
committerAngel Velásquez <angvp@archlinux.org>2018-01-29 14:10:10 -0500
commit148692cd8fc79b3e43ef0f2c40a2da9d87c9da9e (patch)
treed34782a388091c4f14b24b9d0878f4a8265beef2 /main
parent2ff2b26aa92c8efd21090562091361924a3a9428 (diff)
downloadarchweb-148692cd8fc79b3e43ef0f2c40a2da9d87c9da9e.tar.gz
archweb-148692cd8fc79b3e43ef0f2c40a2da9d87c9da9e.zip
More code refactoring / tests (#79)
* main: move tests to main/tests Move the templatetags tests to main/tests/test_templatetags. * main: Add test for templatetags country Create a test for the templatetag country_flag. * main: remove duplicate floatvalue floatvalue is only used in the mirrors templates and the same exact function exists in the mirror_status templatetags. * main: Remove duplicate hours filter The hours filter is also defined in the mirror_status and only used in mirrors. * main: move percentage filter to mirrors Move the percentage filter to the only user of it and add a test for basic use cases. * main: remove duplicate duration implementation The duration templatetag filter is also defined in mirror_status.py * templates: remove unrequired import flags * main: Add missing testcase for country_flag Add the None test case, so that the function is fully covered. * todolists: create tests for Todolist model Add basic tests for the Todolist model
Diffstat (limited to 'main')
-rw-r--r--main/templatetags/flags.py36
-rw-r--r--main/tests/test_templatetags_flags.py22
-rw-r--r--main/tests/test_templatetags_pgp.py (renamed from main/tests.py)8
3 files changed, 29 insertions, 37 deletions
diff --git a/main/templatetags/flags.py b/main/templatetags/flags.py
index d50ee51d..3abd1aed 100644
--- a/main/templatetags/flags.py
+++ b/main/templatetags/flags.py
@@ -1,4 +1,3 @@
-from datetime import timedelta
from django import template
register = template.Library()
@@ -11,40 +10,5 @@ def country_flag(country):
return '<span class="fam-flag fam-flag-%s" title="%s"></span> ' % (
unicode(country.code).lower(), unicode(country.name))
-@register.filter
-def percentage(value, arg=1):
- if not value and type(value) != float:
- return u''
- new_val = value * 100.0
- return '%.*f%%' % (arg, new_val)
-
-@register.filter
-def duration(value):
- if not value and type(value) != timedelta:
- return u''
- # does not take microseconds into account
- total_secs = value.seconds + value.days * 24 * 3600
- mins = total_secs // 60
- hrs, mins = divmod(mins, 60)
- return '%d:%02d' % (hrs, mins)
-
-@register.filter
-def floatvalue(value, arg=2):
- if value is None:
- return u''
- return '%.*f' % (arg, value)
-
-
-@register.filter
-def hours(value):
- if not value and type(value) != timedelta:
- return u''
- # does not take microseconds into account
- total_secs = value.seconds + value.days * 24 * 3600
- mins = total_secs // 60
- hrs, mins = divmod(mins, 60)
- if hrs == 1:
- return '%d hour' % hrs
- return '%d hours' % hrs
# vim: set ts=4 sw=4 et:
diff --git a/main/tests/test_templatetags_flags.py b/main/tests/test_templatetags_flags.py
new file mode 100644
index 00000000..7ff0406c
--- /dev/null
+++ b/main/tests/test_templatetags_flags.py
@@ -0,0 +1,22 @@
+from django.test import TestCase
+
+
+from main.templatetags.flags import country_flag
+from mirrors.models import CheckLocation
+
+
+class FlagsTemplateTest(TestCase):
+
+ def setUp(self):
+ self.checkloc = CheckLocation.objects.create(hostname='arch.org',
+ source_ip='127.0.0.1',
+ country='US')
+
+ def tearDown(self):
+ self.checkloc.delete()
+
+ def test_country_flag(self):
+ flag = country_flag(self.checkloc.country)
+ self.assertIn(self.checkloc.country.name, flag)
+ self.assertIn(self.checkloc.country.code.lower(), flag)
+ self.assertEqual(country_flag(None), '')
diff --git a/main/tests.py b/main/tests/test_templatetags_pgp.py
index 130e7ed1..89e68ec6 100644
--- a/main/tests.py
+++ b/main/tests/test_templatetags_pgp.py
@@ -1,7 +1,7 @@
from django.conf import settings
from django.test import TestCase
-from main.templatetags.pgp import pgp_key_link, format_key
+from main.templatetags.pgp import pgp_key_link, format_key, pgp_fingerprint
class PGPTemplateTest(TestCase):
@@ -52,3 +52,9 @@ class PGPTemplateTest(TestCase):
with self.settings(PGP_SERVER_SECURE=False):
pgp_key = '423423fD9004FB063E2C81117BFB1108D234DAFZ'
self.assertNotIn("https", pgp_key_link(pgp_key))
+
+ def test_pgp_fingerprint(self):
+ self.assertEqual(pgp_fingerprint(None), u"")
+ keyid = '423423fD9004FB063E2C81117BFB1108D234DAFZ'
+ fingerprint = pgp_fingerprint(keyid)
+ self.assertTrue(len(fingerprint) > len(keyid))