[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Fix unittests for director, reporter and oonicli



commit 539c491e304a89ef2e57cb49aeeadbddab8d8baa
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Fri Aug 5 17:45:47 2016 +0200

    Fix unittests for director, reporter and oonicli
---
 ooni/director.py            |  1 -
 ooni/templates/httpt.py     |  4 ++--
 ooni/tests/bases.py         |  1 +
 ooni/tests/test_director.py |  5 +++--
 ooni/tests/test_oonicli.py  | 10 +++++++---
 ooni/tests/test_reporter.py |  4 +++-
 6 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
index 304a14a..ab31bf5 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -373,7 +373,6 @@ class Director(object):
         Launches a Tor with :param: socks_port :param: control_port
         :param: tor_binary set in ooniprobe.conf
         """
-        from txtorcon import TorConfig
         if self._tor_state == 'running':
             log.debug("Tor is already running")
             defer.returnValue(self._tor_state)
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index cba8702..d1aa1dc 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -110,8 +110,8 @@ class HTTPTest(NetTestCase):
                 self.agent = FixedRedirectAgent(self.agent)
                 self.report['agent'] = 'redirect'
             except:
-                log.err("Warning! You are running an old version of twisted"\
-                        "(<= 10.1). I will not be able to follow redirects."\
+                log.err("Warning! You are running an old version of twisted "
+                        "(<= 10.1). I will not be able to follow redirects."
                         "This may make the testing less precise.")
 
         if len(self.contentDecoders) > 0:
diff --git a/ooni/tests/bases.py b/ooni/tests/bases.py
index 40e3b5e..5a7da5f 100644
--- a/ooni/tests/bases.py
+++ b/ooni/tests/bases.py
@@ -11,6 +11,7 @@ class ConfigTestCase(unittest.TestCase):
         self.ooni_home_dir = os.path.abspath("ooni_home")
         self.config = config
         self.config.initialize_ooni_home(self.ooni_home_dir)
+        config.is_initialized = lambda: True
         super(ConfigTestCase, self).setUp()
 
     def skipTest(self, reason):
diff --git a/ooni/tests/test_director.py b/ooni/tests/test_director.py
index 6638adb..e5ca084 100644
--- a/ooni/tests/test_director.py
+++ b/ooni/tests/test_director.py
@@ -72,10 +72,11 @@ class TestDirector(ConfigTestCase):
     def test_start_tor(self):
         @defer.inlineCallbacks
         def director_start_tor():
+            self.config.advanced.start_tor = True
             director = Director()
             yield director.start_tor()
-            assert config.tor.socks_port == 4242
-            assert config.tor.control_port == 4242
+            self.assertEqual(config.tor.socks_port, 4242)
+            self.assertEqual(config.tor.control_port, 4242)
 
         return director_start_tor()
 
diff --git a/ooni/tests/test_oonicli.py b/ooni/tests/test_oonicli.py
index 06a21ff..8ad8a36 100644
--- a/ooni/tests/test_oonicli.py
+++ b/ooni/tests/test_oonicli.py
@@ -66,8 +66,6 @@ class TestRunDirector(ConfigTestCase):
         if not is_internet_connected():
             self.skipTest("You must be connected to the internet to run this test")
 
-        config.tor.socks_port = 9050
-        config.tor.control_port = None
         self.filenames = ['example-input.txt']
         with open('example-input.txt', 'w+') as f:
             f.write('http://torproject.org/\n')
@@ -83,7 +81,7 @@ class TestRunDirector(ConfigTestCase):
 
     @defer.inlineCallbacks
     def run_helper(self, test_name, nettest_args, verify_function, ooni_args=()):
-        output_file = os.path.abspath('test_report.yamloo')
+        output_file = os.path.abspath('test_report.njson')
         self.filenames.append(output_file)
         oldargv = sys.argv
         sys.argv = ['']
@@ -91,6 +89,12 @@ class TestRunDirector(ConfigTestCase):
         sys.argv.extend(['-n', '-o', output_file, test_name])
         sys.argv.extend(nettest_args)
         global_options = setupGlobalOptions(False, False, False)
+
+        config.tor.socks_port = 9050
+        config.advanced.start_tor = False
+        config.tor.control_port = None
+        config.advanced.debug = True
+
         yield runWithDirector(global_options,
                               create_input_store=False)
         with open(output_file) as f:
diff --git a/ooni/tests/test_reporter.py b/ooni/tests/test_reporter.py
index cbfdaeb..f7a917d 100644
--- a/ooni/tests/test_reporter.py
+++ b/ooni/tests/test_reporter.py
@@ -3,6 +3,7 @@ import yaml
 import json
 import time
 import shutil
+import tempfile
 
 from twisted.internet import defer
 from twisted.trial import unittest
@@ -119,8 +120,8 @@ class TestOONIBReportLog(ConfigTestCase):
 
     def setUp(self):
         super(TestOONIBReportLog, self).setUp()
-        self.report_log = OONIBReportLog()
         self.measurement_id = '20160727T182604Z-ZZ-AS0-dummy'
+        self.config.measurements_directory = tempfile.mkdtemp()
         self.measurement_dir = os.path.join(
             self.config.measurements_directory,
             self.measurement_id
@@ -128,6 +129,7 @@ class TestOONIBReportLog(ConfigTestCase):
         self.report_log_path = os.path.join(self.measurement_dir,
                                             'report_log.json')
         os.mkdir(self.measurement_dir)
+        self.report_log = OONIBReportLog()
 
     def tearDown(self):
         shutil.rmtree(self.measurement_dir)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits