summaryrefslogtreecommitdiffstats
path: root/mirrors/tests/test_models.py
diff options
context:
space:
mode:
authorjelle van der Waa <jelle@vdwaa.nl>2018-01-22 18:41:39 +0100
committerAngel Velásquez <angvp@archlinux.org>2018-01-22 12:41:39 -0500
commitf42f357fdf20d76bc5468ec227dac66cd0ca3ca8 (patch)
tree3603d73e12c84cf5513cef7ac8a2041289d34159 /mirrors/tests/test_models.py
parentc79dc7dcf4a13e381a59a63c57590f2272aa0869 (diff)
downloadarchweb-f42f357fdf20d76bc5468ec227dac66cd0ca3ca8.tar.gz
archweb-f42f357fdf20d76bc5468ec227dac66cd0ca3ca8.zip
Mirror tests (#78)release_2018-01-22
* mirrors: Move tests to mirrors/tests Move the tests to separate files in mirrors/tests and expand the model tests with tests for the Mirror class. * Add CheckLocation test * mirrors: Add tests for template filters Include tests for the filters used in the mirrors views. * devel: Add tests for template filter in_group Include a test for a simple case of the in_group filter.
Diffstat (limited to 'mirrors/tests/test_models.py')
-rw-r--r--mirrors/tests/test_models.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/mirrors/tests/test_models.py b/mirrors/tests/test_models.py
new file mode 100644
index 00000000..1e1eafec
--- /dev/null
+++ b/mirrors/tests/test_models.py
@@ -0,0 +1,70 @@
+from django.test import TestCase
+
+from mirrors.models import Mirror, CheckLocation
+from mirrors.tests import create_mirror_url
+
+
+class MirrorUrlTest(TestCase):
+ def setUp(self):
+ self.mirror_url = create_mirror_url()
+
+ def testAddressFamilies(self):
+ self.assertIsNotNone(self.mirror_url.address_families())
+
+ def testHostname(self):
+ self.assertEqual(self.mirror_url.hostname, 'archlinux.org')
+
+ def testGetAbsoluteUrl(self):
+ absolute_url = self.mirror_url.get_absolute_url()
+ expected = '/mirrors/%s/%d/' % (self.mirror_url.mirror.name, self.mirror_url.pk)
+ self.assertEqual(absolute_url, expected)
+
+ def test_mirror_overview(self):
+ response = self.client.get('/mirrors/')
+ self.assertEqual(response.status_code, 200)
+ self.assertIn(self.mirror_url.mirror.name, response.content)
+
+ def testClean(self):
+ # TODO: add test for self.mirror_url.clean()
+ pass
+
+ def tearDown(self):
+ self.mirror_url.delete()
+
+
+class MirrorTest(TestCase):
+ def setUp(self):
+ self.mirror = Mirror.objects.create(name='mirror1',
+ admin_email='admin@archlinux.org')
+
+ def tearDown(self):
+ self.mirror.delete()
+
+ def test_downstream(self):
+ self.assertEqual(list(self.mirror.downstream()), [])
+
+ def test_get_absolute_url(self):
+ absolute_url = self.mirror.get_absolute_url()
+ expected = '/mirrors/{}/'.format(self.mirror.name)
+ self.assertEqual(absolute_url, expected)
+
+ def test_get_full_url(self):
+ self.assertIn(self.mirror.get_absolute_url(), self.mirror.get_full_url())
+ self.assertIn('http', self.mirror.get_full_url('http'))
+
+
+class CheckLocationTest(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_family(self):
+ # TODO: mock socket.getaddrinfo in CheckLocation.family
+ self.assertIsInstance(self.checkloc.family, int)
+
+ def test_ip_version(self):
+ self.assertIsInstance(self.checkloc.ip_version, int)