def test_check_arguments_4(self, mock_log, mock_login, mock_sys, mock_arg): argparse.ArgumentParser.parse_args = MagicMock() argparse.ArgumentParser.parse_args.return_value = argparse.Namespace( check=False, diff=False, file=None, hostname=None, login=None, passwd=None, port=None, post_snapfile=None, pre_snapfile=None, snap=False, snapcheck=False, verbosity=None, version=False) js = SnapAdmin() js.args.snap = False js.args.file = os.path.join(os.path.dirname(__file__), 'configs', 'main_3.yml') js.args.check = False js.args.snapcheck = False js.args.diff = True js.args.post_snapfile = None js.args.pre_snapfile = "mock_snap" with patch('jnpr.jsnapy.jsnapy.argparse.ArgumentParser.print_help' ) as mock_parser: js.check_arguments() js.get_hosts() mock_sys.assert_called_with(1) mock_parser.assert_called_with()
def test_check_arguments_operation_lesser_parameter(self, mock_help, mock_exit): # if correct number of argument is not passed it will print help and exit js = SnapAdmin() js.args.snapcheck = True js.check_arguments() mock_help.assert_called() mock_exit.assert_called_with(1)
def test_check_arguments_test_file_3(self, mock_log, mock_login, mock_sys, mock_arg): js = SnapAdmin() js.args.snap = False js.args.file = None js.args.testfiles = [ os.path.join(os.path.dirname(__file__), 'configs', 'test_diff.yml'), os.path.join(os.path.dirname(__file__), 'configs', 'tests.yml') ] js.args.check = False js.args.snapcheck = True js.args.diff = False js.args.login = "******" js.args.hostname = "10.216.193.114" js.args.passwd = "xyz" js.args.post_snapfile = "mock_snap2" js.args.pre_snapfile = "mock_snap" with patch('argparse.ArgumentParser.print_help') as mock_parser: js.check_arguments() js.get_hosts() self.assertTrue(js.main_file) self.assertEqual(js.main_file['hosts'][0]['device'], "10.216.193.114") self.assertEqual(js.main_file['hosts'][0]['username'], "abc") self.assertEqual(js.main_file['hosts'][0]['passwd'], "xyz") self.assertEqual(js.main_file['tests'][0], js.args.testfiles[0]) self.assertEqual(js.main_file['tests'][1], js.args.testfiles[1])
def test_check_arguments_snap_operation(self, mock_help, mock_exit): # check arguments for snap operation js = SnapAdmin() js.args.snapcheck = True js.args.file = "main.yml" js.check_arguments() self.assertFalse(mock_exit.called) self.assertFalse(mock_help.called)
def test_check_arguments_wrong_operation(self, mock_help, mock_exit): # assert that if correct operation is not passed it will print help and exit js = SnapAdmin() js.args.snap = False js.args.snapcheck = False js.args.diff = False js.args.check = False js.check_arguments() mock_help.assert_called() mock_exit.assert_called_with(1)
def test_check_arguments_check_operation(self, mock_help, mock_exit): # check arguments for check operation js = SnapAdmin() js.args.check = True js.args.file = "main.yml" js.args.pre_snapfile = "pre" js.args.post_snapfile = "post" js.check_arguments() self.assertFalse(mock_exit.called) self.assertFalse(mock_help.called)
def test_check_arguments_test_file_4(self, mock_log, mock_sys, mock_get_hosts, mock_arg): js = SnapAdmin() js.args.snap = False js.args.file = None js.args.testfiles = os.path.join(os.path.dirname(__file__), 'configs', 'test_diff.yml') js.args.check = False js.args.snapcheck = False js.args.diff = True js.args.login = "******" js.args.hostname = "10.216.193.114" js.args.passwd = "xyz" js.args.post_snapfile = "mock_snap2" js.args.pre_snapfile = "mock_snap" with patch('argparse.ArgumentParser.print_help') as mock_parser: js.check_arguments() self.assertFalse(mock_get_hosts.called)
def test_check_arguments_test_file_5(self, mock_log, mock_sys, mock_get_hosts, mock_arg): js = SnapAdmin() js.args.snap = False js.args.file = None js.args.testfiles = None js.args.check = True js.args.snapcheck = False js.args.diff = False js.args.login = None js.args.hostname = "10.216.193.114" js.args.passwd = "xyz" js.args.post_snapfile = "mock_snap2" js.args.pre_snapfile = "mock_snap" with patch('argparse.ArgumentParser.print_help') as mock_parser: js.check_arguments() self.assertFalse(mock_get_hosts.called) mock_sys.assert_called_with(1) mock_parser.assert_called_with()
def test_check_arguments_3(self, mock_log, mock_login, mock_sys, mock_arg): argparse.ArgumentParser.parse_args = MagicMock() argparse.ArgumentParser.parse_args.return_value = argparse.Namespace( check=False, diff=False, file=None, hostname=None, login=None, passwd=None, port=None, post_snapfile=None, pre_snapfile=None, snap=False, snapcheck=False, verbosity=None, version=False) js = SnapAdmin() js.args.snapcheck = True with patch('argparse.ArgumentParser.print_help') as mock_parser: js.check_arguments() mock_sys.assert_called_with(1) mock_parser.assert_called_with()