Skip to content

Commit

Permalink
PR #276 - tests for --skip-service
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Jun 11, 2017
1 parent 9e55bd4 commit b66ac3a
Showing 1 changed file with 78 additions and 15 deletions.
93 changes: 78 additions & 15 deletions awslimitchecker/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def test_parse_args_parser(self):
help='perform action for only the specified '
'service name; see -s|--list-services for '
'valid names'),
call().add_argument('--skip-service', action='store', nargs='*',
default=[],
call().add_argument('--skip-service', action='append',
dest='skip_service', default=[],
help='avoid performing actions for the '
'specified service name; see '
'-s|--list-services for valid names'),
Expand Down Expand Up @@ -263,6 +263,25 @@ def test_parse_args_ta_refresh_older(self):
assert isinstance(res, argparse.Namespace)
assert res.ta_refresh_mode == 123

def test_parse_args_skip_service_none(self):
argv = []
res = self.cls.parse_args(argv)
assert res.skip_service == []

def test_parse_args_skip_service_one(self):
argv = ['--skip-service', 'foo']
res = self.cls.parse_args(argv)
assert res.skip_service == ['foo']

def test_parse_args_skip_service_multiple(self):
argv = [
'--skip-service', 'foo',
'--skip-service', 'bar',
'--skip-service=baz'
]
res = self.cls.parse_args(argv)
assert res.skip_service == ['foo', 'bar', 'baz']

def test_entry_version(self, capsys):
argv = ['awslimitchecker', '-V']
expected = 'awslimitchecker ver (see <foo> for source code)\n'
Expand Down Expand Up @@ -457,6 +476,63 @@ def test_list_limits_one_service(self, capsys):
})
]

def test_entry_skip_service_none(self):
argv = ['awslimitchecker']
with patch.object(sys, 'argv', argv):
with patch('%s.Runner.check_thresholds' % pb,
autospec=True) as mock_check:
mock_check.return_value = 2
with patch('%s.AwsLimitChecker' % pb, autospec=True) as mock_c:
with pytest.raises(SystemExit) as excinfo:
self.cls.console_entry_point()
assert excinfo.value.code == 2
assert mock_c.mock_calls == [
call(account_id=None, account_role=None, critical_threshold=99,
external_id=None, mfa_serial_number=None, mfa_token=None,
profile_name=None, region=None, ta_refresh_mode=None,
ta_refresh_timeout=None, warning_threshold=80)
]

def test_entry_skip_service(self):
argv = ['awslimitchecker', '--skip-service=foo']
with patch.object(sys, 'argv', argv):
with patch('%s.Runner.check_thresholds' % pb,
autospec=True) as mock_check:
mock_check.return_value = 2
with patch('%s.AwsLimitChecker' % pb, autospec=True) as mock_c:
with pytest.raises(SystemExit) as excinfo:
self.cls.console_entry_point()
assert excinfo.value.code == 2
assert mock_c.mock_calls == [
call(account_id=None, account_role=None, critical_threshold=99,
external_id=None, mfa_serial_number=None, mfa_token=None,
profile_name=None, region=None, ta_refresh_mode=None,
ta_refresh_timeout=None, warning_threshold=80),
call().remove_services(['foo'])
]

def test_entry_skip_service_multi(self):
argv = [
'awslimitchecker',
'--skip-service=foo',
'--skip-service', 'bar'
]
with patch.object(sys, 'argv', argv):
with patch('%s.Runner.check_thresholds' % pb,
autospec=True) as mock_check:
mock_check.return_value = 2
with patch('%s.AwsLimitChecker' % pb, autospec=True) as mock_c:
with pytest.raises(SystemExit) as excinfo:
self.cls.console_entry_point()
assert excinfo.value.code == 2
assert mock_c.mock_calls == [
call(account_id=None, account_role=None, critical_threshold=99,
external_id=None, mfa_serial_number=None, mfa_token=None,
profile_name=None, region=None, ta_refresh_mode=None,
ta_refresh_timeout=None, warning_threshold=80),
call().remove_services(['foo', 'bar'])
]

def test_entry_limit(self):
argv = ['awslimitchecker', '-L', 'foo=bar']
with patch.object(sys, 'argv', argv):
Expand Down Expand Up @@ -619,19 +695,6 @@ def test_entry_no_service_name(self, capsys):
assert excinfo.value.code == 6
assert self.cls.service_name is None

def test_entry_no_service_name_skip_service(self, capsys):
argv = ['awslimitchecker', '--skip-service', 'Firehose']
with patch.object(sys, 'argv', argv):
with patch('%s.Runner.check_thresholds' % pb,
autospec=True) as mock_ct:
with pytest.raises(SystemExit) as excinfo:
mock_ct.return_value = 6
self.cls.console_entry_point()
out, err = capsys.readouterr()
assert out == ''
assert excinfo.value.code == 6
assert self.cls.service_name is None

def test_entry_no_service_name_region(self, capsys):
argv = ['awslimitchecker', '-r', 'myregion']
with patch.object(sys, 'argv', argv):
Expand Down

0 comments on commit b66ac3a

Please sign in to comment.