Skip to content

Commit

Permalink
tests: fixed mocked paths
Browse files Browse the repository at this point in the history
  • Loading branch information
xmendez committed May 18, 2018
1 parent 9ca821d commit c59540f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def test_payload(self):

with mock.patch('os.walk') as mocked_oswalk:
mocked_oswalk.return_value = [
('/foo', ('bar',), ('baz',)),
('/foo/bar', (), ('spam', 'eggs')),
('foo', ('bar',), ('baz',)),
('foo/bar', (), ('spam', 'eggs')),
]
payload_list = list(wfuzz.payload(**{'payloads': [('dirwalk', {'default': 'mockeddir', 'encoder': None}, None)]}))
self.assertEqual(payload_list, [('../../../../../foo/baz',), ('../../../../../foo/bar/spam',), ('../../../../../foo/bar/eggs',)])
payload_list = list(wfuzz.payload(**{'payloads': [('dirwalk', {'default': 'foo', 'encoder': None}, None)]}))
self.assertEqual(payload_list, [('baz',), ('bar/spam',), ('bar/eggs',)])

mocked_fun = "builtins.open" if sys.version_info >= (3, 0) else "__builtin__.open"
with mock.patch(mocked_fun, mock.mock_open(read_data="one\ntwo\n")):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_moduleman.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ def test_load_dir2(self):
def test_load_file(self):
with mock.patch('imp.find_module') as mocked_find_module:
with mock.patch('imp.load_module') as mocked_load_module:
mocked_find_module.return_value = (None, '/any/project.py', ('.py', 'U', 1))
mocked_find_module.return_value = (None, 'any/project.py', ('.py', 'U', 1))
mocked_load_module.return_value = sys.modules[__name__]

br = BRegistrant(FileLoader(**{"filename": 'project1.py', "base_path": 'any'}))

self.assertEqual(sorted(br.get_plugins_names()), sorted(['test_plugin1', 'test_plugin2', 'test_plugin3']))

self.assertTrue(br.get_plugin("test_plugin1").name == "test_plugin1")
self.assertTrue(br.get_plugin("../../../../../any/test_plugin2").name == "test_plugin2")
self.assertTrue(br.get_plugin("test_plugin2").name == "test_plugin2")

with self.assertRaises(Exception) as context:
br.get_plugin("any")
br.get_plugin("test_")
self.assertTrue("Multiple plugins found" in str(context.exception))

def test_simple_filter(self):
Expand Down

0 comments on commit c59540f

Please sign in to comment.