From b8df254738a43b690d1f511bc5c13290140c7ed0 Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Wed, 9 Dec 2020 18:52:51 +0100 Subject: sandbox CA Cert tests to not require ca-certificates (#715) CA Cert tests will fail on systems that don't have ca-certificates installed and configured. Signed-off-by: Daniel Watkins Signed-off-by: Eduardo Otubo --- tests/unittests/test_handler/test_handler_ca_certs.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'tests/unittests/test_handler') diff --git a/tests/unittests/test_handler/test_handler_ca_certs.py b/tests/unittests/test_handler/test_handler_ca_certs.py index e74a0a08..a16430d5 100644 --- a/tests/unittests/test_handler/test_handler_ca_certs.py +++ b/tests/unittests/test_handler/test_handler_ca_certs.py @@ -152,6 +152,7 @@ class TestAddCaCerts(TestCase): self.paths = helpers.Paths({ 'cloud_dir': tmpdir, }) + self.add_patch("cloudinit.config.cc_ca_certs.os.stat", "m_stat") def test_no_certs_in_list(self): """Test that no certificate are written if not provided.""" @@ -215,17 +216,12 @@ class TestAddCaCerts(TestCase): expected = "cloud-init-ca-certs.crt\n" - with ExitStack() as mocks: - mock_write = mocks.enter_context( - mock.patch.object(util, 'write_file', autospec=True)) - mock_stat = mocks.enter_context( - mock.patch("cloudinit.config.cc_ca_certs.os.stat") - ) - mock_stat.return_value.st_size = 0 + with mock.patch.object(util, 'write_file', autospec=True) as m_write: + self.m_stat.return_value.st_size = 0 cc_ca_certs.add_ca_certs([cert]) - mock_write.assert_has_calls([ + m_write.assert_has_calls([ mock.call("/usr/share/ca-certificates/cloud-init-ca-certs.crt", cert, mode=0o644), mock.call("/etc/ca-certificates.conf", expected, omode="wb")]) -- cgit v1.2.3