commit 8e85d49eccf6ea2b6fa63cbadf9e049c021f6650 Author: Sambuddha Basu sambuddhabasu1@gmail.com Date: Tue Dec 16 18:02:37 2014 +0400
Added outdated_relays test --- test/unit/tutorial_examples.py | 47 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py index 9184957..9ce78a0 100644 --- a/test/unit/tutorial_examples.py +++ b/test/unit/tutorial_examples.py @@ -9,8 +9,11 @@ import stem.response
from stem.control import Controller from test import mocking -from test.mocking import get_router_status_entry_v3 -from test.mocking import ROUTER_STATUS_ENTRY_V3_HEADER +from test.mocking import ( + get_relay_server_descriptor, + get_router_status_entry_v3, + ROUTER_STATUS_ENTRY_V3_HEADER, +)
try: # added in python 3.3 @@ -53,6 +56,14 @@ Exit relay for our connection to 64.15.112.44:80
"""
+OUTDATED_RELAYS_OUTPUT = """\ +Checking for outdated relays... + + 0.1.0 Sambuddha Basu + +2 outdated relays found, 1 had contact information +""" +
def _get_event(content): controller_event = mocking.get_message(content) @@ -185,3 +196,35 @@ class TestTutorialExamples(unittest.TestCase): __builtins__['raw_input'] = origin_raw_input stream_event(controller, event) self.assertEqual(EXIT_USED_OUTPUT, stdout_mock.getvalue()) + + @patch('sys.stdout', new_callable = StringIO.StringIO) + @patch('stem.descriptor.remote.DescriptorDownloader') + def test_outdated_relays(self, downloader_mock, stdout_mock): + def tutorial_example(): + from stem.descriptor.remote import DescriptorDownloader + from stem.version import Version + + downloader = DescriptorDownloader() + count, with_contact = 0, 0 + + print "Checking for outdated relays..." + print + + for desc in downloader.get_server_descriptors(): + if desc.tor_version < Version('0.2.3.0'): + count += 1 + + if desc.contact: + print ' %-15s %s' % (desc.tor_version, desc.contact.decode("utf-8", "replace")) + with_contact += 1 + + print + print "%i outdated relays found, %i had contact information" % (count, with_contact) + + desc_1 = get_relay_server_descriptor({'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}) + desc_2 = get_relay_server_descriptor({'platform': 'node-Tor 0.1.0 on Linux x86_64'}) + desc_3 = get_relay_server_descriptor({'opt': 'contact Random Person admin@gtr-10.de', 'platform': 'node-Tor 0.2.3.0 on Linux x86_64'}) + desc_4 = get_relay_server_descriptor({'opt': 'contact Sambuddha Basu', 'platform': 'node-Tor 0.1.0 on Linux x86_64'}) + downloader_mock().get_server_descriptors.return_value = [desc_1, desc_2, desc_3, desc_4] + tutorial_example() + self.assertEqual(OUTDATED_RELAYS_OUTPUT, stdout_mock.getvalue())