mirror of
https://github.com/jtesta/ssh-audit.git
synced 2025-06-22 02:33:40 +02:00
Refactor output level/colors, fix python:S1845.
This commit is contained in:
@ -10,8 +10,8 @@ class TestAuditConf(object):
|
||||
self.AuditConf = ssh_audit.AuditConf
|
||||
self.usage = ssh_audit.usage
|
||||
|
||||
@classmethod
|
||||
def _test_conf(cls, conf, **kwargs):
|
||||
@staticmethod
|
||||
def _test_conf(conf, **kwargs):
|
||||
options = {
|
||||
'host': None,
|
||||
'port': 22,
|
||||
@ -20,7 +20,7 @@ class TestAuditConf(object):
|
||||
'batch': False,
|
||||
'colors': True,
|
||||
'verbose': False,
|
||||
'minlevel': 'info',
|
||||
'level': 'info',
|
||||
'ipv4': True,
|
||||
'ipv6': True,
|
||||
'ipvo': ()
|
||||
@ -34,7 +34,7 @@ class TestAuditConf(object):
|
||||
assert conf.batch is options['batch']
|
||||
assert conf.colors is options['colors']
|
||||
assert conf.verbose is options['verbose']
|
||||
assert conf.minlevel == options['minlevel']
|
||||
assert conf.level == options['level']
|
||||
assert conf.ipv4 == options['ipv4']
|
||||
assert conf.ipv6 == options['ipv6']
|
||||
assert conf.ipvo == options['ipvo']
|
||||
@ -115,14 +115,14 @@ class TestAuditConf(object):
|
||||
conf.ipvo = (4, 4, 4, 6, 6)
|
||||
assert conf.ipvo == (4, 6)
|
||||
|
||||
def test_audit_conf_minlevel(self):
|
||||
def test_audit_conf_level(self):
|
||||
conf = self.AuditConf()
|
||||
for level in ['info', 'warn', 'fail']:
|
||||
conf.minlevel = level
|
||||
assert conf.minlevel == level
|
||||
conf.level = level
|
||||
assert conf.level == level
|
||||
for level in ['head', 'good', 'unknown', None]:
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
conf.minlevel = level
|
||||
conf.level = level
|
||||
excinfo.match(r'.*invalid level.*')
|
||||
|
||||
def test_audit_conf_cmdline(self):
|
||||
@ -183,10 +183,10 @@ class TestAuditConf(object):
|
||||
conf = c('-v localhost')
|
||||
self._test_conf(conf, host='localhost', verbose=True)
|
||||
conf = c('-l info localhost')
|
||||
self._test_conf(conf, host='localhost', minlevel='info')
|
||||
self._test_conf(conf, host='localhost', level='info')
|
||||
conf = c('-l warn localhost')
|
||||
self._test_conf(conf, host='localhost', minlevel='warn')
|
||||
self._test_conf(conf, host='localhost', level='warn')
|
||||
conf = c('-l fail localhost')
|
||||
self._test_conf(conf, host='localhost', minlevel='fail')
|
||||
self._test_conf(conf, host='localhost', level='fail')
|
||||
with pytest.raises(SystemExit):
|
||||
conf = c('-l something localhost')
|
||||
|
@ -41,13 +41,13 @@ class TestOutput(object):
|
||||
out = self.Output()
|
||||
# default: on
|
||||
assert out.batch is False
|
||||
assert out.colors is True
|
||||
assert out.minlevel == 'info'
|
||||
assert out.use_colors is True
|
||||
assert out.level == 'info'
|
||||
|
||||
def test_output_colors(self, output_spy):
|
||||
out = self.Output()
|
||||
# test without colors
|
||||
out.colors = False
|
||||
out.use_colors = False
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
assert output_spy.flush() == [u'info color']
|
||||
@ -66,7 +66,7 @@ class TestOutput(object):
|
||||
if not out.colors_supported:
|
||||
return
|
||||
# test with colors
|
||||
out.colors = True
|
||||
out.use_colors = True
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
assert output_spy.flush() == [u'info color']
|
||||
@ -93,29 +93,29 @@ class TestOutput(object):
|
||||
|
||||
def test_output_levels(self):
|
||||
out = self.Output()
|
||||
assert out.getlevel('info') == 0
|
||||
assert out.getlevel('good') == 0
|
||||
assert out.getlevel('warn') == 1
|
||||
assert out.getlevel('fail') == 2
|
||||
assert out.getlevel('unknown') > 2
|
||||
assert out.get_level('info') == 0
|
||||
assert out.get_level('good') == 0
|
||||
assert out.get_level('warn') == 1
|
||||
assert out.get_level('fail') == 2
|
||||
assert out.get_level('unknown') > 2
|
||||
|
||||
def test_output_minlevel_property(self):
|
||||
def test_output_level_property(self):
|
||||
out = self.Output()
|
||||
out.minlevel = 'info'
|
||||
assert out.minlevel == 'info'
|
||||
out.minlevel = 'good'
|
||||
assert out.minlevel == 'info'
|
||||
out.minlevel = 'warn'
|
||||
assert out.minlevel == 'warn'
|
||||
out.minlevel = 'fail'
|
||||
assert out.minlevel == 'fail'
|
||||
out.minlevel = 'invalid level'
|
||||
assert out.minlevel == 'unknown'
|
||||
out.level = 'info'
|
||||
assert out.level == 'info'
|
||||
out.level = 'good'
|
||||
assert out.level == 'info'
|
||||
out.level = 'warn'
|
||||
assert out.level == 'warn'
|
||||
out.level = 'fail'
|
||||
assert out.level == 'fail'
|
||||
out.level = 'invalid level'
|
||||
assert out.level == 'unknown'
|
||||
|
||||
def test_output_minlevel(self, output_spy):
|
||||
def test_output_level(self, output_spy):
|
||||
out = self.Output()
|
||||
# visible: all
|
||||
out.minlevel = 'info'
|
||||
out.level = 'info'
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
@ -124,7 +124,7 @@ class TestOutput(object):
|
||||
out.fail('fail color')
|
||||
assert len(output_spy.flush()) == 5
|
||||
# visible: head, warn, fail
|
||||
out.minlevel = 'warn'
|
||||
out.level = 'warn'
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
@ -133,7 +133,7 @@ class TestOutput(object):
|
||||
out.fail('fail color')
|
||||
assert len(output_spy.flush()) == 3
|
||||
# visible: head, fail
|
||||
out.minlevel = 'fail'
|
||||
out.level = 'fail'
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
@ -142,7 +142,7 @@ class TestOutput(object):
|
||||
out.fail('fail color')
|
||||
assert len(output_spy.flush()) == 2
|
||||
# visible: head
|
||||
out.minlevel = 'invalid level'
|
||||
out.level = 'invalid level'
|
||||
output_spy.begin()
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
@ -155,7 +155,7 @@ class TestOutput(object):
|
||||
out = self.Output()
|
||||
# visible: all
|
||||
output_spy.begin()
|
||||
out.minlevel = 'info'
|
||||
out.level = 'info'
|
||||
out.batch = False
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
@ -165,7 +165,7 @@ class TestOutput(object):
|
||||
assert len(output_spy.flush()) == 5
|
||||
# visible: all except head
|
||||
output_spy.begin()
|
||||
out.minlevel = 'info'
|
||||
out.level = 'info'
|
||||
out.batch = True
|
||||
out.info('info color')
|
||||
out.head('head color')
|
||||
|
Reference in New Issue
Block a user