Make some comments more clear. Add two tests that make sure the module test case…

Make some comments more clear. Add two tests that make sure the module test case is provided with the two correctly typed attributes. Rename ModuleTestBase to ModuleTest because it is the one most programmers should interact with.
parent f246121b
......@@ -2,17 +2,24 @@ from inspect import getmodule
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([
......@@ -30,7 +37,7 @@ 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:
......@@ -38,17 +45,18 @@ def load_tests(loader, tests, pattern):
# 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()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment