summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <therealfalcon@gmail.com>2021-08-12 20:06:28 -0500
committerGitHub <noreply@github.com>2021-08-12 19:06:28 -0600
commit1c3b10b58768ec4c70384f4a7af7ce956518fe7c (patch)
treed01279fb517bde8d98bb0be9ca032043883007b8
parente119ceceb7d76af7d75c04a8779b9c5fc68083a8 (diff)
downloadcloud-init-git-1c3b10b58768ec4c70384f4a7af7ce956518fe7c.tar.gz
Replace broken httpretty tests with mock (SC-324) (#973)
* Replace broken httpretty tests with mock Certain versions of python/httpretty don't work correctly using https URIs. #960 recently added httpretty tests using https. This commit replaces the httpretty tests that were failing on https with mocks of readurl instead.
-rw-r--r--tests/unittests/test_handler/test_handler_puppet.py59
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)