def test_verbose_level(self): """User passes no args, should exit with SystemExit.""" import argparse from unittest import mock from umbr_api.umbrella import main args = argparse.Namespace(command=None, verbose=1) with mock.patch('umbr_api.umbrella.create_parser') as \ mock_create_parser: mock_create_parser.return_value = args with self.assertRaises(SystemExit) as expected_exc: main() self.assertEqual(expected_exc.exception.code, 0)
def test_umbrella_main_keyring(self): """Call main.""" import argparse from umbr_api.umbrella import main args = argparse.Namespace( command='keyring', key_to_add=None, show=True, verbose=0, ) with self.assertRaises(SystemExit) as expected_exc: main(args) self.assertTrue(expected_exc.exception.code == 0 or expected_exc.exception.code == 1)
def test_get_fail(self): """User passes '--get 201', should exit with SystemExit(400).""" import argparse from unittest import mock from umbr_api.umbrella import main args = argparse.Namespace( command='get', key=None, max_records=201, verbose=2, ) with mock.patch('umbr_api.umbrella.create_parser') as \ mock_create_parser: mock_create_parser.return_value = args with self.assertRaises(SystemExit) as expected_exc: main() self.assertEqual(expected_exc.exception.code, 400)
def test_umbrella_main_get(self): """Call main.""" import argparse from unittest import mock from umbr_api.umbrella import main my_response = FakeResponse('data/templates/get/case1') args = argparse.Namespace( command='get', key=FAKE_KEY, max_records=2, verbose=2, ) with mock.patch('requests.request') as mock_requests_post: mock_requests_post.return_value = my_response with self.assertRaises(SystemExit) as expected_exc: main(args) self.assertEqual(expected_exc.exception.code, 200)
def test_get(self): """User passes '--get', should exit with SystemExit(0).""" import argparse from unittest import mock from umbr_api.umbrella import main args = argparse.Namespace( command="get", key=None, max_records=5, verbose=2, exclude=None, format="simple", ) with mock.patch( "umbr_api.umbrella.create_parser") as mock_create_parser: mock_create_parser.return_value = args with self.assertRaises(SystemExit) as expected_exc: main() self.assertEqual(expected_exc.exception.code, 200)
def test_umbrella_main_get_exclude_non_exist(self): """Test with columns filtration.""" import argparse from unittest import mock from umbr_api.umbrella import main my_response = FakeResponse("data/templates/get/case1") args = argparse.Namespace( command="get", key=FAKE_KEY, max_records=2, verbose=2, exclude="1234", format="simple", ) with mock.patch("requests.request") as mock_requests_post: mock_requests_post.return_value = my_response with self.assertRaises(SystemExit) as expected_exc: main(args) self.assertEqual(expected_exc.exception.code, 200)