-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests and Pep8 fixes (#279)
* * added more tests * coverage increased from 65% to 91% * pep8 fixes * * fixed long string to comply with pep8 * changed permissions of 2 test files * * f-strings to string concatenation for python3.5 support * max-line-length 120 fix throughout repo
- Loading branch information
1 parent
2593c86
commit 5af7675
Showing
25 changed files
with
290 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import unittest | ||
from unittest import mock | ||
import sys | ||
from snare.cloner import Cloner | ||
import shutil | ||
from yarl import URL | ||
import asyncio | ||
import aiohttp | ||
from snare.utils.asyncmock import AsyncMock | ||
|
||
|
||
class TestClonerGetRootHost(unittest.TestCase): | ||
def setUp(self): | ||
self.loop = asyncio.new_event_loop() | ||
|
||
def test_moved_root(self): | ||
self.root = 'http://example.com' | ||
self.max_depth = sys.maxsize | ||
self.css_validate = 'false' | ||
self.handler = Cloner(self.root, self.max_depth, self.css_validate) | ||
self.expected_moved_root = URL('http://www.example.com') | ||
|
||
async def test(): | ||
await self.handler.get_root_host() | ||
|
||
self.loop.run_until_complete(test()) | ||
|
||
self.assertEqual(self.handler.moved_root, self.expected_moved_root) | ||
|
||
@mock.patch('aiohttp.ClientSession') | ||
def test_clienterror(self, session): | ||
self.root = 'http://example.com' | ||
self.max_depth = sys.maxsize | ||
self.css_validate = 'false' | ||
self.handler = Cloner(self.root, self.max_depth, self.css_validate) | ||
|
||
aiohttp.ClientSession = mock.Mock(side_effect=aiohttp.ClientError) | ||
|
||
async def test(): | ||
await self.handler.get_root_host() | ||
|
||
with self.assertRaises(SystemExit): | ||
self.loop.run_until_complete(test()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
import sys | ||
from snare.cloner import Cloner | ||
import shutil | ||
|
||
|
||
class TestClonerInitialization(unittest.TestCase): | ||
def setUp(self): | ||
self.root = 'http://example.com' | ||
self.max_depth = sys.maxsize | ||
self.css_validate = 'false' | ||
self.handler = Cloner(self.root, self.max_depth, self.css_validate, default_path='/tmp') | ||
|
||
def test_cloner_init(self): | ||
self.assertIsInstance(self.handler, Cloner) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.handler.target_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import unittest | ||
import sys | ||
from snare.cloner import Cloner | ||
import shutil | ||
import asyncio | ||
|
||
|
||
class TestClonerRun(unittest.TestCase): | ||
def setUp(self): | ||
self.root = 'http://example.com' | ||
self.max_depth = sys.maxsize | ||
self.css_validate = 'false' | ||
self.handler = Cloner(self.root, self.max_depth, self.css_validate, default_path='/tmp') | ||
self.loop = asyncio.new_event_loop() | ||
|
||
def test_run(self): | ||
self.loop.run_until_complete(self.handler.run()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.