Skip to content

Commit 4e8be5a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Stop setting attributes on class"
2 parents c74af3f + 38407c6 commit 4e8be5a

File tree

9 files changed

+24
-59
lines changed

9 files changed

+24
-59
lines changed

openstackclient/tests/unit/identity/v2_0/test_catalog.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def test_catalog_list(self):
5353
identity_fakes.TOKEN,
5454
fake_service=self.service_catalog,
5555
)
56-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
57-
type(self.app.client_manager).auth_ref = self.ar_mock
56+
self.app.client_manager.auth_ref = auth_ref
5857

5958
arglist = []
6059
verifylist = []
@@ -99,8 +98,7 @@ def test_catalog_list_with_endpoint_url(self):
9998
identity_fakes.TOKEN,
10099
fake_service=service_catalog,
101100
)
102-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
103-
type(self.app.client_manager).auth_ref = self.ar_mock
101+
self.app.client_manager.auth_ref = auth_ref
104102

105103
arglist = []
106104
verifylist = []
@@ -136,8 +134,7 @@ def test_catalog_show(self):
136134
identity_fakes.UNSCOPED_TOKEN,
137135
fake_service=self.service_catalog,
138136
)
139-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
140-
type(self.app.client_manager).auth_ref = self.ar_mock
137+
self.app.client_manager.auth_ref = auth_ref
141138

142139
arglist = [
143140
'compute',

openstackclient/tests/unit/identity/v2_0/test_role.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def setUp(self):
5858
identity_fakes.TOKEN,
5959
fake_service=self.fake_service,
6060
)
61-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
62-
type(self.app.client_manager).auth_ref = self.ar_mock
61+
self.app.client_manager.auth_ref = auth_ref
6362

6463

6564
class TestRoleAdd(TestRole):

openstackclient/tests/unit/identity/v2_0/test_role_assignment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def test_role_assignment_list_project_and_user(self):
169169
self.assertEqual(datalist, tuple(data))
170170

171171
def test_role_assignment_list_def_creds(self):
172-
auth_ref = self.app.client_manager.auth_ref = mock.Mock()
172+
self.app.client_manager.auth_ref = mock.Mock()
173+
auth_ref = self.app.client_manager.auth_ref
173174
auth_ref.project_id.return_value = identity_fakes.project_id
174175
auth_ref.user_id.return_value = identity_fakes.user_id
175176

openstackclient/tests/unit/identity/v2_0/test_token.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,25 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
15-
16-
from unittest import mock
1714

1815
from openstackclient.identity.v2_0 import token
1916
from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
2017

2118

22-
class TestToken(identity_fakes.TestIdentityv2):
23-
fake_user = identity_fakes.FakeUser.create_one_user()
24-
fake_project = identity_fakes.FakeProject.create_one_project()
25-
19+
class TestTokenIssue(identity_fakes.TestIdentityv2):
2620
def setUp(self):
2721
super().setUp()
2822

29-
# Get a shortcut to the Auth Ref Mock
30-
self.ar_mock = mock.PropertyMock()
31-
type(self.app.client_manager).auth_ref = self.ar_mock
32-
33-
34-
class TestTokenIssue(TestToken):
35-
def setUp(self):
36-
super().setUp()
23+
self.fake_user = identity_fakes.FakeUser.create_one_user()
24+
self.fake_project = identity_fakes.FakeProject.create_one_project()
3725

3826
self.cmd = token.IssueToken(self.app, None)
3927

4028
def test_token_issue(self):
4129
auth_ref = identity_fakes.fake_auth_ref(
4230
identity_fakes.TOKEN,
4331
)
44-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
45-
type(self.app.client_manager).auth_ref = self.ar_mock
32+
self.app.client_manager.auth_ref = auth_ref
4633

4734
arglist = []
4835
verifylist = []
@@ -67,8 +54,7 @@ def test_token_issue_with_unscoped_token(self):
6754
auth_ref = identity_fakes.fake_auth_ref(
6855
identity_fakes.UNSCOPED_TOKEN,
6956
)
70-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
71-
type(self.app.client_manager).auth_ref = self.ar_mock
57+
self.app.client_manager.auth_ref = auth_ref
7258

7359
arglist = []
7460
verifylist = []
@@ -91,7 +77,7 @@ def test_token_issue_with_unscoped_token(self):
9177
self.assertEqual(datalist, data)
9278

9379

94-
class TestTokenRevoke(TestToken):
80+
class TestTokenRevoke(identity_fakes.TestIdentityv2):
9581
TOKEN = 'fob'
9682

9783
def setUp(self):

openstackclient/tests/unit/identity/v3/test_catalog.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
12-
#
1312

1413
from unittest import mock
1514

@@ -72,8 +71,7 @@ def test_catalog_list(self):
7271
identity_fakes.TOKEN_WITH_PROJECT_ID,
7372
fake_service=self.fake_service,
7473
)
75-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
76-
type(self.app.client_manager).auth_ref = self.ar_mock
74+
self.app.client_manager.auth_ref = auth_ref
7775

7876
arglist = []
7977
verifylist = []
@@ -110,8 +108,7 @@ def test_catalog_show(self):
110108
identity_fakes.TOKEN_WITH_PROJECT_ID,
111109
fake_service=self.fake_service,
112110
)
113-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
114-
type(self.app.client_manager).auth_ref = self.ar_mock
111+
self.app.client_manager.auth_ref = auth_ref
115112

116113
arglist = [
117114
'compute',

openstackclient/tests/unit/identity/v3/test_project.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
1514

1615
from unittest import mock
1716
from unittest.mock import call
@@ -914,8 +913,7 @@ def test_project_list_my_projects(self):
914913
auth_ref = identity_fakes.fake_auth_ref(
915914
identity_fakes.TOKEN_WITH_PROJECT_ID,
916915
)
917-
ar_mock = mock.PropertyMock(return_value=auth_ref)
918-
type(self.app.client_manager).auth_ref = ar_mock
916+
self.app.client_manager.auth_ref = auth_ref
919917

920918
arglist = [
921919
'--my-projects',

openstackclient/tests/unit/identity/v3/test_role_assignment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ def test_role_assignment_list_project_with_domain(self):
708708
self.assertEqual(datalist, tuple(data))
709709

710710
def test_role_assignment_list_def_creds(self):
711-
auth_ref = self.app.client_manager.auth_ref = mock.Mock()
711+
self.app.client_manager.auth_ref = mock.Mock()
712+
auth_ref = self.app.client_manager.auth_ref
712713
auth_ref.project_id.return_value = self.project.id
713714
auth_ref.user_id.return_value = self.user.id
714715

openstackclient/tests/unit/identity/v3/test_token.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,12 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
#
15-
16-
from unittest import mock
1714

1815
from openstackclient.identity.v3 import token
1916
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
2017

2118

22-
class TestToken(identity_fakes.TestIdentityv3):
23-
def setUp(self):
24-
super().setUp()
25-
26-
# Get a shortcut to the Auth Ref Mock
27-
self.ar_mock = mock.PropertyMock()
28-
type(self.app.client_manager).auth_ref = self.ar_mock
29-
30-
31-
class TestTokenIssue(TestToken):
19+
class TestTokenIssue(identity_fakes.TestIdentityv3):
3220
def setUp(self):
3321
super().setUp()
3422

@@ -38,8 +26,7 @@ def test_token_issue_with_project_id(self):
3826
auth_ref = identity_fakes.fake_auth_ref(
3927
identity_fakes.TOKEN_WITH_PROJECT_ID,
4028
)
41-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
42-
type(self.app.client_manager).auth_ref = self.ar_mock
29+
self.app.client_manager.auth_ref = auth_ref
4330

4431
arglist = []
4532
verifylist = []
@@ -64,8 +51,7 @@ def test_token_issue_with_domain_id(self):
6451
auth_ref = identity_fakes.fake_auth_ref(
6552
identity_fakes.TOKEN_WITH_DOMAIN_ID,
6653
)
67-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
68-
type(self.app.client_manager).auth_ref = self.ar_mock
54+
self.app.client_manager.auth_ref = auth_ref
6955

7056
arglist = []
7157
verifylist = []
@@ -90,8 +76,7 @@ def test_token_issue_with_unscoped(self):
9076
auth_ref = identity_fakes.fake_auth_ref(
9177
identity_fakes.UNSCOPED_TOKEN,
9278
)
93-
self.ar_mock = mock.PropertyMock(return_value=auth_ref)
94-
type(self.app.client_manager).auth_ref = self.ar_mock
79+
self.app.client_manager.auth_ref = auth_ref
9580

9681
arglist = []
9782
verifylist = []
@@ -114,7 +99,7 @@ def test_token_issue_with_unscoped(self):
11499
self.assertEqual(datalist, data)
115100

116101

117-
class TestTokenRevoke(TestToken):
102+
class TestTokenRevoke(identity_fakes.TestIdentityv3):
118103
TOKEN = 'fob'
119104

120105
def setUp(self):

openstackclient/tests/unit/identity/v3/test_trust.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ def test_trust_list_no_options(self):
236236
self.assertEqual(datalist, tuple(data))
237237

238238
def test_trust_list_auth_user(self):
239-
auth_ref = self.app.client_manager.auth_ref = mock.Mock()
239+
self.app.client_manager.auth_ref = mock.Mock()
240+
auth_ref = self.app.client_manager.auth_ref
240241
auth_ref.user_id.return_value = identity_fakes.user_id
241242

242243
arglist = ['--auth-user']

0 commit comments

Comments
 (0)