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 2 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
3 changes: 3 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,8 @@ def test_add_meta_tag(self):
assert(soup.find("meta", attrs={"name": "google-site-verification"}) and
soup.find("meta", attrs={"name": "msvalidate.01"}))

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') == 72000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you write it as 20*60*60? It will make more sense. And update the others too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes more sense. Will do the changes

assert parse_timeout('10M') == 600
assert parse_timeout('1D') == 86400

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') == 86400 # Default 24H format is used.
18 changes: 18 additions & 0 deletions snare/tests/test_str_to_bool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for this case. True, False and Error separate.

self.v = 'true'
assert str_to_bool(self.v) is True
self.v = 'false'
assert str_to_bool(self.v) is False

with self.assertRaises(ArgumentTypeError):
str_to_bool('twz')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are using self.v for the previous two cases, do the same for this too.

2 changes: 1 addition & 1 deletion snare/utils/snare_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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