Add unit test for proxy
authorHuanhuan Li <huanhuanx.li@intel.com>
Thu, 22 Aug 2013 23:11:09 +0000 (07:11 +0800)
committerHuanhuanX Li <huanhuanx.li@intel.com>
Wed, 5 Mar 2014 08:27:05 +0000 (10:27 +0200)
Change-Id: Ic3f5567df03125ef28ca96e16b23869996a6d6ed

tests/suite.py
tests/test_proxy.py [new file with mode: 0644]

index 66abd2d..dea87ab 100644 (file)
@@ -7,6 +7,7 @@ import test_baseimager
 #import test_msger
 import test_runner
 import test_chroot
+import test_proxy
 
 if os.getuid() != 0:
     raise SystemExit("Root permission is needed")
@@ -18,5 +19,6 @@ suite.addTests(test_baseimager.suite())
 #suite.addTests(test_msger.suite())
 suite.addTests(test_runner.suite())
 suite.addTests(test_chroot.suite())
+suite.addTests(test_proxy.suite())
 result = unittest.TextTestRunner(verbosity=2).run(suite)
 sys.exit(not result.wasSuccessful())
diff --git a/tests/test_proxy.py b/tests/test_proxy.py
new file mode 100644 (file)
index 0000000..9655b58
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import unittest
+from mic.utils import proxy
+
+def suite():
+    return unittest.makeSuite(ProxyTest)
+
+class ProxyTest(unittest.TestCase):
+
+    def test_proxy(self):
+        proxy.set_proxies('http://proxy.some.com:11', '1.2.3.4')
+        self.assertEqual(proxy.get_proxy_for('http://1.2.3.4'), None)
+        self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11')
+
+        proxy.set_proxies('http://proxy.some.com:11', 'download.am.org')
+        self.assertEqual(proxy.get_proxy_for('http://download.am.org'), None)
+        self.assertEqual(proxy.get_proxy_for('https://download.am.org'), None)
+        self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11')
+
+        proxy.set_proxies('http://proxy.some.com:11', '1.2.3.0/24')
+        self.assertEqual(proxy.get_proxy_for('http://1.2.3.4'), None)
+        self.assertEqual(proxy.get_proxy_for('http://1.2.3.0'), None)
+        self.assertEqual(proxy.get_proxy_for('http://1.2.3.255'), None)
+        self.assertEqual(proxy.get_proxy_for('http://download.tizen.org'), 'http://proxy.some.com:11')
+
+        proxy.set_proxies('http://proxy.some.com:11', '.hello.com')
+        self.assertEqual(proxy.get_proxy_for('http://linux.hello.com'), None)
+        self.assertEqual(proxy.get_proxy_for('http://linux.hello.com.org'), 'http://proxy.some.com:11')
+
+
+
+if __name__ == "__main__":
+    unittest.main()