Skip to content

Commit 2146c42

Browse files
committed
mirrors: test the MirrorRsync model
1 parent cc8996e commit 2146c42

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

mirrors/tests/test_mirrorrsync.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from django.test import TransactionTestCase
2+
3+
from mirrors.models import MirrorRsync, Mirror
4+
5+
6+
TEST_IPV6 = "2a0b:4342:1a31:410::"
7+
TEST_IPV4 = "8.8.8.8"
8+
9+
class MirrorRsyncTest(TransactionTestCase):
10+
def setUp(self):
11+
self.mirror = Mirror.objects.create(name='rmirror',
12+
admin_email='[email protected]')
13+
14+
def tearDown(self):
15+
self.mirror.delete()
16+
17+
def test_ipv6(self):
18+
mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV6, mirror=self.mirror)
19+
self.assertEqual(str(mirrorrsync), TEST_IPV6)
20+
mirrorrsync.delete()
21+
22+
def test_ipv4(self):
23+
mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4, mirror=self.mirror)
24+
self.assertEqual(str(mirrorrsync), TEST_IPV4)
25+
mirrorrsync.delete()
26+
27+
def test_invalid(self):
28+
with self.assertRaises(ValueError) as e:
29+
MirrorRsync.objects.create(ip="8.8.8.8.8", mirror=self.mirror)
30+
self.assertIn('IPv4 Address with more than 4 bytes', str(e.exception))

0 commit comments

Comments
 (0)