[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Use STEM_CONNECTION attributes for tests
commit 9d36a37adc5499ed0e26a4d9ce5d2d5ae443efe8
Author: Sambuddha Basu <sambuddhabasu1@xxxxxxxxx>
Date: Thu Mar 3 23:41:03 2016 +0530
Use STEM_CONNECTION attributes for tests
---
test/util/tracker/connection_tracker.py | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/test/util/tracker/connection_tracker.py b/test/util/tracker/connection_tracker.py
index 797c76b..52fed10 100644
--- a/test/util/tracker/connection_tracker.py
+++ b/test/util/tracker/connection_tracker.py
@@ -7,9 +7,11 @@ from stem.util import connection
from mock import Mock, patch
-STEM_CONNECTION_1 = connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False)
-STEM_CONNECTION_2 = connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp', False)
-STEM_CONNECTION_3 = connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp', False)
+STEM_CONNECTIONS = [
+ connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False),
+ connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp', False),
+ connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp', False)
+]
class TestConnectionTracker(unittest.TestCase):
@@ -20,7 +22,7 @@ class TestConnectionTracker(unittest.TestCase):
def test_fetching_connections(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
tor_controller_mock().get_conf.return_value = '0'
- get_value_mock.return_value = [STEM_CONNECTION_1, STEM_CONNECTION_2, STEM_CONNECTION_3]
+ get_value_mock.return_value = STEM_CONNECTIONS
with ConnectionTracker(0.04) as daemon:
time.sleep(0.01)
@@ -28,7 +30,7 @@ class TestConnectionTracker(unittest.TestCase):
connections = daemon.get_value()
self.assertEqual(1, daemon.run_counter())
- self.assertEqual(['75.119.206.243', '86.59.30.40', '74.125.28.106'], [conn.remote_address for conn in connections])
+ self.assertEqual([conn.remote_address for conn in STEM_CONNECTIONS], [conn.remote_address for conn in connections])
get_value_mock.return_value = [] # no connection results
time.sleep(0.05)
@@ -65,7 +67,7 @@ class TestConnectionTracker(unittest.TestCase):
# Now make connection resolution work. We still shouldn't provide any
# results since we stopped looking.
- get_value_mock.return_value = [STEM_CONNECTION_1, STEM_CONNECTION_2]
+ get_value_mock.return_value = STEM_CONNECTIONS[:2]
get_value_mock.side_effect = None
time.sleep(0.05)
self.assertEqual([], daemon.get_value())
@@ -75,7 +77,7 @@ class TestConnectionTracker(unittest.TestCase):
daemon.set_custom_resolver(connection.Resolver.NETSTAT)
time.sleep(0.05)
- self.assertEqual(['75.119.206.243', '86.59.30.40'], [conn.remote_address for conn in daemon.get_value()])
+ self.assertEqual([conn.remote_address for conn in STEM_CONNECTIONS[:2]], [conn.remote_address for conn in daemon.get_value()])
@patch('nyx.util.tracker.tor_controller')
@patch('nyx.util.tracker.connection.get_connections')
@@ -84,7 +86,7 @@ class TestConnectionTracker(unittest.TestCase):
def test_tracking_uptime(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
tor_controller_mock().get_conf.return_value = '0'
- get_value_mock.return_value = [STEM_CONNECTION_1]
+ get_value_mock.return_value = [STEM_CONNECTIONS[0]]
first_start_time = time.time()
with ConnectionTracker(0.04) as daemon:
@@ -93,21 +95,21 @@ class TestConnectionTracker(unittest.TestCase):
connections = daemon.get_value()
self.assertEqual(1, len(connections))
- self.assertEqual('75.119.206.243', connections[0].remote_address)
+ self.assertEqual(STEM_CONNECTIONS[0].remote_address, connections[0].remote_address)
self.assertTrue(first_start_time < connections[0].start_time < time.time())
self.assertTrue(connections[0].is_legacy)
second_start_time = time.time()
- get_value_mock.return_value = [STEM_CONNECTION_1, STEM_CONNECTION_2]
+ get_value_mock.return_value = STEM_CONNECTIONS[:2]
time.sleep(0.05)
connections = daemon.get_value()
self.assertEqual(2, len(connections))
- self.assertEqual('75.119.206.243', connections[0].remote_address)
+ self.assertEqual(STEM_CONNECTIONS[0].remote_address, connections[0].remote_address)
self.assertTrue(first_start_time < connections[0].start_time < time.time())
self.assertTrue(connections[0].is_legacy)
- self.assertEqual('86.59.30.40', connections[1].remote_address)
+ self.assertEqual(STEM_CONNECTIONS[1].remote_address, connections[1].remote_address)
self.assertTrue(second_start_time < connections[1].start_time < time.time())
self.assertFalse(connections[1].is_legacy)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits