Introduce BOOTTEST_FETCH configuration option for enabling/disabling TouchManifest auto-fetching feature, for faster and isolated tests.

bzr-import-20160707
Celso Providelo 10 years ago
parent 8d0cc0f292
commit 37bd9924f7

@ -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.

@ -69,3 +69,4 @@ ADT_ARCHES = amd64 i386
BOOTTEST_ARCHES = armhf
BOOTTEST_ENABLE = yes
BOOTTEST_DEBUG = yes
BOOTTEST_FETCH = yes

@ -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)

Loading…
Cancel
Save