[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Add support for votes from Metrics
commit 21cfed42b859becabe71a803164004fea2372929
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
Date: Tue Aug 7 14:14:51 2012 +0530
Add support for votes from Metrics
---
stem/descriptor/__init__.py | 2 +-
test/integ/descriptor/networkstatus.py | 57 +++++++++++++++++++++----------
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 903a877..72d2275 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -96,7 +96,7 @@ def parse_file(path, descriptor_file):
# https://trac.torproject.org/6257
desc = stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor(descriptor_file.read())
- elif desc_type == "network-status-consensus-3" and major_version == 1:
+ elif desc_type in ("network-status-consensus-3", "network-status-vote-3") and major_version == 1:
desc = stem.descriptor.networkstatus_descriptor.NetworkStatusDocument(descriptor_file.read())
for desc in desc.router_descriptors:
desc._set_path(path)
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index e65d960..a634e54 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -18,25 +18,6 @@ def _strptime(string):
return datetime.datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
class TestNetworkStatusDocument(unittest.TestCase):
- def test_metrics_consensus(self):
- """
- Checks if consensus documents from Metrics are parsed properly.
- """
-
- descriptor_path = test.integ.descriptor.get_resource("metrics_consensus")
-
- with file(descriptor_path) as descriptor_file:
- desc = stem.descriptor.parse_file(descriptor_path, descriptor_file)
-
- router = next(desc)
- self.assertEquals("sumkledi", router.nickname)
- self.assertEquals("ABPSI4nNUNC3hKPkBhyzHozozrU", router.identity)
- self.assertEquals("8mCr8Sl7RF4ENU4jb0FZFA/3do8", router.digest)
- self.assertEquals(_strptime("2012-07-12 04:01:55"), router.publication)
- self.assertEquals("178.218.213.229", router.ip)
- self.assertEquals(80, router.orport)
- self.assertEquals(None, router.dirport)
-
def test_cached_consensus(self):
"""
Parses the cached-consensus file in our data directory.
@@ -66,6 +47,25 @@ class TestNetworkStatusDocument(unittest.TestCase):
assert count > 100 # sanity check - assuming atleast 100 relays in the Tor network
+ def test_metrics_consensus(self):
+ """
+ Checks if consensus documents from Metrics are parsed properly.
+ """
+
+ descriptor_path = test.integ.descriptor.get_resource("metrics_consensus")
+
+ with file(descriptor_path) as descriptor_file:
+ desc = stem.descriptor.parse_file(descriptor_path, descriptor_file)
+
+ router = next(desc)
+ self.assertEquals("sumkledi", router.nickname)
+ self.assertEquals("ABPSI4nNUNC3hKPkBhyzHozozrU", router.identity)
+ self.assertEquals("8mCr8Sl7RF4ENU4jb0FZFA/3do8", router.digest)
+ self.assertEquals(_strptime("2012-07-12 04:01:55"), router.publication)
+ self.assertEquals("178.218.213.229", router.ip)
+ self.assertEquals(80, router.orport)
+ self.assertEquals(None, router.dirport)
+
def test_consensus(self):
"""
Checks that consensus documents are properly parsed.
@@ -137,6 +137,25 @@ I/TJmV928na7RLZe2mGHCAW3VQOvV+QkCfj05VZ8CsY="""
self.assertEquals("BF112F1C6D5543CFD0A32215ACABD4197B5279AD", desc.directory_signatures[0].key_digest)
self.assertEquals(expected_signature, desc.directory_signatures[0].signature)
+ def test_metrics_vote(self):
+ """
+ Checks if vote documents from Metrics are parsed properly.
+ """
+
+ descriptor_path = test.integ.descriptor.get_resource("metrics_vote")
+
+ with file(descriptor_path) as descriptor_file:
+ desc = stem.descriptor.parse_file(descriptor_path, descriptor_file)
+
+ router = next(desc)
+ self.assertEquals("sumkledi", router.nickname)
+ self.assertEquals("ABPSI4nNUNC3hKPkBhyzHozozrU", router.identity)
+ self.assertEquals("B5n4BiALAF8B5AqafxohyYiuj7E", router.digest)
+ self.assertEquals(_strptime("2012-07-11 04:22:53"), router.publication)
+ self.assertEquals("178.218.213.229", router.ip)
+ self.assertEquals(80, router.orport)
+ self.assertEquals(None, router.dirport)
+
def test_vote(self):
"""
Checks that vote documents are properly parsed.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits