20
20
from ibm_cloud_sdk_core import get_authenticator_from_environment
21
21
from ibm_cloud_sdk_core .authenticators import (IAMAuthenticator , NoAuthAuthenticator , Authenticator ,
22
22
BasicAuthenticator , CloudPakForDataAuthenticator )
23
- from ibm_cloud_sdk_core .utils import strip_extra_slashes
24
23
25
24
26
25
class IncludeExternalConfigService (BaseService ):
@@ -698,6 +697,7 @@ def test_user_agent_header():
698
697
assert response .get_result ().request .headers .__getitem__ (
699
698
'user-agent' ) == user_agent_header ['User-Agent' ]
700
699
700
+
701
701
@responses .activate
702
702
def test_reserved_keys (caplog ):
703
703
service = AnyServiceV1 ('2021-07-02' , authenticator = NoAuthAuthenticator ())
@@ -723,6 +723,7 @@ def test_reserved_keys(caplog):
723
723
assert caplog .record_tuples [2 ][2 ] == '"headers" has been removed from the request'
724
724
assert caplog .record_tuples [3 ][2 ] == '"cookies" has been removed from the request'
725
725
726
+
726
727
@responses .activate
727
728
def test_ssl_error ():
728
729
responses .add (
@@ -810,56 +811,71 @@ def test_json():
810
811
service = AnyServiceV1 ('2018-11-20' , authenticator = NoAuthAuthenticator ())
811
812
req = service .prepare_request ('POST' , url = '' , headers = {
812
813
'X-opt-out' : True }, data = {'hello' : 'world' , 'fóó' : 'bår' })
813
- assert req .get ('data' ) == b'{"hello": "world", "f\\ u00f3\\ u00f3": "b\\ u00e5r"}'
814
+ assert req .get (
815
+ 'data' ) == b'{"hello": "world", "f\\ u00f3\\ u00f3": "b\\ u00e5r"}'
814
816
815
817
816
- def test_trailing_slash ():
817
- assert strip_extra_slashes ('' ) == ''
818
- assert strip_extra_slashes ('//' ) == '/'
819
- assert strip_extra_slashes ('/////' ) == '/'
820
- assert strip_extra_slashes ('https://host' ) == 'https://host'
821
- assert strip_extra_slashes ('https://host/' ) == 'https://host/'
822
- assert strip_extra_slashes ('https://host//' ) == 'https://host/'
823
- assert strip_extra_slashes ('https://host/path' ) == 'https://host/path'
824
- assert strip_extra_slashes ('https://host/path/' ) == 'https://host/path/'
825
- assert strip_extra_slashes ('https://host/path//' ) == 'https://host/path/'
826
- assert strip_extra_slashes ('https://host//path//' ) == 'https://host//path/'
827
-
818
+ def test_service_url_handling ():
828
819
service = AnyServiceV1 (
829
- '2018-11-20' , service_url = 'https://host/' , authenticator = NoAuthAuthenticator ())
830
- assert service .service_url == 'https://host/'
820
+ '2018-11-20' , service_url = 'https://host///////' , authenticator = NoAuthAuthenticator ())
821
+ assert service .service_url == 'https://host'
822
+
831
823
service .set_service_url ('https://host/' )
832
- assert service .service_url == 'https://host/'
824
+ assert service .service_url == 'https://host'
825
+
833
826
req = service .prepare_request ('POST' ,
834
827
url = '/path/' ,
835
828
headers = {'X-opt-out' : True },
836
829
data = {'hello' : 'world' })
837
- assert req .get ('url' ) == 'https://host// path/'
830
+ assert req .get ('url' ) == 'https://host/path/'
838
831
839
832
service = AnyServiceV1 (
840
833
'2018-11-20' , service_url = 'https://host/' , authenticator = NoAuthAuthenticator ())
841
- assert service .service_url == 'https://host/'
834
+ assert service .service_url == 'https://host'
835
+
842
836
service .set_service_url ('https://host/' )
843
- assert service .service_url == 'https://host/'
837
+ assert service .service_url == 'https://host'
838
+
844
839
req = service .prepare_request ('POST' ,
845
840
url = '/' ,
846
841
headers = {'X-opt-out' : True },
847
842
data = {'hello' : 'world' })
848
843
assert req .get ('url' ) == 'https://host/'
849
844
845
+ req = service .prepare_request ('POST' ,
846
+ url = '////' ,
847
+ headers = {'X-opt-out' : True },
848
+ data = {'hello' : 'world' })
849
+ assert req .get ('url' ) == 'https://host/'
850
+
850
851
service .set_service_url (None )
851
852
assert service .service_url is None
852
853
853
854
service = AnyServiceV1 ('2018-11-20' , service_url = '/' ,
854
855
authenticator = NoAuthAuthenticator ())
855
- assert service .service_url == '/'
856
+ assert service .service_url == ''
857
+
856
858
service .set_service_url ('/' )
857
- assert service .service_url == '/'
858
- req = service .prepare_request ('POST' ,
859
- url = '/' ,
860
- headers = {'X-opt-out' : True },
861
- data = {'hello' : 'world' })
862
- assert req .get ('url' ) == '/'
859
+ assert service .service_url == ''
860
+
861
+ with pytest .raises (ValueError ) as err :
862
+ service .prepare_request ('POST' ,
863
+ url = '/' ,
864
+ headers = {'X-opt-out' : True },
865
+ data = {'hello' : 'world' })
866
+ assert str (err .value ) == 'The service_url is required'
867
+
868
+
869
+ def test_service_url_slash ():
870
+ service = AnyServiceV1 ('2018-11-20' , service_url = '/' ,
871
+ authenticator = NoAuthAuthenticator ())
872
+ assert service .service_url == ''
873
+ with pytest .raises (ValueError ) as err :
874
+ service .prepare_request ('POST' ,
875
+ url = '/' ,
876
+ headers = {'X-opt-out' : True },
877
+ data = {'hello' : 'world' })
878
+ assert str (err .value ) == 'The service_url is required'
863
879
864
880
865
881
def test_service_url_not_set ():
0 commit comments