[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Add some unittests for the director.
commit 307918596d4ec8ab1bbd36c3a7860d31d8849f71
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Fri Jan 31 16:54:47 2014 +0100
Add some unittests for the director.
---
ooni/tests/test_director.py | 47 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/ooni/tests/test_director.py b/ooni/tests/test_director.py
new file mode 100644
index 0000000..c1ad524
--- /dev/null
+++ b/ooni/tests/test_director.py
@@ -0,0 +1,47 @@
+from mock import patch, MagicMock
+
+from ooni.settings import config
+from ooni.director import Director
+
+from twisted.internet import defer
+from twisted.trial import unittest
+
+class TestDirector(unittest.TestCase):
+ def test_get_net_tests(self):
+ director = Director()
+ nettests = director.getNetTests()
+ assert 'http_requests' in nettests
+ assert 'dnsconsistency' in nettests
+ assert 'http_header_field_manipulation' in nettests
+ assert 'traceroute' in nettests
+
+ def test_start_tor(self):
+ from txtorcon import TorControlProtocol
+ proto = MagicMock()
+ proto.tor_protocol = TorControlProtocol()
+
+ mock_TorState = MagicMock()
+ # We use the instance of mock_TorState so that the mock caching will
+ # return the same instance when TorState is created.
+ mts = mock_TorState()
+ mts.protocol.get_conf = lambda x: defer.succeed({'SocksPort': '4242'})
+ mts.post_bootstrap = defer.succeed(mts)
+
+ # Set the tor_protocol to be already fired
+ state = MagicMock()
+ proto.tor_protocol.post_bootstrap = defer.succeed(state)
+
+ mock_launch_tor = MagicMock()
+ mock_launch_tor.return_value = defer.succeed(proto)
+
+ @patch('ooni.director.TorState', mock_TorState)
+ @patch('ooni.director.launch_tor', mock_launch_tor)
+ @defer.inlineCallbacks
+ def director_start_tor():
+ director = Director()
+ yield director.startTor()
+ assert config.tor.socks_port == 4242
+ assert config.tor.control_port == 4242
+ config.tor_state = None
+
+ return director_start_tor()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits