From 38407c6a78b6676ade148bbf9760d33152af7133 Mon Sep 17 00:00:00 2001
From: Stephen Finucane <stephenfin@redhat.com>
Date: Mon, 16 Dec 2024 18:16:48 +0000
Subject: [PATCH] tests: Stop setting attributes on class

For some reason we were setting a property mock on the FakeClientManager
class. In multiple places, no less. This has a nasty habit of causing
side-effects in other tests, depending on the order that tests run in.
Resolve this simply setting the attribute as we'd expect.

Change-Id: I8bf9055e3f5b885dd5a7a6d751b774934da4a7d7
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
---
 .../tests/unit/identity/v2_0/test_catalog.py  |  9 +++----
 .../tests/unit/identity/v2_0/test_role.py     |  3 +--
 .../identity/v2_0/test_role_assignment.py     |  3 ++-
 .../tests/unit/identity/v2_0/test_token.py    | 26 +++++--------------
 .../tests/unit/identity/v3/test_catalog.py    |  7 ++---
 .../tests/unit/identity/v3/test_project.py    |  4 +--
 .../unit/identity/v3/test_role_assignment.py  |  3 ++-
 .../tests/unit/identity/v3/test_token.py      | 25 ++++--------------
 .../tests/unit/identity/v3/test_trust.py      |  3 ++-
 9 files changed, 24 insertions(+), 59 deletions(-)

diff --git a/openstackclient/tests/unit/identity/v2_0/test_catalog.py b/openstackclient/tests/unit/identity/v2_0/test_catalog.py
index 63b3d475d4..ef8b1cf9a1 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_catalog.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_catalog.py
@@ -53,8 +53,7 @@ class TestCatalogList(TestCatalog):
             identity_fakes.TOKEN,
             fake_service=self.service_catalog,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -99,8 +98,7 @@ class TestCatalogList(TestCatalog):
             identity_fakes.TOKEN,
             fake_service=service_catalog,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -136,8 +134,7 @@ class TestCatalogShow(TestCatalog):
             identity_fakes.UNSCOPED_TOKEN,
             fake_service=self.service_catalog,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = [
             'compute',
diff --git a/openstackclient/tests/unit/identity/v2_0/test_role.py b/openstackclient/tests/unit/identity/v2_0/test_role.py
index 830653b0f4..117d2f0011 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_role.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_role.py
@@ -58,8 +58,7 @@ class TestRole(identity_fakes.TestIdentityv2):
             identity_fakes.TOKEN,
             fake_service=self.fake_service,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
 
 class TestRoleAdd(TestRole):
diff --git a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
index a06c270f0d..741b3ee193 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py
@@ -169,7 +169,8 @@ class TestRoleAssignmentList(TestRoleAssignment):
         self.assertEqual(datalist, tuple(data))
 
     def test_role_assignment_list_def_creds(self):
-        auth_ref = self.app.client_manager.auth_ref = mock.Mock()
+        self.app.client_manager.auth_ref = mock.Mock()
+        auth_ref = self.app.client_manager.auth_ref
         auth_ref.project_id.return_value = identity_fakes.project_id
         auth_ref.user_id.return_value = identity_fakes.user_id
 
diff --git a/openstackclient/tests/unit/identity/v2_0/test_token.py b/openstackclient/tests/unit/identity/v2_0/test_token.py
index 1e90104d94..56a5a2c458 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_token.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_token.py
@@ -11,29 +11,17 @@
 #   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #   License for the specific language governing permissions and limitations
 #   under the License.
-#
-
-from unittest import mock
 
 from openstackclient.identity.v2_0 import token
 from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
 
 
-class TestToken(identity_fakes.TestIdentityv2):
-    fake_user = identity_fakes.FakeUser.create_one_user()
-    fake_project = identity_fakes.FakeProject.create_one_project()
-
+class TestTokenIssue(identity_fakes.TestIdentityv2):
     def setUp(self):
         super().setUp()
 
-        # Get a shortcut to the Auth Ref Mock
-        self.ar_mock = mock.PropertyMock()
-        type(self.app.client_manager).auth_ref = self.ar_mock
-
-
-class TestTokenIssue(TestToken):
-    def setUp(self):
-        super().setUp()
+        self.fake_user = identity_fakes.FakeUser.create_one_user()
+        self.fake_project = identity_fakes.FakeProject.create_one_project()
 
         self.cmd = token.IssueToken(self.app, None)
 
@@ -41,8 +29,7 @@ class TestTokenIssue(TestToken):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.TOKEN,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -67,8 +54,7 @@ class TestTokenIssue(TestToken):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.UNSCOPED_TOKEN,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -91,7 +77,7 @@ class TestTokenIssue(TestToken):
         self.assertEqual(datalist, data)
 
 
-class TestTokenRevoke(TestToken):
+class TestTokenRevoke(identity_fakes.TestIdentityv2):
     TOKEN = 'fob'
 
     def setUp(self):
diff --git a/openstackclient/tests/unit/identity/v3/test_catalog.py b/openstackclient/tests/unit/identity/v3/test_catalog.py
index ed2db3b4d2..df292b1689 100644
--- a/openstackclient/tests/unit/identity/v3/test_catalog.py
+++ b/openstackclient/tests/unit/identity/v3/test_catalog.py
@@ -9,7 +9,6 @@
 #   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #   License for the specific language governing permissions and limitations
 #   under the License.
-#
 
 from unittest import mock
 
@@ -72,8 +71,7 @@ class TestCatalogList(TestCatalog):
             identity_fakes.TOKEN_WITH_PROJECT_ID,
             fake_service=self.fake_service,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -110,8 +108,7 @@ class TestCatalogShow(TestCatalog):
             identity_fakes.TOKEN_WITH_PROJECT_ID,
             fake_service=self.fake_service,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = [
             'compute',
diff --git a/openstackclient/tests/unit/identity/v3/test_project.py b/openstackclient/tests/unit/identity/v3/test_project.py
index 9b7fc8ceaa..9085498e31 100644
--- a/openstackclient/tests/unit/identity/v3/test_project.py
+++ b/openstackclient/tests/unit/identity/v3/test_project.py
@@ -11,7 +11,6 @@
 #   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #   License for the specific language governing permissions and limitations
 #   under the License.
-#
 
 from unittest import mock
 from unittest.mock import call
@@ -914,8 +913,7 @@ class TestProjectList(TestProject):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.TOKEN_WITH_PROJECT_ID,
         )
-        ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = [
             '--my-projects',
diff --git a/openstackclient/tests/unit/identity/v3/test_role_assignment.py b/openstackclient/tests/unit/identity/v3/test_role_assignment.py
index 65dad0d775..6fc66469c2 100644
--- a/openstackclient/tests/unit/identity/v3/test_role_assignment.py
+++ b/openstackclient/tests/unit/identity/v3/test_role_assignment.py
@@ -708,7 +708,8 @@ class TestRoleAssignmentList(identity_fakes.TestIdentityv3):
         self.assertEqual(datalist, tuple(data))
 
     def test_role_assignment_list_def_creds(self):
-        auth_ref = self.app.client_manager.auth_ref = mock.Mock()
+        self.app.client_manager.auth_ref = mock.Mock()
+        auth_ref = self.app.client_manager.auth_ref
         auth_ref.project_id.return_value = self.project.id
         auth_ref.user_id.return_value = self.user.id
 
diff --git a/openstackclient/tests/unit/identity/v3/test_token.py b/openstackclient/tests/unit/identity/v3/test_token.py
index 96375ea35c..f8d09b72cc 100644
--- a/openstackclient/tests/unit/identity/v3/test_token.py
+++ b/openstackclient/tests/unit/identity/v3/test_token.py
@@ -11,24 +11,12 @@
 #   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #   License for the specific language governing permissions and limitations
 #   under the License.
-#
-
-from unittest import mock
 
 from openstackclient.identity.v3 import token
 from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
 
 
-class TestToken(identity_fakes.TestIdentityv3):
-    def setUp(self):
-        super().setUp()
-
-        # Get a shortcut to the Auth Ref Mock
-        self.ar_mock = mock.PropertyMock()
-        type(self.app.client_manager).auth_ref = self.ar_mock
-
-
-class TestTokenIssue(TestToken):
+class TestTokenIssue(identity_fakes.TestIdentityv3):
     def setUp(self):
         super().setUp()
 
@@ -38,8 +26,7 @@ class TestTokenIssue(TestToken):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.TOKEN_WITH_PROJECT_ID,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -64,8 +51,7 @@ class TestTokenIssue(TestToken):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.TOKEN_WITH_DOMAIN_ID,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -90,8 +76,7 @@ class TestTokenIssue(TestToken):
         auth_ref = identity_fakes.fake_auth_ref(
             identity_fakes.UNSCOPED_TOKEN,
         )
-        self.ar_mock = mock.PropertyMock(return_value=auth_ref)
-        type(self.app.client_manager).auth_ref = self.ar_mock
+        self.app.client_manager.auth_ref = auth_ref
 
         arglist = []
         verifylist = []
@@ -114,7 +99,7 @@ class TestTokenIssue(TestToken):
         self.assertEqual(datalist, data)
 
 
-class TestTokenRevoke(TestToken):
+class TestTokenRevoke(identity_fakes.TestIdentityv3):
     TOKEN = 'fob'
 
     def setUp(self):
diff --git a/openstackclient/tests/unit/identity/v3/test_trust.py b/openstackclient/tests/unit/identity/v3/test_trust.py
index fb7ac9b0c6..d3a2fa3712 100644
--- a/openstackclient/tests/unit/identity/v3/test_trust.py
+++ b/openstackclient/tests/unit/identity/v3/test_trust.py
@@ -236,7 +236,8 @@ class TestTrustList(TestTrust):
         self.assertEqual(datalist, tuple(data))
 
     def test_trust_list_auth_user(self):
-        auth_ref = self.app.client_manager.auth_ref = mock.Mock()
+        self.app.client_manager.auth_ref = mock.Mock()
+        auth_ref = self.app.client_manager.auth_ref
         auth_ref.user_id.return_value = identity_fakes.user_id
 
         arglist = ['--auth-user']