def test_get_user_input_custom(self): command = config.Setup(client=self.client, env=self.env) # get_user_input self.env.getpass.return_value = 'A' * 64 self.env.input.side_effect = ['user', 'custom', 'custom-endpoint'] _, _, endpoint_url, _ = command.get_user_input() self.assertEqual(endpoint_url, 'custom-endpoint')
def test_setup_cancel(self, confirm_mock): with tempfile.NamedTemporaryFile() as config_file: confirm_mock.return_value = False self.env.getpass.return_value = 'A' * 64 self.env.input.side_effect = ['user', 'public'] command = config.Setup(client=self.client, env=self.env) self.assertRaises(exceptions.CLIAbort, command.execute, {'--config': config_file.name})
def test_get_user_input_default(self): command = config.Setup(client=self.client, env=self.env) # get_user_input self.env.getpass.return_value = 'A' * 64 self.env.input.side_effect = ['user', ''] _, _, endpoint_url, _ = command.get_user_input() self.assertEqual(endpoint_url, consts.API_PUBLIC_ENDPOINT)
def test_get_user_input_private(self): command = config.Setup(client=self.client, env=self.env) # get_user_input self.env.getpass.return_value = 'A' * 64 self.env.input.side_effect = ['user', 'private'] username, secret, endpoint_url, timeout = command.get_user_input() self.assertEqual(username, 'user') self.assertEqual(secret, 'A' * 64) self.assertEqual(endpoint_url, consts.API_PRIVATE_ENDPOINT) self.assertEqual(timeout, 10)
def test_setup(self, confirm_mock): with tempfile.NamedTemporaryFile() as config_file: confirm_mock.return_value = True self.env.getpass.return_value = 'A' * 64 self.env.input.side_effect = ['user', 'public'] command = config.Setup(client=self.client, env=self.env) output = command.execute({'--config': config_file.name}) self.assertEqual('Configuration Updated Successfully', output) contents = config_file.read().decode("utf-8") self.assertTrue('[softlayer]' in contents) self.assertTrue('username = user' in contents) self.assertTrue('api_key = AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA' in contents) self.assertTrue('endpoint_url = %s' % consts.API_PUBLIC_ENDPOINT in contents)