commit c2ffe4f6785d846a083ffc347f13759e5d748c96 Author: Isis Lovecruft isis@torproject.org Date: Wed Nov 1 23:51:39 2017 +0000
Fix bridgedb.main erroring unittests due to multi-bridgeauth code. --- bridgedb/main.py | 7 +++++- bridgedb/test/test_main.py | 53 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/bridgedb/main.py b/bridgedb/main.py index f6d16ec..cb3eee1 100644 --- a/bridgedb/main.py +++ b/bridgedb/main.py @@ -46,7 +46,12 @@ def expandBridgeAuthDir(authdir, filename): """Expands a descriptor ``filename`` relative to which of the BRIDGE_AUTHORITY_DIRECTORIES, ``authdir`` it resides within. """ - return os.path.abspath(os.path.expanduser(os.sep.join([authdir, filename]))) + path = filename + + if not authdir in filename or not os.path.isabs(filename): + path = os.path.abspath(os.path.expanduser(os.sep.join([authdir, filename]))) + + return path
def load(state, hashring, clear=False): """Read and parse all descriptors, and load into a bridge hashring. diff --git a/bridgedb/test/test_main.py b/bridgedb/test/test_main.py index fddb8a9..a2e975e 100644 --- a/bridgedb/test/test_main.py +++ b/bridgedb/test/test_main.py @@ -81,9 +81,12 @@ class BridgedbTests(unittest.TestCase): fh.flush() fh.close()
- def _copyDescFilesHere(self, files): + def _copyDescFilesHere(self, authdirs, files): """Copy all the **files** to the _trial_tmp/ directory.
+ :param list authdirs: A list of strings representing the directories + from BridgeAuthorities, as in the BRIDGE_AUTHORITY_DIRECTORIES + config option. :param list files: A list of strings representing the paths to descriptor files. This should probably be taken from a ``bridgedb.persistent.Conf`` object which has parsed the @@ -95,18 +98,23 @@ class BridgedbTests(unittest.TestCase): """ updatedPaths = []
- for f in files: - base = os.path.basename(f) - src = os.path.join(CI_RUNDIR, base) - if os.path.isfile(src): - dst = os.path.join(HERE, base) - shutil.copy(src, dst) - updatedPaths.append(dst) - else: - self.skip = True - raise unittest.SkipTest( - "Can't find mock descriptor files in %s directory" % - CI_RUNDIR) + for d in authdirs: + for f in files: + base = os.path.basename(f) + src = os.path.join(CI_RUNDIR, d, base) + if os.path.isfile(src): + dstdir = os.path.join(HERE, d) + if not os.path.isdir(dstdir): + os.mkdir(dstdir) + self._directories_created.append(dstdir) + dst = os.path.join(dstdir, base) + shutil.copy(src, dst) + updatedPaths.append(dst) + else: + self.skip = True + raise unittest.SkipTest( + "Can't find mock descriptor files in %s directory" % + CI_RUNDIR)
return updatedPaths
@@ -157,14 +165,24 @@ class BridgedbTests(unittest.TestCase): directory, produce a state object from the loaded bridgedb.conf file, and make an HMAC key. """ + # We'll want to nuke these after the test runs + self._directories_created = [] + # Get the bridgedb.conf file in the top-level directory of this repo: self.configFile = os.path.join(TOPDIR, 'bridgedb.conf') self.config = main.loadConfig(self.configFile) + self.config.BRIDGE_AUTHORITY_DIRECTORIES = ["from-bifroest"]
# Copy the referenced descriptor files from bridgedb/run/ to CWD: - self.config.STATUS_FILE = self._copyDescFilesHere([self.config.STATUS_FILE])[0] - self.config.BRIDGE_FILES = self._copyDescFilesHere(self.config.BRIDGE_FILES) - self.config.EXTRA_INFO_FILES = self._copyDescFilesHere(self.config.EXTRA_INFO_FILES) + self.config.STATUS_FILE = self._copyDescFilesHere( + self.config.BRIDGE_AUTHORITY_DIRECTORIES, + [self.config.STATUS_FILE])[0] + self.config.BRIDGE_FILES = self._copyDescFilesHere( + self.config.BRIDGE_AUTHORITY_DIRECTORIES, + self.config.BRIDGE_FILES) + self.config.EXTRA_INFO_FILES = self._copyDescFilesHere( + self.config.BRIDGE_AUTHORITY_DIRECTORIES, + self.config.EXTRA_INFO_FILES)
# Initialise the state self.state = main.persistent.State(**self.config.__dict__) @@ -185,6 +203,9 @@ class BridgedbTests(unittest.TestCase): main.updateBridgeHistory = self._orig_updateBridgeHistory sys.argv = self._orig_sys_argv
+ for d in self._directories_created: + shutil.rmtree(d) + def test_main_updateBridgeHistory(self): """main.updateBridgeHistory should update some timestamps for some bridges.
tor-commits@lists.torproject.org