| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from unittest import mock |
| 16 |
|
| 17 |
import mistralclient.tests.unit.base_shell_test as base |
| 18 |
|
| 19 |
|
| 20 |
class TestShell(base.BaseShellTests): |
| 21 |
|
| 22 |
def test_help(self): |
| 23 |
"""Test that client is not created for help and bash complete""" |
| 24 |
for command in ('-h', |
| 25 |
'--help', |
| 26 |
'help', |
| 27 |
'help workbook-list', |
| 28 |
'bash-completion'): |
| 29 |
with mock.patch('mistralclient.api.client.client') as client_mock: |
| 30 |
self.shell(command) |
| 31 |
self.assertFalse(client_mock.called) |
| 32 |
|
| 33 |
@mock.patch('mistralclient.api.client.client') |
| 34 |
def test_command_no_mistral_url(self, client_mock): |
| 35 |
self.shell( |
| 36 |
'workbook-list' |
| 37 |
) |
| 38 |
self.assertTrue(client_mock.called) |
| 39 |
params = client_mock.call_args |
| 40 |
self.assertEqual('', params[1]['mistral_url']) |
| 41 |
|
| 42 |
@mock.patch('mistralclient.api.client.client') |
| 43 |
def test_command_interactive_mode(self, client_mock): |
| 44 |
self.shell('') |
| 45 |
self.assertTrue(client_mock.called) |
| 46 |
params = client_mock.call_args |
| 47 |
self.assertEqual('', params[1]['mistral_url']) |
| 48 |
|
| 49 |
@mock.patch('mistralclient.api.client.client') |
| 50 |
def test_command_with_mistral_url(self, client_mock): |
| 51 |
self.shell( |
| 52 |
'--os-mistral-url=http://localhost:8989/v2 workbook-list' |
| 53 |
) |
| 54 |
self.assertTrue(client_mock.called) |
| 55 |
params = client_mock.call_args |
| 56 |
self.assertEqual('http://localhost:8989/v2', |
| 57 |
params[1]['mistral_url']) |
| 58 |
|
| 59 |
@mock.patch('mistralclient.api.client.determine_client_version') |
| 60 |
def test_mistral_version(self, client_mock): |
| 61 |
self.shell( |
| 62 |
'--os-mistral-version=v1 workbook-list' |
| 63 |
) |
| 64 |
self.assertTrue(client_mock.called) |
| 65 |
mistral_version = client_mock.call_args |
| 66 |
self.assertEqual('v1', mistral_version[0][0]) |
| 67 |
|
| 68 |
@mock.patch('mistralclient.api.client.determine_client_version') |
| 69 |
def test_no_mistral_version(self, client_mock): |
| 70 |
self.shell('workbook-list') |
| 71 |
self.assertTrue(client_mock.called) |
| 72 |
mistral_version = client_mock.call_args |
| 73 |
self.assertEqual('v2', mistral_version[0][0]) |
| 74 |
|
| 75 |
@mock.patch('mistralclient.api.client.client') |
| 76 |
def test_service_type(self, client_mock): |
| 77 |
self.shell('--os-mistral-service-type=test workbook-list') |
| 78 |
self.assertTrue(client_mock.called) |
| 79 |
parmters = client_mock.call_args |
| 80 |
self.assertEqual('test', parmters[1]['service_type']) |
| 81 |
|
| 82 |
@mock.patch('mistralclient.api.client.client') |
| 83 |
def test_no_service_type(self, client_mock): |
| 84 |
self.shell('workbook-list') |
| 85 |
self.assertTrue(client_mock.called) |
| 86 |
params = client_mock.call_args |
| 87 |
self.assertEqual('workflowv2', params[1]['service_type']) |
| 88 |
|
| 89 |
@mock.patch('mistralclient.api.client.client') |
| 90 |
def test_endpoint_type(self, client_mock): |
| 91 |
self.shell('--os-mistral-endpoint-type=adminURL workbook-list') |
| 92 |
self.assertTrue(client_mock.called) |
| 93 |
params = client_mock.call_args |
| 94 |
self.assertEqual('adminURL', params[1]['endpoint_type']) |
| 95 |
|
| 96 |
@mock.patch('mistralclient.api.client.client') |
| 97 |
def test_no_endpoint_type(self, client_mock): |
| 98 |
self.shell('workbook-list') |
| 99 |
self.assertTrue(client_mock.called) |
| 100 |
params = client_mock.call_args |
| 101 |
self.assertEqual('publicURL', params[1]['endpoint_type']) |
| 102 |
|
| 103 |
@mock.patch('mistralclient.api.client.client') |
| 104 |
def test_auth_url(self, client_mock): |
| 105 |
self.shell( |
| 106 |
'--os-auth-url=https://127.0.0.1:35357/v3 ' |
| 107 |
'--os-username=admin ' |
| 108 |
'--os-password=1234 ' |
| 109 |
'workbook-list' |
| 110 |
) |
| 111 |
self.assertTrue(client_mock.called) |
| 112 |
params = client_mock.call_args |
| 113 |
self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) |
| 114 |
|
| 115 |
@mock.patch('mistralclient.api.client.client') |
| 116 |
def test_no_auth_url(self, client_mock): |
| 117 |
self.shell('workbook-list') |
| 118 |
self.assertTrue(client_mock.called) |
| 119 |
params = client_mock.call_args |
| 120 |
self.assertEqual('', params[1]['auth_url']) |
| 121 |
|
| 122 |
@mock.patch('mistralclient.api.client.client') |
| 123 |
def test_default_auth_url_with_os_password(self, client_mock): |
| 124 |
self.shell('--os-username=admin --os-password=1234 workbook-list') |
| 125 |
self.assertTrue(client_mock.called) |
| 126 |
params = client_mock.call_args |
| 127 |
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url']) |
| 128 |
|
| 129 |
@mock.patch('mistralclient.api.client.client') |
| 130 |
def test_default_auth_url_with_os_auth_token(self, client_mock): |
| 131 |
self.shell( |
| 132 |
'--os-auth-token=abcd1234 ' |
| 133 |
'workbook-list' |
| 134 |
) |
| 135 |
self.assertTrue(client_mock.called) |
| 136 |
params = client_mock.call_args |
| 137 |
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url']) |
| 138 |
|
| 139 |
@mock.patch('mistralclient.api.client.client') |
| 140 |
def test_profile(self, client_mock): |
| 141 |
self.shell('--profile=SECRET_HMAC_KEY workbook-list') |
| 142 |
self.assertTrue(client_mock.called) |
| 143 |
params = client_mock.call_args |
| 144 |
self.assertEqual('SECRET_HMAC_KEY', params[1]['profile']) |
| 145 |
|
| 146 |
@mock.patch('mistralclient.api.client.client') |
| 147 |
def test_region_name(self, client_mock): |
| 148 |
self.shell('--os-region-name=RegionOne workbook-list') |
| 149 |
|
| 150 |
self.assertTrue(client_mock.called) |
| 151 |
|
| 152 |
params = client_mock.call_args |
| 153 |
|
| 154 |
self.assertEqual('RegionOne', params[1]['region_name']) |
| 155 |
|
| 156 |
@mock.patch('mistralclient.api.client.client') |
| 157 |
def test_tenant_id_and_tenant_name(self, client_mock): |
| 158 |
self.shell( |
| 159 |
'--os-tenant-id=123tenant --os-tenant-name=fake_tenant' |
| 160 |
' workbook-list') |
| 161 |
|
| 162 |
self.assertTrue(client_mock.called) |
| 163 |
|
| 164 |
params = client_mock.call_args |
| 165 |
self.assertEqual('fake_tenant', params[1]['project_name']) |
| 166 |
self.assertEqual('123tenant', params[1]['project_id']) |
| 167 |
|
| 168 |
@mock.patch('mistralclient.api.client.client') |
| 169 |
def test_project_id_and_project_name(self, client_mock): |
| 170 |
self.shell( |
| 171 |
'--os-project-name=fake_tenant --os-project-id=123tenant' |
| 172 |
' workbook-list') |
| 173 |
|
| 174 |
self.assertTrue(client_mock.called) |
| 175 |
|
| 176 |
params = client_mock.call_args |
| 177 |
|
| 178 |
self.assertEqual('fake_tenant', params[1]['project_name']) |
| 179 |
self.assertEqual('123tenant', params[1]['project_id']) |
| 180 |
|
| 181 |
@mock.patch('mistralclient.api.client.client') |
| 182 |
def test_project_domain_name(self, client_mock): |
| 183 |
self.shell('--os-project-domain-name=default workbook-list') |
| 184 |
|
| 185 |
self.assertTrue(client_mock.called) |
| 186 |
|
| 187 |
params = client_mock.call_args |
| 188 |
|
| 189 |
self.assertEqual('default', params[1]['project_domain_name']) |
| 190 |
|
| 191 |
@mock.patch('mistralclient.api.client.client') |
| 192 |
def test_project_domain_id(self, client_mock): |
| 193 |
self.shell('--os-project-domain-id=default workbook-list') |
| 194 |
|
| 195 |
self.assertTrue(client_mock.called) |
| 196 |
|
| 197 |
params = client_mock.call_args |
| 198 |
|
| 199 |
self.assertEqual('default', params[1]['project_domain_id']) |
| 200 |
|
| 201 |
@mock.patch('mistralclient.api.client.client') |
| 202 |
def test_user_domain_name(self, client_mock): |
| 203 |
self.shell('--os-user-domain-name=default workbook-list') |
| 204 |
|
| 205 |
self.assertTrue(client_mock.called) |
| 206 |
|
| 207 |
params = client_mock.call_args |
| 208 |
self.assertEqual('default', params[1]['user_domain_name']) |
| 209 |
|
| 210 |
@mock.patch('mistralclient.api.client.client') |
| 211 |
def test_user_domain_id(self, client_mock): |
| 212 |
self.shell('--os-user-domain-id=default workbook-list') |
| 213 |
|
| 214 |
self.assertTrue(client_mock.called) |
| 215 |
|
| 216 |
params = client_mock.call_args |
| 217 |
self.assertEqual('default', params[1]['user_domain_id']) |
| 218 |
|
| 219 |
@mock.patch('mistralclient.api.client.client') |
| 220 |
def test_target_user_name_and_password(self, client_mock): |
| 221 |
self.shell( |
| 222 |
'--os-target-username=admin' |
| 223 |
' --os-target-password=secret_pass workbook-list') |
| 224 |
self.assertTrue(client_mock.called) |
| 225 |
|
| 226 |
params = client_mock.call_args |
| 227 |
self.assertEqual('admin', params[1]['target_username']) |
| 228 |
self.assertEqual('secret_pass', params[1]['target_api_key']) |
| 229 |
|
| 230 |
@mock.patch('mistralclient.api.client.client') |
| 231 |
def test_target_tenant_name_and_id(self, client_mock): |
| 232 |
self.shell( |
| 233 |
'--os-target-tenant-id=123fake' |
| 234 |
' --os-target-tenant-name=fake_target workbook-list') |
| 235 |
self.assertTrue(client_mock.called) |
| 236 |
|
| 237 |
params = client_mock.call_args |
| 238 |
self.assertEqual('123fake', params[1]['target_project_id']) |
| 239 |
self.assertEqual('fake_target', params[1]['target_project_name']) |
| 240 |
|
| 241 |
@mock.patch('mistralclient.api.client.client') |
| 242 |
def test_target_user_domain_id(self, client_mock): |
| 243 |
self.shell('--os-target-user-domain-id=default workbook-list') |
| 244 |
|
| 245 |
self.assertTrue(client_mock.called) |
| 246 |
|
| 247 |
params = client_mock.call_args |
| 248 |
self.assertEqual('default', params[1]['target_user_domain_id']) |
| 249 |
|
| 250 |
@mock.patch('mistralclient.api.client.client') |
| 251 |
def test_target_user_domain_name(self, client_mock): |
| 252 |
self.shell('--os-target-user-domain-name=default workbook-list') |
| 253 |
|
| 254 |
self.assertTrue(client_mock.called) |
| 255 |
|
| 256 |
params = client_mock.call_args |
| 257 |
self.assertEqual('default', params[1]['target_user_domain_name']) |
| 258 |
|
| 259 |
@mock.patch('mistralclient.api.client.client') |
| 260 |
def test_target_project_domain_id(self, client_mock): |
| 261 |
self.shell('--os-target-project-domain-id=default workbook-list') |
| 262 |
|
| 263 |
self.assertTrue(client_mock.called) |
| 264 |
|
| 265 |
params = client_mock.call_args |
| 266 |
self.assertEqual('default', params[1]['target_project_domain_id']) |
| 267 |
|
| 268 |
@mock.patch('mistralclient.api.client.client') |
| 269 |
def test_target_project_domain_name(self, client_mock): |
| 270 |
self.shell('--os-target-project-domain-name=default workbook-list') |
| 271 |
|
| 272 |
self.assertTrue(client_mock.called) |
| 273 |
|
| 274 |
params = client_mock.call_args |
| 275 |
self.assertEqual('default', params[1]['target_project_domain_name']) |
| 276 |
|
| 277 |
@mock.patch('mistralclient.api.client.client') |
| 278 |
def test_no_domains_keystone_v3(self, client_mock): |
| 279 |
self.shell( |
| 280 |
'--os-auth-url=https://127.0.0.1:35357/v3 ' |
| 281 |
'--os-username=admin ' |
| 282 |
'--os-password=1234 ' |
| 283 |
'workbook-list' |
| 284 |
) |
| 285 |
self.assertTrue(client_mock.called) |
| 286 |
params = client_mock.call_args |
| 287 |
self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) |
| 288 |
|
| 289 |
|
| 290 |
self.assertEqual('default', params[1]['project_domain_id']) |
| 291 |
self.assertEqual('default', params[1]['user_domain_id']) |
| 292 |
self.assertEqual('default', params[1]['target_project_domain_id']) |
| 293 |
self.assertEqual('default', params[1]['target_user_domain_id']) |
| 294 |
|
| 295 |
@mock.patch('mistralclient.api.client.client') |
| 296 |
def test_with_domain_names_keystone_v3(self, client_mock): |
| 297 |
self.shell( |
| 298 |
'--os-auth-url=https://127.0.0.1:35357/v3 ' |
| 299 |
'--os-username=admin ' |
| 300 |
'--os-password=1234 ' |
| 301 |
'--os-project-domain-name=fake_domain ' |
| 302 |
'--os-user-domain-name=fake_domain ' |
| 303 |
'--os-target-project-domain-name=fake_domain ' |
| 304 |
'--os-target-user-domain-name=fake_domain ' |
| 305 |
'workbook-list' |
| 306 |
) |
| 307 |
self.assertTrue(client_mock.called) |
| 308 |
params = client_mock.call_args |
| 309 |
self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) |
| 310 |
|
| 311 |
|
| 312 |
self.assertEqual('', params[1]['project_domain_id']) |
| 313 |
self.assertEqual('', params[1]['user_domain_id']) |
| 314 |
self.assertEqual('fake_domain', params[1]['project_domain_name']) |
| 315 |
self.assertEqual('fake_domain', params[1]['user_domain_name']) |
| 316 |
self.assertEqual( |
| 317 |
'fake_domain', |
| 318 |
params[1]['target_project_domain_name'] |
| 319 |
) |
| 320 |
self.assertEqual('fake_domain', params[1]['target_user_domain_name']) |
| 321 |
|
| 322 |
@mock.patch('mistralclient.api.client.client') |
| 323 |
def test_no_domains_keystone_v2(self, client_mock): |
| 324 |
self.shell( |
| 325 |
'--os-auth-url=https://127.0.0.1:35357/v2.0 ' |
| 326 |
'--os-username=admin ' |
| 327 |
'--os-password=1234 ' |
| 328 |
'workbook-list' |
| 329 |
) |
| 330 |
self.assertTrue(client_mock.called) |
| 331 |
params = client_mock.call_args |
| 332 |
self.assertEqual('https://127.0.0.1:35357/v2.0', params[1]['auth_url']) |
| 333 |
|
| 334 |
self.assertEqual('', params[1]['project_domain_id']) |
| 335 |
self.assertEqual('', params[1]['user_domain_id']) |
| 336 |
self.assertEqual('', params[1]['target_project_domain_id']) |
| 337 |
self.assertEqual('', params[1]['target_user_domain_id']) |