[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Move compare_flags test
commit ebdd4538f444cf8ee576d2a3969379c50179f7ca
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Sep 27 14:47:18 2020 -0700
Move compare_flags test
---
docs/_static/example/compare_flags.py | 2 +-
test/unit/examples.py | 44 +++++++++++++++++++++++++++++--
test/unit/tutorial_examples.py | 49 -----------------------------------
3 files changed, 43 insertions(+), 52 deletions(-)
diff --git a/docs/_static/example/compare_flags.py b/docs/_static/example/compare_flags.py
index 1efb1d2c..94c236e6 100644
--- a/docs/_static/example/compare_flags.py
+++ b/docs/_static/example/compare_flags.py
@@ -35,7 +35,7 @@ for vote in votes.values():
# Finally, compare moria1's votes to maatuska's votes.
-for fingerprint in all_fingerprints:
+for fingerprint in sorted(all_fingerprints):
moria1_vote = votes['moria1'].routers.get(fingerprint)
maatuska_vote = votes['maatuska'].routers.get(fingerprint)
diff --git a/test/unit/examples.py b/test/unit/examples.py
index 0fa140ab..8fca999a 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -18,8 +18,10 @@ import test.require
from stem.control import Controller
from stem.descriptor.bandwidth_file import BandwidthFile
from stem.descriptor.extrainfo_descriptor import RelayExtraInfoDescriptor
+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.exit_policy import ExitPolicy
from stem.response import ControlMessage
from unittest.mock import Mock, patch
@@ -105,6 +107,14 @@ EXPECTED_COLLECTOR_READING = """\
caerSidi (4F0C867DF0EF68160568C826838F482CEA7CFE44)
"""
+EXPECTED_COMPARE_FLAGS = """\
+moria1 has the Running flag but maatuska doesn't: 546C54E2A89D88E0794D04AECBF1AC8AC9DA81DE
+maatuska has the Running flag but moria1 doesn't: 6871F682350BA931838C0EC1E4A23044DAE06A73
+maatuska has the Running flag but moria1 doesn't: 92FCB6748A40E6088E22FBAB943AB2DD743EA818
+moria1 has the Running flag but maatuska doesn't: DCAEC3D069DC39AAE43D13C8AF31B5645E05ED61
+maatuska has the Running flag but moria1 doesn't: E2BB13AA2F6960CD93ABE5257A825687F3973C62
+"""
+
EXPECTED_EXIT_USED = """\
Tracking requests for tor exits. Press 'enter' to end.
@@ -321,8 +331,38 @@ class TestExamples(unittest.TestCase):
self.assertEqual(EXPECTED_COLLECTOR_READING, stdout_mock.getvalue())
- def test_compare_flags(self):
- pass
+ @patch('stem.directory.Authority.from_cache')
+ @patch('stem.descriptor.remote.Query')
+ @patch('sys.stdout', new_callable = io.StringIO)
+ def test_compare_flags(self, stdout_mock, query_mock, authorities_mock):
+ authorities_mock().items.return_value = [
+ ('moria1', DIRECTORY_AUTHORITIES['moria1']),
+ ('maatuska', DIRECTORY_AUTHORITIES['maatuska']),
+ ]
+
+ r_line = 'caerSidi %s oQZFLYe9e4A7bOkWKR7TaNxb0JE 2012-08-06 11:19:31 71.35.150.29 9001 0'
+
+ moria1_consensus = NetworkStatusDocumentV3.create(routers = [
+ RouterStatusEntryV3.create({'r': r_line % 'kvy2dIpA5giOIvurlDqy3XQ+qBg=', 's': ' '}),
+ RouterStatusEntryV3.create({'r': r_line % 'aHH2gjULqTGDjA7B5KIwRNrganM=', 's': ' '}),
+ RouterStatusEntryV3.create({'r': r_line % '4rsTqi9pYM2Tq+UleoJWh/OXPGI=', 's': ' '}),
+ RouterStatusEntryV3.create({'r': r_line % 'VGxU4qidiOB5TQSuy/Gsisnagd4='}),
+ RouterStatusEntryV3.create({'r': r_line % '3K7D0GncOarkPRPIrzG1ZF4F7WE='}),
+ ])
+
+ maatuska_consensus = NetworkStatusDocumentV3.create(routers = [
+ RouterStatusEntryV3.create({'r': r_line % 'kvy2dIpA5giOIvurlDqy3XQ+qBg='}),
+ RouterStatusEntryV3.create({'r': r_line % 'aHH2gjULqTGDjA7B5KIwRNrganM='}),
+ RouterStatusEntryV3.create({'r': r_line % '4rsTqi9pYM2Tq+UleoJWh/OXPGI='}),
+ RouterStatusEntryV3.create({'r': r_line % 'VGxU4qidiOB5TQSuy/Gsisnagd4=', 's': ' '}),
+ RouterStatusEntryV3.create({'r': r_line % '3K7D0GncOarkPRPIrzG1ZF4F7WE=', 's': ' '}),
+ ])
+
+ query_mock().run.side_effect = [[moria1_consensus], [maatuska_consensus]]
+
+ import compare_flags
+
+ self.assertEqual(EXPECTED_COMPARE_FLAGS, stdout_mock.getvalue())
def test_create_descriptor(self):
pass
diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py
index 0badb937..ad9a68f4 100644
--- a/test/unit/tutorial_examples.py
+++ b/test/unit/tutorial_examples.py
@@ -24,14 +24,6 @@ PURPOSE=%s'
PATH_CONTENT = '$%s=%s,$%s=%s,$%s=%s'
-COMPARE_FLAGS_OUTPUT = """\
-maatuska has the Running flag but moria1 doesn't: E2BB13AA2F6960CD93ABE5257A825687F3973C62
-moria1 has the Running flag but maatuska doesn't: 546C54E2A89D88E0794D04AECBF1AC8AC9DA81DE
-maatuska has the Running flag but moria1 doesn't: 92FCB6748A40E6088E22FBAB943AB2DD743EA818
-maatuska has the Running flag but moria1 doesn't: 6871F682350BA931838C0EC1E4A23044DAE06A73
-moria1 has the Running flag but maatuska doesn't: DCAEC3D069DC39AAE43D13C8AF31B5645E05ED61
-"""
-
VOTES_BY_BANDWIDTH_AUTHORITIES_OUTPUT = """\
Getting gabelmoo's vote from http://131.188.40.189:80/tor/status-vote/current/authority:
5935 measured entries and 1332 unmeasured
@@ -78,47 +70,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.Query')
- @patch('stem.directory.Authority.from_cache')
- def test_compare_flags(self, authorities_mock, query_mock, stdout_mock):
- authorities_mock().items.return_value = [('moria1', DIRECTORY_AUTHORITIES['moria1']), ('maatuska', DIRECTORY_AUTHORITIES['maatuska'])]
-
- fingerprint = [
- ('92FCB6748A40E6088E22FBAB943AB2DD743EA818', 'kvy2dIpA5giOIvurlDqy3XQ+qBg='),
- ('6871F682350BA931838C0EC1E4A23044DAE06A73', 'aHH2gjULqTGDjA7B5KIwRNrganM='),
- ('E2BB13AA2F6960CD93ABE5257A825687F3973C62', '4rsTqi9pYM2Tq+UleoJWh/OXPGI='),
- ('546C54E2A89D88E0794D04AECBF1AC8AC9DA81DE', 'VGxU4qidiOB5TQSuy/Gsisnagd4='),
- ('DCAEC3D069DC39AAE43D13C8AF31B5645E05ED61', '3K7D0GncOarkPRPIrzG1ZF4F7WE='),
- ]
-
- entry = [
- # entries for moria1
-
- _get_router_status(fingerprint_base64 = fingerprint[0][1], s_line = ' '),
- _get_router_status(fingerprint_base64 = fingerprint[1][1], s_line = ' '),
- _get_router_status(fingerprint_base64 = fingerprint[2][1], s_line = ' '),
- _get_router_status(fingerprint_base64 = fingerprint[3][1]),
- _get_router_status(fingerprint_base64 = fingerprint[4][1]),
-
- # entries for maatuska
-
- _get_router_status(fingerprint_base64 = fingerprint[0][1]),
- _get_router_status(fingerprint_base64 = fingerprint[1][1]),
- _get_router_status(fingerprint_base64 = fingerprint[2][1]),
- _get_router_status(fingerprint_base64 = fingerprint[3][1], s_line = ' '),
- _get_router_status(fingerprint_base64 = fingerprint[4][1], s_line = ' '),
- ]
-
- query_mock().run.side_effect = [
- [NetworkStatusDocumentV3.create(routers = (entry[0], entry[1], entry[2], entry[3], entry[4]))],
- [NetworkStatusDocumentV3.create(routers = (entry[5], entry[6], entry[7], entry[8], entry[9]))],
- ]
-
- exec_documentation_example('compare_flags.py')
-
- self.assertCountEqual(COMPARE_FLAGS_OUTPUT.splitlines(), stdout_mock.getvalue().splitlines())
-
@patch('sys.stdout', new_callable = io.StringIO)
@patch('stem.directory.Authority.from_cache')
@patch('stem.descriptor.remote.DescriptorDownloader.query')
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits