Skip to content

Commit 8a2088c

Browse files
unit tests for config setup
1 parent f86e2d2 commit 8a2088c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

SoftLayer/CLI/config/setup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def cli(env):
4545
"""Edit configuration."""
4646

4747
username, secret, endpoint_url, timeout = get_user_input(env)
48-
49-
env.client.transport.transport.endpoint_url = endpoint_url
50-
new_client = SoftLayer.client(username=username, api_key=secret, endpoint_url=endpoint_url, timeout=timeout)
48+
new_client = SoftLayer.Client(username=username, api_key=secret, endpoint_url=endpoint_url, timeout=timeout)
5149
api_key = get_api_key(new_client, username, secret)
5250

5351
path = '~/.softlayer'
@@ -115,9 +113,7 @@ def get_user_input(env):
115113
if endpoint_type == 'custom':
116114
endpoint_url = env.input('Endpoint URL', default=endpoint)
117115
else:
118-
endpoint_url = endpoint
119-
120-
print("SETTING enpoint to %s "% endpoint_url)
116+
endpoint_url = endpoint_type
121117

122118
# Ask for timeout
123119
timeout = env.input('Timeout', default=defaults['timeout'] or 0)

tests/CLI/modules/config_tests.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,17 @@ def test_setup(self, mocked_input, getpass, confirm_mock):
6262
getpass.return_value = 'A' * 64
6363
mocked_input.side_effect = ['user', 'public', 0]
6464

65-
result = self.run_command(['--config=%s' % config_file.name,
66-
'config', 'setup'])
65+
result = self.run_command(['--config=%s' % config_file.name, 'config', 'setup'])
6766

6867
self.assert_no_fail(result)
69-
self.assertTrue('Configuration Updated Successfully'
70-
in result.output)
68+
self.assertTrue('Configuration Updated Successfully' in result.output)
7169
contents = config_file.read().decode("utf-8")
7270
self.assertTrue('[softlayer]' in contents)
7371
self.assertTrue('username = user' in contents)
7472
self.assertTrue('api_key = AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
7573
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA' in contents)
76-
self.assertTrue('endpoint_url = %s' % consts.API_PUBLIC_ENDPOINT
77-
in contents)
74+
self.assertTrue('endpoint_url = %s' % consts.API_PUBLIC_ENDPOINT in contents)
75+
7876

7977
@mock.patch('SoftLayer.CLI.formatting.confirm')
8078
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
@@ -115,6 +113,17 @@ def test_get_user_input_custom(self, mocked_input, getpass):
115113

116114
self.assertEqual(endpoint_url, 'custom-endpoint')
117115

116+
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
117+
@mock.patch('SoftLayer.CLI.environment.Environment.input')
118+
def test_github_1074(self, mocked_input, getpass):
119+
"""Tests to make sure directly using an endpoint works"""
120+
getpass.return_value = 'A' * 64
121+
mocked_input.side_effect = ['user', 'test-endpoint', 0]
122+
123+
_, _, endpoint_url, _ = config.get_user_input(self.env)
124+
125+
self.assertEqual(endpoint_url, 'test-endpoint')
126+
118127
@mock.patch('SoftLayer.CLI.environment.Environment.getpass')
119128
@mock.patch('SoftLayer.CLI.environment.Environment.input')
120129
def test_get_user_input_default(self, mocked_input, getpass):

0 commit comments

Comments
 (0)