Commit 0b4784e1 by fwkz

Refactoring unit tests to utilize RoutersploitTestCase class.

parent 960f60e1
...@@ -3,8 +3,10 @@ import os ...@@ -3,8 +3,10 @@ import os
import pexpect import pexpect
from routersploit.test import RoutersploitTestCase
class RoutersploitCompleterTest(unittest.TestCase):
class RoutersploitCompleterTest(RoutersploitTestCase):
def __init__(self, methodName='runTest'): def __init__(self, methodName='runTest'):
super(RoutersploitCompleterTest, self).__init__(methodName) super(RoutersploitCompleterTest, self).__init__(methodName)
......
...@@ -8,10 +8,10 @@ except ImportError: ...@@ -8,10 +8,10 @@ except ImportError:
import mock import mock
from routersploit.interpreter import RoutersploitInterpreter from routersploit.interpreter import RoutersploitInterpreter
from routersploit.exceptions import RoutersploitException from routersploit.test import RoutersploitTestCase
class RoutersploitInterpreterTest(unittest.TestCase): class RoutersploitInterpreterTest(RoutersploitTestCase):
def setUp(self): def setUp(self):
RoutersploitInterpreter.setup = mock.Mock() RoutersploitInterpreter.setup = mock.Mock()
...@@ -39,18 +39,6 @@ class RoutersploitInterpreterTest(unittest.TestCase): ...@@ -39,18 +39,6 @@ class RoutersploitInterpreterTest(unittest.TestCase):
getattr(self.interpreter, '_{}__parse_prompt'.format(self.interpreter.__class__.__name__))() getattr(self.interpreter, '_{}__parse_prompt'.format(self.interpreter.__class__.__name__))()
def assertIsDecorated(self, function, decorator_name):
try:
decorator_list = function.__decorators__
except AttributeError:
decorator_list = []
self.assertIn(
decorator_name,
decorator_list,
msg="'{}' method should be decorated with 'module_required'".format(function.__name__)
)
@mock.patch('routersploit.utils.print_success') @mock.patch('routersploit.utils.print_success')
def test_command_set(self, mock_print_success): def test_command_set(self, mock_print_success):
rhost, new_rhost_value = 'rhost_value', "new_rhost_value" rhost, new_rhost_value = 'rhost_value', "new_rhost_value"
......
import unittest import unittest
from routersploit.utils import iter_modules from routersploit.utils import iter_modules
from routersploit.test import RoutersploitTestCase
class ModuleTest(unittest.TestCase): class ModuleTest(RoutersploitTestCase):
"""A test case that every module must pass. """A test case that every module must pass.
Attributes: Attributes:
...@@ -32,6 +33,11 @@ class ModuleTest(unittest.TestCase): ...@@ -32,6 +33,11 @@ class ModuleTest(unittest.TestCase):
) )
self.assertItemsEqual(required_metadata, self.module_metadata.keys()) self.assertItemsEqual(required_metadata, self.module_metadata.keys())
def test_metadata_type(self):
self.assertIsSequence(self.module_metadata['authors'])
self.assertIsSequence(self.module_metadata['references'])
self.assertIsSequence(self.module_metadata['devices'])
def load_tests(loader, tests, pattern): def load_tests(loader, tests, pattern):
""" Map every module to a test case, and group them into a suite. """ """ Map every module to a test case, and group them into a suite. """
......
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