1212
1313from unittest import mock
1414
15+ from openstack .identity .v3 import project as _project
16+ from openstack .test import fakes as sdk_fakes
17+
1518from openstackclient .common import project_cleanup
1619from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
1720from openstackclient .tests .unit import utils as test_utils
2023class TestProjectCleanup (
2124 identity_fakes .FakeClientMixin , test_utils .TestCommand
2225):
23- project = identity_fakes .FakeProject .create_one_project ()
24-
2526 def setUp (self ):
2627 super ().setUp ()
2728 self .cmd = project_cleanup .ProjectCleanup (self .app , None )
2829
29- self .project_cleanup_mock = mock .Mock ()
30- self .sdk_connect_as_project_mock = mock .Mock (
31- return_value = self .app .client_manager .sdk_connection
32- )
33- self .app .client_manager .sdk_connection .project_cleanup = (
34- self .project_cleanup_mock
35- )
36- self .app .client_manager .sdk_connection .identity .find_project = (
37- mock .Mock (return_value = self .project )
38- )
39- self .app .client_manager .sdk_connection .connect_as_project = (
40- self .sdk_connect_as_project_mock
41- )
30+ self .project = sdk_fakes .generate_fake_resource (_project .Project )
31+ self .identity_sdk_client .find_project .return_value = self .project
32+ self .app .client_manager .sdk_connection .connect_as_project .return_value = self .app .client_manager .sdk_connection
4233
4334 def test_project_no_options (self ):
4435 arglist = []
@@ -74,7 +65,9 @@ def test_project_cleanup_with_filters(self):
7465 with mock .patch ('getpass.getpass' , return_value = 'y' ):
7566 result = self .cmd .take_action (parsed_args )
7667
77- self .sdk_connect_as_project_mock .assert_called_with (self .project )
68+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
69+ self .project
70+ )
7871 filters = {'created_at' : '2200-01-01' , 'updated_at' : '2200-01-02' }
7972
8073 calls = [
@@ -91,7 +84,9 @@ def test_project_cleanup_with_filters(self):
9184 skip_resources = None ,
9285 ),
9386 ]
94- self .project_cleanup_mock .assert_has_calls (calls )
87+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
88+ calls
89+ )
9590
9691 self .assertIsNone (result )
9792
@@ -112,7 +107,9 @@ def test_project_cleanup_with_auto_approve(self):
112107
113108 result = self .cmd .take_action (parsed_args )
114109
115- self .sdk_connect_as_project_mock .assert_called_with (self .project )
110+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
111+ self .project
112+ )
116113 calls = [
117114 mock .call (
118115 dry_run = True ,
@@ -127,7 +124,9 @@ def test_project_cleanup_with_auto_approve(self):
127124 skip_resources = None ,
128125 ),
129126 ]
130- self .project_cleanup_mock .assert_has_calls (calls )
127+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
128+ calls
129+ )
131130
132131 self .assertIsNone (result )
133132
@@ -147,7 +146,9 @@ def test_project_cleanup_with_project(self):
147146 with mock .patch ('getpass.getpass' , return_value = 'y' ):
148147 result = self .cmd .take_action (parsed_args )
149148
150- self .sdk_connect_as_project_mock .assert_called_with (self .project )
149+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
150+ self .project
151+ )
151152 calls = [
152153 mock .call (
153154 dry_run = True ,
@@ -162,7 +163,9 @@ def test_project_cleanup_with_project(self):
162163 skip_resources = None ,
163164 ),
164165 ]
165- self .project_cleanup_mock .assert_has_calls (calls )
166+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
167+ calls
168+ )
166169
167170 self .assertIsNone (result )
168171
@@ -182,7 +185,9 @@ def test_project_cleanup_with_project_abort(self):
182185 with mock .patch ('getpass.getpass' , return_value = 'y' ):
183186 result = self .cmd .take_action (parsed_args )
184187
185- self .sdk_connect_as_project_mock .assert_called_with (self .project )
188+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
189+ self .project
190+ )
186191 calls = [
187192 mock .call (
188193 dry_run = True ,
@@ -191,7 +196,9 @@ def test_project_cleanup_with_project_abort(self):
191196 skip_resources = None ,
192197 ),
193198 ]
194- self .project_cleanup_mock .assert_has_calls (calls )
199+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
200+ calls
201+ )
195202
196203 self .assertIsNone (result )
197204
@@ -211,8 +218,10 @@ def test_project_cleanup_with_dry_run(self):
211218
212219 result = self .cmd .take_action (parsed_args )
213220
214- self .sdk_connect_as_project_mock .assert_called_with (self .project )
215- self .project_cleanup_mock .assert_called_once_with (
221+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
222+ self .project
223+ )
224+ self .app .client_manager .sdk_connection .project_cleanup .assert_called_once_with (
216225 dry_run = True ,
217226 status_queue = mock .ANY ,
218227 filters = {},
@@ -238,7 +247,7 @@ def test_project_cleanup_with_auth_project(self):
238247 with mock .patch ('getpass.getpass' , return_value = 'y' ):
239248 result = self .cmd .take_action (parsed_args )
240249
241- self .sdk_connect_as_project_mock .assert_not_called ()
250+ self .app . client_manager . sdk_connection . connect_as_project .assert_not_called ()
242251 calls = [
243252 mock .call (
244253 dry_run = True ,
@@ -253,7 +262,9 @@ def test_project_cleanup_with_auth_project(self):
253262 skip_resources = None ,
254263 ),
255264 ]
256- self .project_cleanup_mock .assert_has_calls (calls )
265+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
266+ calls
267+ )
257268
258269 self .assertIsNone (result )
259270
@@ -272,7 +283,9 @@ def test_project_cleanup_with_skip_resource(self):
272283 with mock .patch ('getpass.getpass' , return_value = 'y' ):
273284 result = self .cmd .take_action (parsed_args )
274285
275- self .sdk_connect_as_project_mock .assert_called_with (self .project )
286+ self .app .client_manager .sdk_connection .connect_as_project .assert_called_with (
287+ self .project
288+ )
276289
277290 calls = [
278291 mock .call (
@@ -288,6 +301,8 @@ def test_project_cleanup_with_skip_resource(self):
288301 skip_resources = [skip_resource ],
289302 ),
290303 ]
291- self .project_cleanup_mock .assert_has_calls (calls )
304+ self .app .client_manager .sdk_connection .project_cleanup .assert_has_calls (
305+ calls
306+ )
292307
293308 self .assertIsNone (result )
0 commit comments