summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-23 10:48:03 +0200
committerChristian Ehrhardt <christian.ehrhardt@canonical.com>2016-05-23 10:48:03 +0200
commitcf37b78e9bada97a7cc223bd824fb0e8cd8c4c7c (patch)
tree73f6912c3d6b8bd628d48226c438f595e3a8f6dc /tests/unittests
parentf06dd57907caa648743a73566b2b6e62b96be2fb (diff)
downloadvyos-cloud-init-cf37b78e9bada97a7cc223bd824fb0e8cd8c4c7c.tar.gz
vyos-cloud-init-cf37b78e9bada97a7cc223bd824fb0e8cd8c4c7c.zip
extend test_apt_source_replace by a no-filename case
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_handler_apt_source.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_source.py b/tests/unittests/test_handler/test_handler_apt_source.py
index ce356fc6..050ee78f 100644
--- a/tests/unittests/test_handler/test_handler_apt_source.py
+++ b/tests/unittests/test_handler/test_handler_apt_source.py
@@ -59,6 +59,15 @@ class TestAptSourceConfig(TestCase):
params['MIRROR'] = "http://archive.ubuntu.com/ubuntu"
return params
+ def myjoin(self, *args, **kwargs):
+ """ myjoin - redir into writable tmpdir"""
+ if (args[0] == "/etc/apt/sources.list.d/"
+ and args[1] == "cloud_config_sources.list"
+ and len(args) == 2):
+ return self.join(self.tmp, args[0].lstrip("/"), args[1])
+ else:
+ return self.join(*args, **kwargs)
+
def apt_source_basic(self, filename, cfg):
""" apt_source_basic
Test Fix deb source string, has to overwrite mirror conf in params
@@ -99,36 +108,46 @@ class TestAptSourceConfig(TestCase):
filename = os.path.join(self.tmp, "etc/apt/sources.list.d/",
"cloud_config_sources.list")
- def myjoin(*args, **kwargs):
- """ myjoin - redir into writable tmpdir"""
- if (args[0] == "/etc/apt/sources.list.d/"
- and args[1] == "cloud_config_sources.list"
- and len(args) == 2):
- return self.join(self.tmp, args[0].lstrip("/"), args[1])
- else:
- return self.join(*args, **kwargs)
-
- with mock.patch.object(os.path, 'join', side_effect=myjoin):
+ with mock.patch.object(os.path, 'join', side_effect=self.myjoin):
self.apt_source_basic(filename, cfg)
- def test_apt_source_replacement(self):
- """ test_apt_source_replace
+ def apt_source_replacement(self, filename, cfg):
+ """ apt_source_replace
Test Autoreplacement of MIRROR and RELEASE in source specs
"""
params = self._get_default_params()
- cfg = {'source': 'deb $MIRROR $RELEASE multiverse',
- 'filename': self.aptlistfile}
-
cc_apt_configure.add_sources([cfg], params)
- self.assertTrue(os.path.isfile(self.aptlistfile))
+ self.assertTrue(os.path.isfile(filename))
- contents = load_tfile_or_url(self.aptlistfile)
+ contents = load_tfile_or_url(filename)
self.assertTrue(re.search(r"%s %s %s %s\n" %
("deb", params['MIRROR'], params['RELEASE'],
"multiverse"),
contents, flags=re.IGNORECASE))
+ def test_apt_source_replace(self):
+ """ test_apt_source_replace
+ Test Autoreplacement of MIRROR and RELEASE in source specs with
+ Filename being set
+ """
+ cfg = {'source': 'deb $MIRROR $RELEASE multiverse',
+ 'filename': self.aptlistfile}
+ self.apt_source_replacement(self.aptlistfile, cfg)
+
+ def test_apt_source_replace_nofn(self):
+ """ test_apt_source_replace_nofn
+ Test Autoreplacement of MIRROR and RELEASE in source specs with
+ No filename being set
+ """
+ cfg = {'source': 'deb $MIRROR $RELEASE multiverse'}
+ # mock into writable tmp dir and check path/content there
+ filename = os.path.join(self.tmp, "etc/apt/sources.list.d/",
+ "cloud_config_sources.list")
+
+ with mock.patch.object(os.path, 'join', side_effect=self.myjoin):
+ self.apt_source_replacement(filename, cfg)
+
def test_apt_source_keyid(self):
""" test_apt_source_keyid
Test specification of a source + keyid