diff options
-rw-r--r-- | tests/unittests/test_handler/test_handler_puppet.py | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/tests/unittests/test_handler/test_handler_puppet.py b/tests/unittests/test_handler/test_handler_puppet.py index c0ba2e3c..b7891ab4 100644 --- a/tests/unittests/test_handler/test_handler_puppet.py +++ b/tests/unittests/test_handler/test_handler_puppet.py @@ -5,7 +5,6 @@ from cloudinit.sources import DataSourceNone from cloudinit import (distros, helpers, cloud, util) from cloudinit.tests.helpers import CiTestCase, HttprettyTestCase, mock -import httpretty import logging import textwrap @@ -309,62 +308,45 @@ class TestPuppetHandle(CiTestCase): m_subp.call_args_list) -class TestInstallPuppetAio(HttprettyTestCase): +URL_MOCK = mock.Mock() +URL_MOCK.contents = b'#!/bin/bash\necho "Hi Mom"' - @mock.patch('cloudinit.config.cc_puppet.subp.subp', - return_value=(None, None)) - def test_install_with_default_arguments(self, m_subp): - """Install AIO with no arguments""" - response = b'#!/bin/bash\necho "Hi Mom"' - httpretty.register_uri( - httpretty.GET, cc_puppet.AIO_INSTALL_URL, - body=response, status=200) +@mock.patch('cloudinit.config.cc_puppet.subp.subp', return_value=(None, None)) +@mock.patch( + 'cloudinit.config.cc_puppet.url_helper.readurl', + return_value=URL_MOCK, autospec=True, +) +class TestInstallPuppetAio(HttprettyTestCase): + def test_install_with_default_arguments(self, m_readurl, m_subp): + """Install AIO with no arguments""" cc_puppet.install_puppet_aio() self.assertEqual( [mock.call([mock.ANY, '--cleanup'], capture=False)], m_subp.call_args_list) - @mock.patch('cloudinit.config.cc_puppet.subp.subp', - return_value=(None, None)) - def test_install_with_custom_url(self, m_subp): + def test_install_with_custom_url(self, m_readurl, m_subp): """Install AIO from custom URL""" - response = b'#!/bin/bash\necho "Hi Mom"' - url = 'http://custom.url/path/to/script.sh' - httpretty.register_uri( - httpretty.GET, url, body=response, status=200) - cc_puppet.install_puppet_aio('http://custom.url/path/to/script.sh') + m_readurl.assert_called_with( + url='http://custom.url/path/to/script.sh', + retries=5) self.assertEqual( [mock.call([mock.ANY, '--cleanup'], capture=False)], m_subp.call_args_list) - @mock.patch('cloudinit.config.cc_puppet.subp.subp', - return_value=(None, None)) - def test_install_with_version(self, m_subp): + def test_install_with_version(self, m_readurl, m_subp): """Install AIO with specific version""" - response = b'#!/bin/bash\necho "Hi Mom"' - httpretty.register_uri( - httpretty.GET, cc_puppet.AIO_INSTALL_URL, - body=response, status=200) - cc_puppet.install_puppet_aio(cc_puppet.AIO_INSTALL_URL, '7.6.0') self.assertEqual( [mock.call([mock.ANY, '-v', '7.6.0', '--cleanup'], capture=False)], m_subp.call_args_list) - @mock.patch('cloudinit.config.cc_puppet.subp.subp', - return_value=(None, None)) - def test_install_with_collection(self, m_subp): + def test_install_with_collection(self, m_readurl, m_subp): """Install AIO with specific collection""" - response = b'#!/bin/bash\necho "Hi Mom"' - httpretty.register_uri( - httpretty.GET, cc_puppet.AIO_INSTALL_URL, - body=response, status=200) - cc_puppet.install_puppet_aio( cc_puppet.AIO_INSTALL_URL, None, 'puppet6-nightly') @@ -373,15 +355,8 @@ class TestInstallPuppetAio(HttprettyTestCase): capture=False)], m_subp.call_args_list) - @mock.patch('cloudinit.config.cc_puppet.subp.subp', - return_value=(None, None)) - def test_install_with_no_cleanup(self, m_subp): + def test_install_with_no_cleanup(self, m_readurl, m_subp): """Install AIO with no cleanup""" - response = b'#!/bin/bash\necho "Hi Mom"' - httpretty.register_uri( - httpretty.GET, cc_puppet.AIO_INSTALL_URL, - body=response, status=200) - cc_puppet.install_puppet_aio( cc_puppet.AIO_INSTALL_URL, None, None, False) |