From 5240d9239351b1a5ec71676e9c652927f1cd9532 Mon Sep 17 00:00:00 2001 From: Huanhuan Li Date: Fri, 23 Aug 2013 07:11:09 +0800 Subject: [PATCH] Add unit test for proxy Change-Id: Ic3f5567df03125ef28ca96e16b23869996a6d6ed --- tests/suite.py | 2 ++ tests/test_proxy.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/test_proxy.py diff --git a/tests/suite.py b/tests/suite.py index 66abd2d..dea87ab 100644 --- a/tests/suite.py +++ b/tests/suite.py @@ -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 index 0000000..9655b58 --- /dev/null +++ b/tests/test_proxy.py @@ -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() -- 2.7.4