diff --git a/.gitignore b/.gitignore index 1d99689b..ffbdcaea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ *.py[cod] *$py.class +.coverage # Sphinx documentation docs/_build/ diff --git a/snare/tests/test_add_meta_tag.py b/snare/tests/test_add_meta_tag.py index df28b88a..5c3bea59 100644 --- a/snare/tests/test_add_meta_tag.py +++ b/snare/tests/test_add_meta_tag.py @@ -28,5 +28,10 @@ def test_add_meta_tag(self): assert(soup.find("meta", attrs={"name": "google-site-verification"}) and soup.find("meta", attrs={"name": "msvalidate.01"})) + def test_add_meta_tag_with_empty_tags(self): + config = configparser.ConfigParser() + config['WEB-TOOLS'] = dict(google='', bing='') + assert add_meta_tag(self.page_dir, self.index_page, config) is None + def tearDown(self): shutil.rmtree(self.main_page_path) diff --git a/snare/tests/test_parse_timeout.py b/snare/tests/test_parse_timeout.py new file mode 100644 index 00000000..b4a3de5f --- /dev/null +++ b/snare/tests/test_parse_timeout.py @@ -0,0 +1,12 @@ +import unittest +from snare.utils.snare_helpers import parse_timeout + + +class TestParseTimeout(unittest.TestCase): + + def test_parse_timeout(self): + assert parse_timeout('20H') == 20*60*60 + assert parse_timeout('10M') == 10*60 + assert parse_timeout('1D') == 24*60*60 + + assert parse_timeout('24Y') == 24*60*60 # Default 24H format is used. diff --git a/snare/tests/test_str_to_bool.py b/snare/tests/test_str_to_bool.py new file mode 100644 index 00000000..69a472e8 --- /dev/null +++ b/snare/tests/test_str_to_bool.py @@ -0,0 +1,22 @@ +import unittest +from argparse import ArgumentTypeError +from snare.utils.snare_helpers import str_to_bool + + +class TestStrToBool(unittest.TestCase): + + def setUp(self): + self.v = None + + def test_str_to_bool_true(self): + self.v = 'true' + assert str_to_bool(self.v) is True + + def test_str_to_bool_false(self): + self.v = 'false' + assert str_to_bool(self.v) is False + + def test_str_to_bool_error(self): + self.v = 'twz' + with self.assertRaises(ArgumentTypeError): + str_to_bool(self.v) diff --git a/snare/utils/snare_helpers.py b/snare/utils/snare_helpers.py index 98855847..1c0f6528 100644 --- a/snare/utils/snare_helpers.py +++ b/snare/utils/snare_helpers.py @@ -80,7 +80,6 @@ def add_meta_tag(page_dir, index_page, config): def parse_timeout(timeout): - result = None timeouts_coeff = { 'M': 60, 'H': 3600, @@ -90,7 +89,7 @@ def parse_timeout(timeout): form = timeout[-1] if form not in timeouts_coeff.keys(): print('Bad timeout format, default will be used') - parse_timeout('24H') + result = parse_timeout('24H') else: result = int(timeout[:-1]) result *= timeouts_coeff[form]