[tor-commits] [bridgedb/develop] Add two unittests for parsing networkstatus files with headers.

isis at torproject.org isis at torproject.org
Thu Feb 19 02:21:12 UTC 2015


commit 8b7649bb60b5e4902f74074060679622cd445884
Author: Isis Lovecruft <isis at torproject.org>
Date:   Fri Dec 5 09:23:49 2014 +0000

    Add two unittests for parsing networkstatus files with headers.
---
 lib/bridgedb/test/test_parse_descriptors.py |   38 +++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/bridgedb/test/test_parse_descriptors.py b/lib/bridgedb/test/test_parse_descriptors.py
index 6479168..4c10874 100644
--- a/lib/bridgedb/test/test_parse_descriptors.py
+++ b/lib/bridgedb/test/test_parse_descriptors.py
@@ -232,6 +232,44 @@ class ParseDescriptorsTests(unittest.TestCase):
         self.assertEqual(bridge.fingerprint,
                          u'6FA9216CF3A06E89A03121ACC31F70F8DFD7DDCC')
 
+    def test_parse_descriptors_parseBridgeNetworkStatusFile_with_annotations(self):
+        """Test ``b.p.descriptors.parseNetworkStatusFile`` with some document
+        headers before the first 'r'-line.
+        """
+        expectedIPs = [self.expectedIPBridge0, self.expectedIPBridge1]
+        descFile = 'networkstatus-bridges'
+
+        with open(descFile, 'w') as fh:
+            fh.write('signature and stuff from the BridgeAuth would go here\n')
+            fh.write('some more annotations with parameters and stuff\n')
+            fh.write(BRIDGE_NETWORKSTATUS_0)
+            fh.write(BRIDGE_NETWORKSTATUS_1)
+            fh.flush()
+
+        routers = descriptors.parseNetworkStatusFile(descFile)
+        bridge = routers[0]
+        self.assertIn(bridge.address, expectedIPs)
+        self.assertEqual(bridge.fingerprint, self.expectedFprBridge0)
+
+    def test_parse_descriptors_parseBridgeNetworkStatusFile_with_annotations_no_skipping(self):
+        """Test ``b.p.descriptors.parseNetworkStatusFile`` with some
+        document headers before the first 'r'-line, but without skipping said
+        annotations.
+        """
+        expectedIPs = [self.expectedIPBridge0, self.expectedIPBridge1]
+        descFile = 'networkstatus-bridges'
+
+        with open(descFile, 'w') as fh:
+            fh.write('signature and stuff from the BridgeAuth would go here\n')
+            fh.write('some more annotations with parameters and stuff\n')
+            fh.write(BRIDGE_NETWORKSTATUS_0)
+            fh.write(BRIDGE_NETWORKSTATUS_1)
+            fh.flush()
+
+        self.assertRaises(ValueError,
+                          descriptors.parseNetworkStatusFile,
+                          descFile, skipAnnotations=False)
+
     def test_parse_descriptors_parseBridgeExtraInfoFiles_return_type(self):
         """The return type of ``b.p.descriptors.parseBridgeExtraInfoFiles``
         should be a dictionary (after deduplication).





More information about the tor-commits mailing list