14
14
from ibm_cloud_sdk_core .authenticators import (IAMAuthenticator , NoAuthAuthenticator , Authenticator ,
15
15
BasicAuthenticator , CloudPakForDataAuthenticator )
16
16
from ibm_cloud_sdk_core import get_authenticator_from_environment
17
+ from ibm_cloud_sdk_core .utils import strip_extra_slashes
17
18
18
19
19
20
class IncludeExternalConfigService (BaseService ):
@@ -518,27 +519,37 @@ def test_json():
518
519
req = service .prepare_request ('POST' , url = '' , headers = {'X-opt-out' : True }, data = {'hello' : 'world' })
519
520
assert req .get ('data' ) == "{\" hello\" : \" world\" }"
520
521
521
- # For v2.x this test expects to see trailing slashes, this should be changed in v3.x
522
522
def test_trailing_slash ():
523
- service = AnyServiceV1 ('2018-11-20' , service_url = 'https://trailingSlash.com/' , authenticator = NoAuthAuthenticator ())
524
- assert service .service_url == 'https://trailingSlash.com/'
525
- service .set_service_url ('https://trailingSlash.com/' )
526
- assert service .service_url == 'https://trailingSlash.com/'
523
+ assert strip_extra_slashes ('' ) == ''
524
+ assert strip_extra_slashes ('//' ) == '/'
525
+ assert strip_extra_slashes ('/////' ) == '/'
526
+ assert strip_extra_slashes ('https://host' ) == 'https://host'
527
+ assert strip_extra_slashes ('https://host/' ) == 'https://host/'
528
+ assert strip_extra_slashes ('https://host//' ) == 'https://host/'
529
+ assert strip_extra_slashes ('https://host/path' ) == 'https://host/path'
530
+ assert strip_extra_slashes ('https://host/path/' ) == 'https://host/path/'
531
+ assert strip_extra_slashes ('https://host/path//' ) == 'https://host/path/'
532
+ assert strip_extra_slashes ('https://host//path//' ) == 'https://host//path/'
533
+
534
+ service = AnyServiceV1 ('2018-11-20' , service_url = 'https://host/' , authenticator = NoAuthAuthenticator ())
535
+ assert service .service_url == 'https://host/'
536
+ service .set_service_url ('https://host/' )
537
+ assert service .service_url == 'https://host/'
527
538
req = service .prepare_request ('POST' ,
528
- url = '/trailingSlashPath /' ,
539
+ url = '/path /' ,
529
540
headers = {'X-opt-out' : True },
530
541
data = {'hello' : 'world' })
531
- assert req .get ('url' ) == 'https://trailingSlash.com//trailingSlashPath /'
542
+ assert req .get ('url' ) == 'https://host//path /'
532
543
533
- service = AnyServiceV1 ('2018-11-20' , service_url = 'https://trailingSlash.com /' , authenticator = NoAuthAuthenticator ())
534
- assert service .service_url == 'https://trailingSlash.com /'
535
- service .set_service_url ('https://trailingSlash.com /' )
536
- assert service .service_url == 'https://trailingSlash.com /'
544
+ service = AnyServiceV1 ('2018-11-20' , service_url = 'https://host /' , authenticator = NoAuthAuthenticator ())
545
+ assert service .service_url == 'https://host /'
546
+ service .set_service_url ('https://host /' )
547
+ assert service .service_url == 'https://host /'
537
548
req = service .prepare_request ('POST' ,
538
549
url = '/' ,
539
550
headers = {'X-opt-out' : True },
540
551
data = {'hello' : 'world' })
541
- assert req .get ('url' ) == 'https://trailingSlash.com/ /'
552
+ assert req .get ('url' ) == 'https://host /'
542
553
543
554
service .set_service_url (None )
544
555
assert service .service_url is None
@@ -551,7 +562,7 @@ def test_trailing_slash():
551
562
url = '/' ,
552
563
headers = {'X-opt-out' : True },
553
564
data = {'hello' : 'world' })
554
- assert req .get ('url' ) == '// '
565
+ assert req .get ('url' ) == '/'
555
566
556
567
def test_service_url_not_set ():
557
568
service = BaseService (service_url = '' , authenticator = NoAuthAuthenticator ())
0 commit comments