Skip to content

Commit

Permalink
Test coverage increased (#188)
Browse files Browse the repository at this point in the history
* increased coverage

* test ArgumentTypeError

* requested changes

* minor change
  • Loading branch information
rjt-gupta authored and rnehra01 committed Mar 14, 2019
1 parent 35846cd commit c049841
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.coverage

# Sphinx documentation
docs/_build/
Expand Down
5 changes: 5 additions & 0 deletions snare/tests/test_add_meta_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions snare/tests/test_parse_timeout.py
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions snare/tests/test_str_to_bool.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions snare/utils/snare_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down

0 comments on commit c049841

Please sign in to comment.