Skip to content

Commit

Permalink
Make some comments more clear. Add two tests that make sure the modul…
Browse files Browse the repository at this point in the history
…e test case is provided with the two correctly typed attributes. Rename ModuleTestBase to ModuleTest because it is the one most programmers should interact with.
  • Loading branch information
allonhadaya committed Apr 28, 2016
1 parent f246121 commit 7bf6cd9
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions routersploit/test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
from itertools import chain
from unittest import main, TestCase, TestSuite

from routersploit.exploits import Exploit
from routersploit.interpreter import RoutersploitInterpreter


class ModuleTestBase(TestCase):
class ModuleTest(TestCase):
"""A test case that every module must pass.
Attributes:
module (module): The exploit instance of the module being tested.
module (Exploit): The exploit instance of the module being tested.
metadata (Dict): The info associated with the module.
"""

def test_has_exploit(self):
self.assertIsInstance(self.module, Exploit)

def test_has_metadata(self):
self.assertIsInstance(self.metadata, dict)

def test_legal_metadata_keys(self):

legal_keys = set([
Expand All @@ -30,25 +37,26 @@ def load_tests(loader, tests, pattern):

def tests():

# let interpreter load modules as it sees fit
# let interpreter load the modules
interpreter = RoutersploitInterpreter()

for module_path in interpreter.modules:

# use the given module
interpreter.command_use(module_path)

class ModuleTest(ModuleTestBase):
class ParametrizedModuleTest(ModuleTest):

# bind module and metadata
module = interpreter.current_module
metadata = interpreter.module_metadata

def shortDescription(self):
return 'testing %s' % getmodule(self.module).__name__
# provide the module name in the test description
return getmodule(self.module).__name__

# yield the tests from this test case
yield loader.loadTestsFromTestCase(ModuleTest)
yield loader.loadTestsFromTestCase(ParametrizedModuleTest)

suite = TestSuite()
suite.addTests(chain(*tests()))
Expand Down

0 comments on commit 7bf6cd9

Please sign in to comment.