From 37bd9924f7a786ad25cc3c0d0b2d181b011c5de7 Mon Sep 17 00:00:00 2001 From: Celso Providelo Date: Mon, 2 Feb 2015 13:10:53 -0500 Subject: [PATCH] Introduce BOOTTEST_FETCH configuration option for enabling/disabling TouchManifest auto-fetching feature, for faster and isolated tests. --- boottest.py | 10 +++++++--- britney.conf | 1 + tests/test_boottest.py | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/boottest.py b/boottest.py index 63e2eb6..eb900b7 100644 --- a/boottest.py +++ b/boottest.py @@ -50,11 +50,12 @@ class TouchManifest(object): with open(self.path, 'w') as fp: fp.write(response.read()) - def __init__(self, distribution, series): + def __init__(self, distribution, series, fetch=True): self.path = "boottest/images/{}/{}/manifest".format( distribution, series) - self.__fetch_manifest(distribution, series) + if fetch: + self.__fetch_manifest(distribution, series) self._manifest = self._load() @@ -102,7 +103,10 @@ class BootTest(object): self.distribution = distribution self.series = series self.debug = debug - self.phone_manifest = TouchManifest(self.distribution, self.series) + manifest_fetch = getattr( + self.britney.options, "boottest_fetch", "no") == "yes" + self.phone_manifest = TouchManifest( + self.distribution, self.series, fetch=manifest_fetch) def _get_status(self, name, version): """Return the current boottest status. diff --git a/britney.conf b/britney.conf index 1a96afe..940e796 100644 --- a/britney.conf +++ b/britney.conf @@ -69,3 +69,4 @@ ADT_ARCHES = amd64 i386 BOOTTEST_ARCHES = armhf BOOTTEST_ENABLE = yes BOOTTEST_DEBUG = yes +BOOTTEST_FETCH = yes diff --git a/tests/test_boottest.py b/tests/test_boottest.py index cb4f370..0442f3c 100644 --- a/tests/test_boottest.py +++ b/tests/test_boottest.py @@ -6,6 +6,7 @@ # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. +import mock import os import shutil import sys @@ -30,6 +31,16 @@ def create_manifest(manifest_dir, lines): fd.write('\n'.join(lines)) +class FakeResponse(object): + + def __init__(self, code=404, content=''): + self.code = code + self.content = content + + def read(self): + return self.content + + class TestTouchManifest(unittest.TestCase): def setUp(self): @@ -39,6 +50,10 @@ class TestTouchManifest(unittest.TestCase): self.imagesdir = os.path.join(self.path, 'boottest/images') os.makedirs(self.imagesdir) self.addCleanup(shutil.rmtree, self.path) + _p = mock.patch('urllib.urlopen') + self.mocked_urlopen = _p.start() + self.mocked_urlopen.side_effect = [FakeResponse(code=404),] + self.addCleanup(_p.stop) def test_missing(self): # Missing manifest file silently results in empty contents. @@ -48,9 +63,18 @@ class TestTouchManifest(unittest.TestCase): def test_fetch(self): # Missing manifest file is fetched dynamically + self.mocked_urlopen.side_effect = [ + FakeResponse(code=200, content='foo 1.0'), + ] manifest = TouchManifest('ubuntu-touch', 'vivid') self.assertNotEqual([], manifest._manifest) + def test_fetch_disabled(self): + # Manifest auto-fetching can be disabled. + manifest = TouchManifest('ubuntu-touch', 'vivid', fetch=False) + self.mocked_urlopen.assert_not_called() + self.assertEqual([], manifest._manifest) + def test_fetch_fails(self): distribution = 'fake' series = 'fake' @@ -98,6 +122,9 @@ class TestBoottestEnd2End(TestBase): self.old_config = fp.read() config = self.old_config.replace( 'ADT_ENABLE = yes', 'ADT_ENABLE = no') + # Disable TouchManifest auto-fetching. + config = config.replace( + 'BOOTTEST_FETCH = yes', 'BOOTTEST_FETCH = no') with open(self.britney_conf, 'w') as fp: fp.write(config)