@@ -518,6 +518,37 @@ def test_json():
518
518
req = service .prepare_request ('POST' , url = '' , headers = {'X-opt-out' : True }, data = {'hello' : 'world' })
519
519
assert req .get ('data' ) == "{\" hello\" : \" world\" }"
520
520
521
+ def test_trailing_slash ():
522
+ service = AnyServiceV1 ('2018-11-20' , service_url = 'https://trailingSlash.com/' , authenticator = NoAuthAuthenticator ())
523
+ assert service .service_url == 'https://trailingSlash.com'
524
+ service .set_service_url ('https://trailingSlash.com/' )
525
+ assert service .service_url == 'https://trailingSlash.com'
526
+ req = service .prepare_request ('POST' ,
527
+ url = '/trailingSlashPath/' ,
528
+ headers = {'X-opt-out' : True },
529
+ data = {'hello' : 'world' })
530
+ assert req .get ('url' ) == 'https://trailingSlash.com/trailingSlashPath'
531
+
532
+ service = AnyServiceV1 ('2018-11-20' , service_url = 'https://trailingSlash.com/' , authenticator = NoAuthAuthenticator ())
533
+ assert service .service_url == 'https://trailingSlash.com'
534
+ service .set_service_url ('https://trailingSlash.com/' )
535
+ assert service .service_url == 'https://trailingSlash.com'
536
+ req = service .prepare_request ('POST' ,
537
+ url = '/' ,
538
+ headers = {'X-opt-out' : True },
539
+ data = {'hello' : 'world' })
540
+ assert req .get ('url' ) == 'https://trailingSlash.com'
541
+
542
+ service = AnyServiceV1 ('2018-11-20' , service_url = '/' , authenticator = NoAuthAuthenticator ())
543
+ assert service .service_url == ''
544
+ service .set_service_url ('/' )
545
+ assert service .service_url == ''
546
+ with pytest .raises (ValueError ): # ValueError thrown because service_url is '' and falsey
547
+ req = service .prepare_request ('POST' ,
548
+ url = '/' ,
549
+ headers = {'X-opt-out' : True },
550
+ data = {'hello' : 'world' })
551
+
521
552
def test_service_url_not_set ():
522
553
service = BaseService (service_url = '' , authenticator = NoAuthAuthenticator ())
523
554
with pytest .raises (ValueError ) as err :
0 commit comments