libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: Add tests for libcloud.utils.networking.is.valid_ip_address.
Date Wed, 04 Dec 2013 01:20:52 GMT
Updated Branches:
  refs/heads/trunk 74dd72687 -> 146a4890e


Add tests for libcloud.utils.networking.is.valid_ip_address.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/fad678a8
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/fad678a8
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/fad678a8

Branch: refs/heads/trunk
Commit: fad678a87a61026acbcb4f5794abcdc5bdb1272e
Parents: 74dd726
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Wed Dec 4 01:35:47 2013 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Wed Dec 4 01:35:47 2013 +0100

----------------------------------------------------------------------
 libcloud/test/test_utils.py | 53 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fad678a8/libcloud/test/test_utils.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_utils.py b/libcloud/test/test_utils.py
index 0233036..9e147b6 100644
--- a/libcloud/test/test_utils.py
+++ b/libcloud/test/test_utils.py
@@ -15,11 +15,14 @@
 # limitations under the License.
 
 import sys
+import socket
 import codecs
 import unittest
 import warnings
 import os.path
 
+from itertools import chain
+
 # In Python > 2.7 DeprecationWarnings are disabled by default
 warnings.simplefilter('default')
 
@@ -34,6 +37,7 @@ from libcloud.utils.py3 import urlquote
 from libcloud.compute.types import Provider
 from libcloud.compute.providers import DRIVERS
 from libcloud.utils.misc import get_secure_random_string
+from libcloud.utils.networking import is_valid_ip_address
 
 
 WARNINGS_BUFFER = []
@@ -233,5 +237,54 @@ class TestUtils(unittest.TestCase):
             self.assertEqual(len(value), i)
 
 
+class NetworkingUtilsTestCase(unittest.TestCase):
+    def test_is_valid_ip_address(self):
+        valid_ipv4_addresses = [
+            '192.168.1.100',
+            '10.0.0.1',
+            '213.151.0.8',
+            '77.77.77.77'
+        ]
+
+        invalid_ipv4_addresses = [
+            '10.1',
+            '256.256.256.256',
+            '0.567.567.567',
+            '192.168.0.257'
+        ]
+
+        valid_ipv6_addresses = [
+            'fe80::200:5aee:feaa:20a2',
+            '2607:f0d0:1002:51::4',
+            '2607:f0d0:1002:0051:0000:0000:0000:0004',
+            '::1'
+        ]
+
+        invalid_ipv6_addresses = [
+            '2607:f0d',
+            '2607:f0d0:0004',
+        ]
+
+        for address in valid_ipv4_addresses:
+            status = is_valid_ip_address(address=address,
+                                         family=socket.AF_INET)
+            self.assertTrue(status)
+
+        for address in valid_ipv6_addresses:
+            status = is_valid_ip_address(address=address,
+                                         family=socket.AF_INET6)
+            self.assertTrue(status)
+
+        for address in chain(invalid_ipv4_addresses, invalid_ipv6_addresses):
+            status = is_valid_ip_address(address=address,
+                                         family=socket.AF_INET)
+            self.assertFalse(status)
+
+        for address in chain(invalid_ipv4_addresses, invalid_ipv6_addresses):
+            status = is_valid_ip_address(address=address,
+                                         family=socket.AF_INET6)
+            self.assertFalse(status)
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message