Browse Source

Merge "Add proxies to url checker cli"

Jenkins 3 years ago
parent
commit
01832db3c9
2 changed files with 25 additions and 1 deletions
  1. 12
    1
      url_access_checker/commands.py
  2. 13
    0
      url_access_checker/tests/unit/test_commands.py

+ 12
- 1
url_access_checker/commands.py View File

@@ -33,12 +33,23 @@ class CheckUrls(command.Command):
33 33
                             help='List of urls to check')
34 34
         parser.add_argument('--timeout', type=int, default=60,
35 35
                             help='Max time to wait for response, Default: 60')
36
+        parser.add_argument('--http-proxy', type=str, default=None,
37
+                            help='Http proxy, Default: None')
38
+        parser.add_argument('--https-proxy', type=str, default=None,
39
+                            help='Https proxy, Default: None')
36 40
         return parser
37 41
 
38 42
     def take_action(self, parsed_args):
39 43
         LOG.info('Starting url access check for {0}'.format(parsed_args.urls))
44
+        proxies = {}
45
+        if parsed_args.http_proxy:
46
+            proxies['http'] = parsed_args.http_proxy
47
+        if parsed_args.https_proxy:
48
+            proxies['https'] = parsed_args.https_proxy
40 49
         try:
41
-            api.check_urls(parsed_args.urls, timeout=parsed_args.timeout)
50
+            api.check_urls(parsed_args.urls,
51
+                           proxies=proxies or None,
52
+                           timeout=parsed_args.timeout)
42 53
         except errors.UrlNotAvailable as e:
43 54
             sys.stdout.write(str(e))
44 55
             raise e

+ 13
- 0
url_access_checker/tests/unit/test_commands.py View File

@@ -34,6 +34,19 @@ class TestUrlCheckerCommands(unittest.TestCase):
34 34
         exit_code = cli.main(['check'] + self.urls)
35 35
         self.assertEqual(exit_code, 0)
36 36
 
37
+    @mock.patch('url_access_checker.api.check_urls')
38
+    def test_check_urls_proxies(self, check_mock):
39
+        cli.UrlAccessCheckApp.LOG_FILENAME = './url_access_checker.log'
40
+        proxies = {
41
+            'http': 'http_proxy',
42
+            'https': 'https_proxy'
43
+        }
44
+        cli.main(['check',
45
+                  '--http-proxy', 'http_proxy',
46
+                  '--https-proxy', 'https_proxy'] + self.urls)
47
+        check_mock.assert_called_once_with(
48
+            self.urls, proxies=proxies, timeout=60)
49
+
37 50
     @mock.patch('requests.get')
38 51
     def test_check_urls_fail(self, get_mock):
39 52
         response_mock = mock.Mock()

Loading…
Cancel
Save