commit 292b7f28e210414195cd23c7f47d1d381019d934 Author: Arturo Filastò art@fuffa.org Date: Mon Sep 29 14:21:11 2014 +0200
Determine the sample config dynamically and not from self.data_directory
Call setUp also in test_nettest and test_oonicli --- ooni/settings.py | 15 +++++++++++---- ooni/tests/bases.py | 5 +---- ooni/tests/test_geoip.py | 5 ++--- ooni/tests/test_nettest.py | 1 + ooni/tests/test_oonicli.py | 1 + 5 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/ooni/settings.py b/ooni/settings.py index 130ce2e..a0fb1a8 100644 --- a/ooni/settings.py +++ b/ooni/settings.py @@ -36,13 +36,15 @@ class OConfig(object): if ooni_home: self._custom_home = ooni_home
+ self.data_directory = abspath(os.path.join(__file__, '..', '..', 'data')) + if self.global_options.get('datadir'): self.data_directory = abspath(expanduser(self.global_options['datadir'])) elif self.advanced.get('data_dir'): self.data_directory = self.advanced['data_dir'] elif hasattr(sys, 'real_prefix'): self.data_directory = os.path.abspath(os.path.join(sys.prefix, 'share', 'ooni')) - else: + elif not os.path.exists(self.data_directory): self.data_directory = '/usr/share/ooni/'
self.nettest_directory = abspath(os.path.join(__file__, '..', 'nettests')) @@ -65,6 +67,11 @@ class OConfig(object): if 'logfile' in self.basic: self.basic.logfile = expanduser(self.basic.logfile.replace('~','~'+self.current_user))
+ if not os.path.exists(self.data_directory): + log.err("Data directory %s does not exists" % self.data_directory) + log.err("Edit data_dir inside of %s" % self.config_file) + + def initialize_ooni_home(self, ooni_home=None): if ooni_home: self.set_paths(ooni_home) @@ -79,13 +86,13 @@ class OConfig(object): os.mkdir(self.reports_directory)
def _create_config_file(self): - sample_config_file = os.path.join(self.data_directory, - 'ooniprobe.conf.sample') target_config_file = self.config_file print "Creating it for you in '%s'." % target_config_file usr_share_path = '/usr/share' if hasattr(sys, 'real_prefix'): usr_share_path = os.path.abspath(os.path.join(sys.prefix, 'share')) + sample_config_file = os.path.join(usr_share_path, 'ooni', + 'ooniprobe.conf.sample')
with open(sample_config_file) as f: with open(target_config_file, 'w+') as w: @@ -111,8 +118,8 @@ class OConfig(object): if setting in dir(self) and configuration[setting] is not None: for k, v in configuration[setting].items(): getattr(self, setting)[k] = v - self.set_paths()
+ self.set_paths() if check_incoherences: self.check_incoherences(configuration)
diff --git a/ooni/tests/bases.py b/ooni/tests/bases.py index be2a1fa..5f46515 100644 --- a/ooni/tests/bases.py +++ b/ooni/tests/bases.py @@ -1,5 +1,3 @@ -import os - from twisted.trial import unittest
from ooni.settings import config @@ -7,9 +5,8 @@ from ooni.settings import config
class ConfigTestCase(unittest.TestCase): def setUp(self): - config.global_options['datadir'] = os.path.join(__file__, '..', '..', '..', 'data') - config.global_options['datadir'] = os.path.abspath(config.global_options['datadir']) config.initialize_ooni_home("ooni_home")
def tearDown(self): + config.set_paths() config.read_config_file() diff --git a/ooni/tests/test_geoip.py b/ooni/tests/test_geoip.py index da7e47f..5e8b67b 100644 --- a/ooni/tests/test_geoip.py +++ b/ooni/tests/test_geoip.py @@ -1,12 +1,11 @@
from twisted.internet import defer -from twisted.trial import unittest
-from ooni.tests import is_internet_connected +from ooni.tests import is_internet_connected, bases from ooni import geoip
-class TestGeoIP(unittest.TestCase): +class TestGeoIP(bases.ConfigTestCase): def test_ip_to_location(self): location = geoip.IPToLocation('8.8.8.8') assert 'countrycode' in location diff --git a/ooni/tests/test_nettest.py b/ooni/tests/test_nettest.py index 4f7b3e4..e93111b 100644 --- a/ooni/tests/test_nettest.py +++ b/ooni/tests/test_nettest.py @@ -329,6 +329,7 @@ class TestNettestTimeout(ConfigTestCase):
@defer.inlineCallbacks def setUp(self): + super(TestNettestTimeout, self).setUp() from twisted.internet.protocol import Protocol, Factory from twisted.internet.endpoints import TCP4ServerEndpoint
diff --git a/ooni/tests/test_oonicli.py b/ooni/tests/test_oonicli.py index ff241ea..9d93cd4 100644 --- a/ooni/tests/test_oonicli.py +++ b/ooni/tests/test_oonicli.py @@ -60,6 +60,7 @@ tor:
class TestRunDirector(ConfigTestCase): def setUp(self): + super(TestRunDirector, self).setUp() if not is_internet_connected(): self.skipTest("You must be connected to the internet to run this test") try: