diff options
author | Christian Ehrhardt <christian.ehrhardt@canonical.com> | 2016-05-11 10:57:14 +0200 |
---|---|---|
committer | Christian Ehrhardt <christian.ehrhardt@canonical.com> | 2016-05-11 10:57:14 +0200 |
commit | 4c5d1966ead445dc6d110e9677902b95dfef2dc5 (patch) | |
tree | afa619dae6f287b2e9e92a9ccccfab6356bbfd48 /tests/unittests | |
parent | 86c59ffa50a74a1d0001c5ef6ccc78bd6f656fdc (diff) | |
download | vyos-cloud-init-4c5d1966ead445dc6d110e9677902b95dfef2dc5.tar.gz vyos-cloud-init-4c5d1966ead445dc6d110e9677902b95dfef2dc5.zip |
test test_apt_source_key with mocked util.subp
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_handler/test_handler_apt_source.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_source.py b/tests/unittests/test_handler/test_handler_apt_source.py index a4d359a5..29535bee 100644 --- a/tests/unittests/test_handler/test_handler_apt_source.py +++ b/tests/unittests/test_handler/test_handler_apt_source.py @@ -6,6 +6,11 @@ import shutil import tempfile import re +try: + from unittest import mock +except ImportError: + import mock + from cloudinit import distros from cloudinit import util from cloudinit.config import cc_apt_configure @@ -116,11 +121,13 @@ class TestAptSourceConfig(TestCase): 'keyid:': "03683F77", 'filename': self.aptlistfile} - cc_apt_configure.add_sources([cfg], params) + with mock.patch.object(util, 'subp', return_value=('fakekey 1234', '')) as mockobj: + cc_apt_configure.add_sources([cfg], params) + + mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 1234') self.assertTrue(os.path.isfile(self.aptlistfile)) - # report content before making regex contents = load_tfile_or_url(self.aptlistfile) self.assertTrue(re.search(r"%s %s %s %s\n" % ("deb", @@ -128,11 +135,6 @@ class TestAptSourceConfig(TestCase): 'cloud-init-test/ubuntu'), "xenial", "main"), contents, flags=re.IGNORECASE)) - # check if key was imported - try: - util.subp(('apt-key', 'list', '03683F77')) - except util.ProcessExecutionError as err: - self.assertRaises(err, "apt-key failed failed") def test_apt_source_ppa(self): |