commit 9d328a42919f96bb43ac73ddf6e86736174d7d77 Author: Damian Johnson atagar@torproject.org Date: Sun Sep 27 14:13:29 2020 -0700
Move outdated_relays test --- test/unit/examples.py | 23 +++++++++++++++++++++-- test/unit/tutorial_examples.py | 23 ----------------------- 2 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/test/unit/examples.py b/test/unit/examples.py index efdac292..0fa140ab 100644 --- a/test/unit/examples.py +++ b/test/unit/examples.py @@ -134,6 +134,14 @@ Circuit 10 (GENERAL) +- 65242C91BFF30F165DA4D132C81A9EBA94B71D62 (torexit16, 176.67.169.171) """
+EXPECTED_OUTDATED_RELAYS = """\ +Checking for outdated relays... + + 0.1.0 Sambuddha Basu + +2 outdated relays found, 1 had contact information +""" +
def _make_circ_event(circ_id, hop1, hop2, hop3): path = '$%s=%s,$%s=%s,$%s=%s' % (hop1[0], hop1[1], hop2[0], hop2[1], hop3[0], hop3[1]) @@ -423,8 +431,19 @@ class TestExamples(unittest.TestCase): def test_manual_config_options(self): pass
- def test_outdated_relays(self): - pass + @patch('stem.descriptor.remote.DescriptorDownloader') + @patch('sys.stdout', new_callable = io.StringIO) + def test_outdated_relays(self, stdout_mock, downloader_mock): + downloader_mock().get_server_descriptors.return_value = [ + RelayDescriptor.create({'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}), + RelayDescriptor.create({'platform': 'node-Tor 0.1.0 on Linux x86_64'}), + RelayDescriptor.create({'opt': 'contact Random Person admin@gtr-10.de', 'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}), + RelayDescriptor.create({'opt': 'contact Sambuddha Basu', 'platform': 'node-Tor 0.1.0 on Linux x86_64'}), + ] + + import outdated_relays + + self.assertEqual(EXPECTED_OUTDATED_RELAYS, stdout_mock.getvalue())
def test_persisting_a_consensus(self): pass diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py index 4df9f6c4..0badb937 100644 --- a/test/unit/tutorial_examples.py +++ b/test/unit/tutorial_examples.py @@ -11,7 +11,6 @@ from unittest.mock import Mock, patch
from stem.descriptor.networkstatus import NetworkStatusDocumentV3 from stem.descriptor.router_status_entry import RouterStatusEntryV3 -from stem.descriptor.server_descriptor import RelayDescriptor from stem.directory import DIRECTORY_AUTHORITIES from stem.response import ControlMessage
@@ -25,14 +24,6 @@ PURPOSE=%s'
PATH_CONTENT = '$%s=%s,$%s=%s,$%s=%s'
-OUTDATED_RELAYS_OUTPUT = """\ -Checking for outdated relays... - - 0.1.0 Sambuddha Basu - -2 outdated relays found, 1 had contact information -""" - COMPARE_FLAGS_OUTPUT = """\ maatuska has the Running flag but moria1 doesn't: E2BB13AA2F6960CD93ABE5257A825687F3973C62 moria1 has the Running flag but maatuska doesn't: 546C54E2A89D88E0794D04AECBF1AC8AC9DA81DE @@ -87,20 +78,6 @@ def _get_router_status(address = None, port = None, nickname = None, fingerprint
class TestTutorialExamples(unittest.TestCase): - @patch('sys.stdout', new_callable = io.StringIO) - @patch('stem.descriptor.remote.DescriptorDownloader') - def test_outdated_relays(self, downloader_mock, stdout_mock): - downloader_mock().get_server_descriptors.return_value = [ - RelayDescriptor.create({'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}), - RelayDescriptor.create({'platform': 'node-Tor 0.1.0 on Linux x86_64'}), - RelayDescriptor.create({'opt': 'contact Random Person admin@gtr-10.de', 'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}), - RelayDescriptor.create({'opt': 'contact Sambuddha Basu', 'platform': 'node-Tor 0.1.0 on Linux x86_64'}), - ] - - exec_documentation_example('outdated_relays.py') - - self.assertCountEqual(OUTDATED_RELAYS_OUTPUT.splitlines(), stdout_mock.getvalue().splitlines()) - @patch('sys.stdout', new_callable = io.StringIO) @patch('stem.descriptor.remote.Query') @patch('stem.directory.Authority.from_cache')
tor-commits@lists.torproject.org