37
37
38
38
from os .path import basename , dirname
39
39
from .utils import (
40
- CaptureOutput , fake_get_auth_keystone , _make_fake_import_keystone_client ,
40
+ CaptureOutput , fake_get_auth_keystone ,
41
41
FakeKeystone , StubResponse , MockHttpTest )
42
42
from swiftclient .utils import (
43
43
EMPTY_ETAG , EXPIRES_ISO8601_FORMAT ,
@@ -2534,16 +2534,26 @@ def _test_options_passed_to_keystone(self, cmd, opts, os_opts,
2534
2534
cmd_args = cmd_args )
2535
2535
ks_endpoint = 'http://example.com:8080/v1/AUTH_acc'
2536
2536
ks_token = 'fake_auth_token'
2537
+ # check correct auth version gets used
2538
+ key = 'auth-version'
2537
2539
fake_ks = FakeKeystone (endpoint = ks_endpoint , token = ks_token )
2540
+ if no_auth :
2541
+ fake_ks2 = fake_ks3 = None
2542
+ elif opts .get (key , self .defaults .get (key )) == '2.0' :
2543
+ fake_ks2 = fake_ks
2544
+ fake_ks3 = None
2545
+ else :
2546
+ fake_ks2 = None
2547
+ fake_ks3 = fake_ks
2538
2548
# fake_conn will check that storage_url and auth_token are as expected
2539
2549
endpoint = os_opts .get ('storage-url' , ks_endpoint )
2540
2550
token = os_opts .get ('auth-token' , ks_token )
2541
2551
fake_conn = self .fake_http_connection (204 , headers = {},
2542
2552
storage_url = endpoint ,
2543
2553
auth_token = token )
2544
2554
2545
- with mock .patch ('swiftclient.client._import_keystone_client' ,
2546
- _make_fake_import_keystone_client ( fake_ks ) ), \
2555
+ with mock .patch ('swiftclient.client.ksclient_v2' , fake_ks2 ), \
2556
+ mock . patch ( 'swiftclient.client.ksclient_v3' , fake_ks3 ), \
2547
2557
mock .patch ('swiftclient.client.http_connection' , fake_conn ), \
2548
2558
mock .patch .dict (os .environ , env , clear = True ), \
2549
2559
patch_disable_warnings () as mock_disable_warnings :
@@ -2562,16 +2572,11 @@ def _test_options_passed_to_keystone(self, cmd, opts, os_opts,
2562
2572
self .assertEqual ([], mock_disable_warnings .mock_calls )
2563
2573
2564
2574
if no_auth :
2565
- # check that keystone client was not used and terminate tests
2566
- self . assertIsNone ( getattr ( fake_ks , 'auth_version' ))
2567
- self . assertEqual ( len ( fake_ks . calls ), 0 )
2575
+ # We patched out both keystoneclient versions to be None;
2576
+ # they *can't* have been used and if we tried to, we would
2577
+ # have raised ClientExceptions
2568
2578
return
2569
2579
2570
- # check correct auth version was passed to _import_keystone_client
2571
- key = 'auth-version'
2572
- expected = opts .get (key , self .defaults .get (key ))
2573
- self .assertEqual (expected , fake_ks .auth_version )
2574
-
2575
2580
# check args passed to keystone Client __init__
2576
2581
self .assertEqual (len (fake_ks .calls ), 1 )
2577
2582
actual_args = fake_ks .calls [0 ]
@@ -2942,9 +2947,9 @@ def setUp(self):
2942
2947
self .account = 'AUTH_alice'
2943
2948
2944
2949
# keystone returns endpoint for another account
2945
- fake_ks = FakeKeystone (endpoint = 'http://example.com:8080/v1/AUTH_bob' ,
2946
- token = 'bob_token' )
2947
- self . fake_ks_import = _make_fake_import_keystone_client ( fake_ks )
2950
+ self . fake_ks = FakeKeystone (
2951
+ endpoint = 'http://example.com:8080/v1/AUTH_bob' ,
2952
+ token = 'bob_token' )
2948
2953
2949
2954
self .cont = 'c1'
2950
2955
self .cont_path = '/v1/%s/%s' % (self .account , self .cont )
@@ -3023,8 +3028,7 @@ def test_upload_with_read_write_access(self):
3023
3028
3024
3029
args , env = self ._make_cmd ('upload' , cmd_args = [self .cont , self .obj ,
3025
3030
'--leave-segments' ])
3026
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3027
- self .fake_ks_import ):
3031
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3028
3032
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3029
3033
with mock .patch .dict (os .environ , env ):
3030
3034
with CaptureOutput () as out :
@@ -3046,8 +3050,7 @@ def test_upload_with_write_only_access(self):
3046
3050
on_request = req_handler )
3047
3051
args , env = self ._make_cmd ('upload' , cmd_args = [self .cont , self .obj ,
3048
3052
'--leave-segments' ])
3049
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3050
- self .fake_ks_import ):
3053
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3051
3054
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3052
3055
with mock .patch .dict (os .environ , env ):
3053
3056
with CaptureOutput () as out :
@@ -3073,8 +3076,7 @@ def test_segment_upload_with_write_only_access(self):
3073
3076
'--segment-size=10' ,
3074
3077
'--segment-container=%s'
3075
3078
% self .cont ])
3076
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3077
- self .fake_ks_import ):
3079
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3078
3080
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3079
3081
with mock .patch .dict (os .environ , env ):
3080
3082
with CaptureOutput () as out :
@@ -3112,8 +3114,7 @@ def test_segment_upload_with_write_only_access_segments_container(self):
3112
3114
cmd_args = [self .cont , self .obj ,
3113
3115
'--leave-segments' ,
3114
3116
'--segment-size=10' ])
3115
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3116
- self .fake_ks_import ):
3117
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3117
3118
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3118
3119
with mock .patch .dict (os .environ , env ):
3119
3120
with CaptureOutput () as out :
@@ -3149,8 +3150,7 @@ def test_upload_with_no_access(self):
3149
3150
3150
3151
args , env = self ._make_cmd ('upload' , cmd_args = [self .cont , self .obj ,
3151
3152
'--leave-segments' ])
3152
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3153
- self .fake_ks_import ):
3153
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3154
3154
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3155
3155
with mock .patch .dict (os .environ , env ):
3156
3156
with CaptureOutput () as out :
@@ -3207,8 +3207,7 @@ def test_download_with_read_write_access(self):
3207
3207
args , env = self ._make_cmd ('download' , cmd_args = [self .cont ,
3208
3208
self .obj .lstrip ('/' ),
3209
3209
'--no-download' ])
3210
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3211
- self .fake_ks_import ):
3210
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3212
3211
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3213
3212
with mock .patch .dict (os .environ , env ):
3214
3213
with CaptureOutput () as out :
@@ -3229,8 +3228,7 @@ def test_download_with_read_only_access(self):
3229
3228
args , env = self ._make_cmd ('download' , cmd_args = [self .cont ,
3230
3229
self .obj .lstrip ('/' ),
3231
3230
'--no-download' ])
3232
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3233
- self .fake_ks_import ):
3231
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3234
3232
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3235
3233
with mock .patch .dict (os .environ , env ):
3236
3234
with CaptureOutput () as out :
@@ -3248,8 +3246,7 @@ def test_download_with_no_access(self):
3248
3246
args , env = self ._make_cmd ('download' , cmd_args = [self .cont ,
3249
3247
self .obj .lstrip ('/' ),
3250
3248
'--no-download' ])
3251
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3252
- self .fake_ks_import ):
3249
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3253
3250
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3254
3251
with mock .patch .dict (os .environ , env ):
3255
3252
with CaptureOutput () as out :
@@ -3273,8 +3270,7 @@ def test_list_with_read_access(self):
3273
3270
fake_conn = self .fake_http_connection (resp , on_request = req_handler )
3274
3271
3275
3272
args , env = self ._make_cmd ('download' , cmd_args = [self .cont ])
3276
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3277
- self .fake_ks_import ):
3273
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3278
3274
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3279
3275
with mock .patch .dict (os .environ , env ):
3280
3276
with CaptureOutput () as out :
@@ -3291,8 +3287,7 @@ def test_list_with_no_access(self):
3291
3287
fake_conn = self .fake_http_connection (403 )
3292
3288
3293
3289
args , env = self ._make_cmd ('download' , cmd_args = [self .cont ])
3294
- with mock .patch ('swiftclient.client._import_keystone_client' ,
3295
- self .fake_ks_import ):
3290
+ with mock .patch ('swiftclient.client.ksclient_v3' , self .fake_ks ):
3296
3291
with mock .patch ('swiftclient.client.http_connection' , fake_conn ):
3297
3292
with mock .patch .dict (os .environ , env ):
3298
3293
with CaptureOutput () as out :
0 commit comments