summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_jinja_filters.py7
-rw-r--r--src/tests/test_validate.py8
2 files changed, 12 insertions, 3 deletions
diff --git a/src/tests/test_jinja_filters.py b/src/tests/test_jinja_filters.py
index 57ff11070..17219802a 100644
--- a/src/tests/test_jinja_filters.py
+++ b/src/tests/test_jinja_filters.py
@@ -16,6 +16,7 @@
from unittest import TestCase
+from ipaddress import ip_network
from vyos.template import vyos_address_from_cidr
from vyos.template import vyos_netmask_from_cidr
from vyos.template import vyos_ipv4
@@ -26,9 +27,9 @@ class TestTeamplteHelpers(TestCase):
pass
def test_helpers_from_cidr(self):
- network = '192.0.2.0/26'
- self.assertEqual(vyos_address_from_cidr(network), '192.0.2.0')
- self.assertEqual(vyos_netmask_from_cidr(network), '255.255.255.192')
+ network_v4 = '192.0.2.0/26'
+ self.assertEqual(vyos_address_from_cidr(network_v4), str(ip_network(network_v4).network_address))
+ self.assertEqual(vyos_netmask_from_cidr(network_v4), str(ip_network(network_v4).netmask))
def test_helpers_ipv4(self):
self.assertTrue(vyos_ipv4('192.0.2.1'))
diff --git a/src/tests/test_validate.py b/src/tests/test_validate.py
index 5e2c751ca..e9fe185ed 100644
--- a/src/tests/test_validate.py
+++ b/src/tests/test_validate.py
@@ -28,12 +28,20 @@ class TestVyOSValidate(TestCase):
def test_is_ipv4(self):
self.assertTrue(vyos.validate.is_ipv4('192.0.2.1'))
+ self.assertTrue(vyos.validate.is_ipv4('192.0.2.0/24'))
+ self.assertTrue(vyos.validate.is_ipv4('192.0.2.1/32'))
+
self.assertFalse(vyos.validate.is_ipv4('2001:db8::1'))
+ self.assertFalse(vyos.validate.is_ipv4('2001:db8::/64'))
self.assertFalse(vyos.validate.is_ipv4('VyOS'))
def test_is_ipv6(self):
self.assertFalse(vyos.validate.is_ipv6('192.0.2.1'))
+ self.assertFalse(vyos.validate.is_ipv6('192.0.2.0/24'))
+ self.assertFalse(vyos.validate.is_ipv6('192.0.2.1/32'))
self.assertTrue(vyos.validate.is_ipv6('2001:db8::1'))
+ self.assertTrue(vyos.validate.is_ipv6('2001:db8::/64'))
+ self.assertTrue(vyos.validate.is_ipv6('2001:db8::1/64'))
self.assertFalse(vyos.validate.is_ipv6('VyOS'))
def test_is_ipv6_link_local(self):