commit 20870dc24ddf18d63fcff59db8e74f83a02d5e84 Author: Damian Johnson atagar@torproject.org Date: Sun Jul 6 13:34:19 2014 -0700
Interpreter unit test made remote descriptor requests
We didn't mock out stem.descriptor.remote so our unit tests issued requests to directory authorities for moria1. Tests passed because I used real mock data, but when moria1's tor version changed our unit tests naturally started breaking.
Oops. Mocking the remote module to drop these requests. --- test/unit/interpreter/commands.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/test/unit/interpreter/commands.py b/test/unit/interpreter/commands.py index 2728deb..30407ba 100644 --- a/test/unit/interpreter/commands.py +++ b/test/unit/interpreter/commands.py @@ -131,14 +131,17 @@ class TestInterpretorCommands(unittest.TestCase):
self.assertEqual(EXPECTED_EVENTS_RESPONSE, interpreter.run_command('/events'))
+ @patch('stem.descriptor.remote.DescriptorDownloader') @patch('socket.gethostbyaddr', Mock(return_value = ['moria.csail.mit.edu'])) - def test_info(self): + def test_info(self, downloader_mock): controller, server_desc, ns_desc = Mock(), Mock(), Mock()
controller.get_microdescriptor.return_value = None controller.get_server_descriptor.return_value = server_desc controller.get_network_status.return_value = ns_desc
+ downloader_mock().get_server_descriptors.return_value = [server_desc] + controller.get_info.side_effect = lambda arg, _: { 'ip-to-country/128.31.0.34': 'us', }[arg] @@ -149,9 +152,9 @@ class TestInterpretorCommands(unittest.TestCase): ns_desc.nickname = 'moria1' ns_desc.flags = ['Authority', 'Fast', 'Guard', 'HSDir', 'Named', 'Running', 'Stable', 'V2Dir', 'Valid']
- server_desc.exit_policy.summary.return_value = 'reject 1-65535' + server_desc.exit_policy = 'reject *:*' server_desc.platform = 'Linux' - server_desc.tor_version = stem.version.Version('0.2.5.3-alpha-dev') + server_desc.tor_version = stem.version.Version('0.2.5.4-alpha-dev') server_desc.contact = '1024D/28988BF5 arma mit edu'
interpreter = ControlInterpretor(controller)
tor-commits@lists.torproject.org