Skip to content

Commit 5e1fc3d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix incorrect warning with --password-prompt option"
2 parents 32762bc + eea369e commit 5e1fc3d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

openstackclient/identity/v3/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def take_action(self, parsed_args):
289289
elif parsed_args.password_prompt:
290290
password = utils.get_password(self.app.stdin)
291291

292-
if not parsed_args.password:
292+
if not password:
293293
LOG.warning(
294294
_(
295295
"No password was supplied, authentication will fail "

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,53 @@ def test_user_create_password_prompt(self):
163163
self.assertEqual(self.columns, columns)
164164
self.assertEqual(self.datalist, data)
165165

166+
def test_user_create_password_prompt_no_warning(self):
167+
arglist = [
168+
'--password-prompt',
169+
self.user.name,
170+
]
171+
verifylist = [
172+
('password', None),
173+
('password_prompt', True),
174+
('enable', False),
175+
('disable', False),
176+
('name', self.user.name),
177+
]
178+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
179+
import logging
180+
181+
# Mock the password prompt
182+
mocker = mock.Mock()
183+
mocker.return_value = 'abc123'
184+
185+
# Use assertLogs to verify no warnings are logged
186+
logger = 'openstackclient.identity.v3.user'
187+
with mock.patch("osc_lib.utils.get_password", mocker):
188+
with self.assertLogs(logger, level='WARNING') as log_ctx:
189+
logging.getLogger(logger).warning(
190+
"Dummy warning for test setup"
191+
)
192+
columns, data = self.cmd.take_action(parsed_args)
193+
194+
self.assertEqual(1, len(log_ctx.records))
195+
self.assertIn(
196+
"Dummy warning for test setup", log_ctx.output[0]
197+
)
198+
self.assertNotIn(
199+
"No password was supplied", ''.join(log_ctx.output)
200+
)
201+
202+
# Set expected values
203+
kwargs = {
204+
'name': self.user.name,
205+
'is_enabled': True,
206+
'password': 'abc123',
207+
}
208+
self.identity_sdk_client.create_user.assert_called_with(**kwargs)
209+
210+
self.assertEqual(self.columns, columns)
211+
self.assertEqual(self.datalist, data)
212+
166213
def test_user_create_email(self):
167214
arglist = [
168215
'--email',

0 commit comments

Comments
 (0)