From a84bf7d84381b5781a9c4b8764f7bf7bb8ef73ae Mon Sep 17 00:00:00 2001 From: Bodo Petermann Date: Fri, 29 May 2020 16:58:33 +0200 Subject: [PATCH] Fix test_barbican_legacy for Python 3.8 Fixes failing unit tests in octavia.tests.unit.certificates.manager.test_barbican_legacy.TestBarbicanManager for Python 3.8 Some of the tests fail setting up a mock.Mock(spec=secrets.Secret) because a ValueError exception is raised unexpectedly. The reason is that test_get_cert_no_registration_raise_on_secret_access_failure patches the `payload` property of barbicanclient.v1.secrets.Secret to raise a ValueError. When a subsequent test tries to set up a mock.Mock(spec=secrets.Secret) in Python 3.8 the Mock class will try to look at the properties of the spec class and accessing `payload` doesn't behave normally anymore: it raises ValueError now. Fixed by using a different approach of mocking `payload` in test_get_cert_no_registration_raise_on_secret_access_failure so that it does not influence subsequent tests. Change-Id: Ic534a4715c85c2216c7251209507acf74a999153 Story: 2007490 Task: 39212 --- .../manager/test_barbican_legacy.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/octavia/tests/unit/certificates/manager/test_barbican_legacy.py b/octavia/tests/unit/certificates/manager/test_barbican_legacy.py index aa7358ba34..ef92f22add 100644 --- a/octavia/tests/unit/certificates/manager/test_barbican_legacy.py +++ b/octavia/tests/unit/certificates/manager/test_barbican_legacy.py @@ -238,20 +238,21 @@ class TestBarbicanManager(base.TestCase): def test_get_cert_no_registration_raise_on_secret_access_failure(self): self.bc.containers.get.return_value = self.container - type(self.certificate).payload = mock.PropertyMock( - side_effect=ValueError) + with mock.patch('barbicanclient.v1.secrets.Secret.payload', + new_callable=mock.PropertyMock) as mock_payload: + mock_payload.side_effect = ValueError - # Get the container data - self.assertRaises( - ValueError, self.cert_manager.get_cert, - context=self.context, - cert_ref=self.container_ref, check_only=True - ) + # Get the container data + self.assertRaises( + ValueError, self.cert_manager.get_cert, + context=self.context, + cert_ref=self.container_ref, check_only=True + ) - # 'get' should be called once with the container_ref - self.bc.containers.get.assert_called_once_with( - container_ref=self.container_ref - ) + # 'get' should be called once with the container_ref + self.bc.containers.get.assert_called_once_with( + container_ref=self.container_ref + ) def test_delete_cert(self): # Attempt to deregister as a consumer