def test_verification_route(self, mifaddr, mexist, mup, mgat, mexecute): mexecute.return_value = (0, '', '') mup.return_value = True mexist.return_value = True mifaddr.return_value = False default_gw, default_iface = '172.18.0.1', 'eth2' mgat.return_value = { 'default': {netifaces.AF_INET: (default_gw, default_iface)}} iface = 'eth1' addr = '10.10.0.2/24' gw = '10.10.0.1' cmd = ['with', 'setup', '-i', iface, '-a', addr, '-g', gw, 'test.url'] cli.main(cmd) execute_stack = [ call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'a', 'add', addr, 'dev', iface]), call(['ip', 'ro', 'change', 'default', 'via', gw, 'dev', iface]), call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'ro', 'change', 'default', 'via', default_gw, 'dev', default_iface]), call(['ip', 'a', 'del', addr, 'dev', iface]), call(['ip', 'a']), call(['ip', 'ro'])] self.assert_by_items(mexecute.call_args_list, execute_stack)
def test_check_urls_proxies(self, check_mock): cli.UrlAccessCheckApp.LOG_FILENAME = './url_access_checker.log' proxies = { 'http': 'http_proxy', 'https': 'https_proxy' } cli.main(['check', '--http-proxy', 'http_proxy', '--https-proxy', 'https_proxy'] + self.urls) check_mock.assert_called_once_with( self.urls, proxies=proxies, timeout=60)
def test_check_urls_fail(self, get_mock): response_mock = mock.Mock() response_mock.status_code = 404 get_mock.return_value = response_mock exit_code = cli.main(['check'] + self.urls) self.assertEqual(exit_code, 1)
def test_check_urls_success(self, get_mock): cli.UrlAccessCheckApp.LOG_FILENAME = './url_access_checker.log' response_mock = mock.Mock() response_mock.status_code = 200 get_mock.return_value = response_mock exit_code = cli.main(['check'] + self.urls) self.assertEqual(exit_code, 0)
def test_verification_vlan(self, mifaddr, mexist, mup, mready, mgat, mexecute): mexecute.return_value = (0, '', '') mup.return_value = False mexist.return_value = False mifaddr.return_value = False mready.return_value = True default_gw, default_iface = '172.18.0.1', 'eth2' mgat.return_value = { 'default': {netifaces.AF_INET: (default_gw, default_iface)}} iface = 'eth1' addr = '10.10.0.2/24' gw = '10.10.0.1' vlan = '101' tagged_iface = '{0}.{1}'.format(iface, vlan) cmd = ['with', 'setup', '-i', iface, '-a', addr, '-g', gw, '--vlan', vlan, 'test.url'] cli.main(cmd) execute_stack = [ call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'link', 'set', 'dev', iface, 'up']), call(['ip', 'link', 'add', 'link', 'eth1', 'name', tagged_iface, 'type', 'vlan', 'id', vlan]), call(['ip', 'link', 'set', 'dev', tagged_iface, 'up']), call(['ip', 'a', 'add', addr, 'dev', tagged_iface]), call(['ip', 'ro', 'change', 'default', 'via', gw, 'dev', tagged_iface]), call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'ro', 'change', 'default', 'via', default_gw, 'dev', default_iface]), call(['ip', 'a', 'del', addr, 'dev', tagged_iface]), call(['ip', 'link', 'set', 'dev', tagged_iface, 'down']), call(['ip', 'link', 'delete', tagged_iface]), call(['ip', 'link', 'set', 'dev', iface, 'down']), call(['ip', 'a']), call(['ip', 'ro'])] self.assert_by_items(mexecute.call_args_list, execute_stack)
def test_verification_vlan(self, mifaddr, mexist, mup, mgat, mexecute): mexecute.return_value = (0, '', '') mup.return_value = False mexist.return_value = False mifaddr.return_value = False default_gw, default_iface = '172.18.0.1', 'eth2' mgat.return_value = { 'default': {netifaces.AF_INET: (default_gw, default_iface)}} iface = 'eth1' addr = '10.10.0.2/24' gw = '10.10.0.1' vlan = '101' tagged_iface = '{0}.{1}'.format(iface, vlan) cmd = ['with', 'setup', '-i', iface, '-a', addr, '-g', gw, '--vlan', vlan, 'test.url'] cli.main(cmd) execute_stack = [ call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'link', 'set', 'dev', iface, 'up']), call(['ip', 'link', 'add', 'link', 'eth1', 'name', tagged_iface, 'type', 'vlan', 'id', vlan]), call(['ip', 'link', 'set', 'dev', tagged_iface, 'up']), call(['ip', 'a', 'add', addr, 'dev', tagged_iface]), call(['ip', 'ro', 'change', 'default', 'via', gw, 'dev', tagged_iface]), call(['ip', 'a']), call(['ip', 'ro']), call(['ip', 'ro', 'change', 'default', 'via', default_gw, 'dev', default_iface]), call(['ip', 'a', 'del', addr, 'dev', tagged_iface]), call(['ip', 'link', 'set', 'dev', tagged_iface, 'down']), call(['ip', 'link', 'delete', tagged_iface]), call(['ip', 'link', 'set', 'dev', iface, 'down']), call(['ip', 'a']), call(['ip', 'ro'])] self.assert_by_items(mexecute.call_args_list, execute_stack)
def test_check_urls_fail_on_requests_error(self): exit_code = cli.main(['check'] + self.urls) self.assertEqual(exit_code, 1)