Skip to content

Commit 06721ea

Browse files
author
Dean Troyer
committed
Integ test cleanup
Change-Id: Ie58a7bec569421097e92a7ddf3cb164fc3f07413
1 parent 8cef12c commit 06721ea

1 file changed

Lines changed: 91 additions & 42 deletions

File tree

openstackclient/tests/test_shell_integ.py

Lines changed: 91 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_shell_args_cacert_insecure(self):
355355

356356

357357
class TestShellCliPrecedence(TestShellInteg):
358-
"""Validate option precedence rules
358+
"""Validate option precedence rules without clouds.yaml
359359
360360
Global option values may be set in three places:
361361
* command line options
@@ -368,6 +368,96 @@ class TestShellCliPrecedence(TestShellInteg):
368368

369369
def setUp(self):
370370
super(TestShellCliPrecedence, self).setUp()
371+
env = {
372+
"OS_AUTH_URL": V3_AUTH_URL,
373+
"OS_PROJECT_DOMAIN_ID": test_shell.DEFAULT_PROJECT_DOMAIN_ID,
374+
"OS_USER_DOMAIN_ID": test_shell.DEFAULT_USER_DOMAIN_ID,
375+
"OS_USERNAME": test_shell.DEFAULT_USERNAME,
376+
"OS_IDENTITY_API_VERSION": "3",
377+
}
378+
self.useFixture(osc_lib_utils.EnvFixture(copy.deepcopy(env)))
379+
380+
self.token = ksa_fixture.V3Token(
381+
project_domain_id=test_shell.DEFAULT_PROJECT_DOMAIN_ID,
382+
user_domain_id=test_shell.DEFAULT_USER_DOMAIN_ID,
383+
user_name=test_shell.DEFAULT_USERNAME,
384+
)
385+
386+
# Set up the v3 auth routes
387+
self.requests_mock.register_uri(
388+
'GET',
389+
V3_AUTH_URL,
390+
json=V3_VERSION_RESP,
391+
status_code=200,
392+
)
393+
self.requests_mock.register_uri(
394+
'POST',
395+
V3_AUTH_URL + 'auth/tokens',
396+
json=self.token,
397+
status_code=200,
398+
)
399+
400+
# Patch a v3 auth URL into the o-c-c data
401+
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
402+
= V3_AUTH_URL
403+
404+
def test_shell_args_options(self):
405+
"""Verify command line options override environment variables"""
406+
407+
_shell = shell.OpenStackShell()
408+
_shell.run(
409+
"--os-username zarquon --os-password qaz "
410+
"configuration show".split(),
411+
)
412+
413+
# Check general calls
414+
self.assertEqual(len(self.requests_mock.request_history), 2)
415+
416+
# Check discovery request
417+
self.assertEqual(
418+
V3_AUTH_URL,
419+
self.requests_mock.request_history[0].url,
420+
)
421+
422+
# Check auth request
423+
auth_req = self.requests_mock.request_history[1].json()
424+
425+
# -env, -cli
426+
# No test, everything not specified tests this
427+
428+
# -env, +cli
429+
self.assertEqual(
430+
'qaz',
431+
auth_req['auth']['identity']['password']['user']['password'],
432+
)
433+
434+
# +env, -cli
435+
self.assertEqual(
436+
test_shell.DEFAULT_PROJECT_DOMAIN_ID,
437+
auth_req['auth']['identity']['password']['user']['domain']['id'],
438+
)
439+
440+
# +env, +cli
441+
self.assertEqual(
442+
'zarquon',
443+
auth_req['auth']['identity']['password']['user']['name'],
444+
)
445+
446+
447+
class TestShellCliPrecedenceOCC(TestShellInteg):
448+
"""Validate option precedence rules with clouds.yaml
449+
450+
Global option values may be set in three places:
451+
* command line options
452+
* environment variables
453+
* clouds.yaml
454+
455+
Verify that the above order is the precedence used,
456+
i.e. a command line option overrides all others, etc
457+
"""
458+
459+
def setUp(self):
460+
super(TestShellCliPrecedenceOCC, self).setUp()
371461
env = {
372462
"OS_CLOUD": "megacloud",
373463
"OS_AUTH_URL": V3_AUTH_URL,
@@ -403,47 +493,6 @@ def setUp(self):
403493
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
404494
= V3_AUTH_URL
405495

406-
# @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
407-
# @mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
408-
# def test_shell_args_options(self, config_mock, vendor_mock):
409-
# """Verify command line options override environment variables"""
410-
411-
# _shell = shell.OpenStackShell()
412-
# _shell.run(
413-
# "--os-username zarquon --os-password qaz "
414-
# "configuration show".split(),
415-
# )
416-
417-
# # Check general calls
418-
# self.assertEqual(len(self.requests_mock.request_history), 2)
419-
420-
# # Check discovery request
421-
# self.assertEqual(
422-
# V3_AUTH_URL,
423-
# self.requests_mock.request_history[0].url,
424-
# )
425-
426-
# # Check auth request
427-
# auth_req = self.requests_mock.request_history[1].json()
428-
429-
# # Environment var, no option
430-
# self.assertEqual(
431-
# test_shell.DEFAULT_PROJECT_DOMAIN_ID,
432-
# auth_req['auth']['identity']['password']['user']['domain']['id'],
433-
# )
434-
435-
# # Environment var, --os-username override
436-
# self.assertEqual(
437-
# 'zarquon',
438-
# auth_req['auth']['identity']['password']['user']['name'],
439-
# )
440-
441-
# # No environment var, --os-password override
442-
# self.assertEqual(
443-
# 'qaz',
444-
# auth_req['auth']['identity']['password']['user']['password'],
445-
# )
446-
447496
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
448497
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
449498
def test_shell_args_precedence_1(self, config_mock, vendor_mock):

0 commit comments

Comments
 (0)