Skip to content

Commit

Permalink
test ArgumentTypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
rjt-gupta committed Mar 13, 2019
1 parent a51448f commit 3a333cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion snare/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, root, max_depth, css_validate):
self.max_depth = max_depth
self.moved_root = None
if len(self.root.host) < 4:
sys.exit('invalid target {}'.format(self.root.host))
sys.exit('invalid taget {}'.format(self.root.host))
self.target_path = '/opt/snare/pages/{}'.format(self.root.host)

if not os.path.exists(self.target_path):
Expand Down
13 changes: 1 addition & 12 deletions snare/tests/test_parse_timeout.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import unittest
from snare.utils.snare_helpers import parse_timeout, str_to_bool
from snare.utils.snare_helpers import parse_timeout


class TestParseTimeout(unittest.TestCase):

def setUp(self):
self.v = None

def test_parse_timeout(self):

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

assert parse_timeout('24Y') == 86400 # Default 24H format is used.

def test_str_to_bool(self):

self.v = 'true'
assert str_to_bool(self.v) is True
self.v = 'false'
assert str_to_bool(self.v) is False
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):
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')
4 changes: 2 additions & 2 deletions snare/utils/snare_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def add_meta_tag(page_dir, index_page, config):
main_page = main.read()
soup = BeautifulSoup(main_page, 'html.parser')

if google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None:
if (google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None):
google_meta = soup.new_tag('meta')
google_meta.attrs['name'] = 'google-site-verification'
google_meta.attrs['content'] = google_content
soup.head.append(google_meta)
if bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None:
if (bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None):
bing_meta = soup.new_tag('meta')
bing_meta.attrs['name'] = 'msvalidate.01'
bing_meta.attrs['content'] = bing_content
Expand Down

0 comments on commit 3a333cd

Please sign in to comment.