summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-06-03 22:56:45 -0400
committerScott Moser <smoser@ubuntu.com>2016-06-03 22:56:45 -0400
commit6c0fc6df1cc332dc3d322961297f8219a3a3048b (patch)
tree53a60f7f8f74aad92846f71f47b8dd800e0e674c /tests/unittests
parentbc9bd58d1533d996029770da758f73217c15af33 (diff)
downloadvyos-cloud-init-6c0fc6df1cc332dc3d322961297f8219a3a3048b.tar.gz
vyos-cloud-init-6c0fc6df1cc332dc3d322961297f8219a3a3048b.zip
tests: fix apt tests to run inside ubuntu build environment
This just mocks out use of lsb_release as it is not available in a build environment. Additionally mocks out use of getkeybyid. This admittedly makes the test for a long key fingerprint not useful as it was broken only inside getkeybyid. Also fix 'make yaml' for cloud-config.txt
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_handler_apt_configure_sources_list.py5
-rw-r--r--tests/unittests/test_handler/test_handler_apt_source.py20
2 files changed, 18 insertions, 7 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py b/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py
index 5d0417a2..5f1dd427 100644
--- a/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py
+++ b/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py
@@ -103,8 +103,9 @@ class TestAptSourceConfigSourceList(t_help.FilesystemMockingTestCase):
with mock.patch.object(templater, 'render_to_file') as mocktmpl:
with mock.patch.object(os.path, 'isfile',
return_value=True) as mockisfile:
- cc_apt_configure.handle("notimportant", cfg, mycloud,
- LOG, None)
+ with mock.patch.object(util, 'rename'):
+ cc_apt_configure.handle("notimportant", cfg, mycloud,
+ LOG, None)
mockisfile.assert_any_call(
('/etc/cloud/templates/sources.list.%s.tmpl' % distro))
diff --git a/tests/unittests/test_handler/test_handler_apt_source.py b/tests/unittests/test_handler/test_handler_apt_source.py
index 4dbe69f0..fa28c916 100644
--- a/tests/unittests/test_handler/test_handler_apt_source.py
+++ b/tests/unittests/test_handler/test_handler_apt_source.py
@@ -43,6 +43,8 @@ class TestAptSourceConfig(TestCase):
"""TestAptSourceConfig
Main Class to test apt_source configs
"""
+ release = "fantastic"
+
def setUp(self):
super(TestAptSourceConfig, self).setUp()
self.tmp = tempfile.mkdtemp()
@@ -55,8 +57,12 @@ class TestAptSourceConfig(TestCase):
self.fallbackfn = os.path.join(self.tmp, "etc/apt/sources.list.d/",
"cloud_config_sources.list")
- @staticmethod
- def _get_default_params():
+ patcher = mock.patch("cloudinit.config.cc_apt_configure.get_release")
+ get_rel = patcher.start()
+ get_rel.return_value = self.release
+ self.addCleanup(patcher.stop)
+
+ def _get_default_params(self):
"""get_default_params
Get the most basic default mrror and release info to be used in tests
"""
@@ -438,7 +444,7 @@ class TestAptSourceConfig(TestCase):
def test_apt_src_keyid_real(self):
"""test_apt_src_keyid_real
Test specification of a keyid without source incl
- up to addition of the key (nothing but add_key_raw mocked)
+ up to addition of the key (add_key_raw, getkeybyid mocked)
"""
keyid = "03683F77"
params = self._get_default_params()
@@ -446,7 +452,9 @@ class TestAptSourceConfig(TestCase):
'filename': self.aptlistfile}
with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj:
- cc_apt_configure.add_sources([cfg], params)
+ with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi:
+ gkbi.return_value = EXPECTEDKEY
+ cc_apt_configure.add_sources([cfg], params)
mockobj.assert_called_with(EXPECTEDKEY)
@@ -464,7 +472,9 @@ class TestAptSourceConfig(TestCase):
'filename': self.aptlistfile}
with mock.patch.object(cc_apt_configure, 'add_key_raw') as mockobj:
- cc_apt_configure.add_sources([cfg], params)
+ with mock.patch.object(cc_apt_configure, 'getkeybyid') as gkbi:
+ gkbi.return_value = EXPECTEDKEY
+ cc_apt_configure.add_sources([cfg], params)
mockobj.assert_called_with(EXPECTEDKEY)