summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@archlinux.org>2020-02-14 22:47:27 +0100
committerJelle van der Waa <jelle@archlinux.org>2020-02-14 22:47:27 +0100
commit2146c423fb8c4cefb39e3ab14227c7d3c9480e32 (patch)
tree6c5feb2b2043079f827afaafe70fcea911f06c04
parentcc8996ec08ca8ffc71863713a33af27c0e910ba9 (diff)
downloadarchweb-2146c423fb8c4cefb39e3ab14227c7d3c9480e32.tar.gz
archweb-2146c423fb8c4cefb39e3ab14227c7d3c9480e32.zip
mirrors: test the MirrorRsync model
-rw-r--r--mirrors/tests/test_mirrorrsync.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/mirrors/tests/test_mirrorrsync.py b/mirrors/tests/test_mirrorrsync.py
new file mode 100644
index 00000000..31dc325d
--- /dev/null
+++ b/mirrors/tests/test_mirrorrsync.py
@@ -0,0 +1,30 @@
+from django.test import TransactionTestCase
+
+from mirrors.models import MirrorRsync, Mirror
+
+
+TEST_IPV6 = "2a0b:4342:1a31:410::"
+TEST_IPV4 = "8.8.8.8"
+
+class MirrorRsyncTest(TransactionTestCase):
+ def setUp(self):
+ self.mirror = Mirror.objects.create(name='rmirror',
+ admin_email='foo@bar.com')
+
+ def tearDown(self):
+ self.mirror.delete()
+
+ def test_ipv6(self):
+ mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV6, mirror=self.mirror)
+ self.assertEqual(str(mirrorrsync), TEST_IPV6)
+ mirrorrsync.delete()
+
+ def test_ipv4(self):
+ mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4, mirror=self.mirror)
+ self.assertEqual(str(mirrorrsync), TEST_IPV4)
+ mirrorrsync.delete()
+
+ def test_invalid(self):
+ with self.assertRaises(ValueError) as e:
+ MirrorRsync.objects.create(ip="8.8.8.8.8", mirror=self.mirror)
+ self.assertIn('IPv4 Address with more than 4 bytes', str(e.exception))