Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage increased #188

Merged
merged 4 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, different input conditions for a method are tested using separate test methods, so you can have a method name like test_add_meta_tag_with_empty_tags or anything else.

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


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

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