Skip to content

Commit

Permalink
fix: Revert service_url slash stripping to work with current generate…
Browse files Browse the repository at this point in the history
…d unit tests
  • Loading branch information
rmkeezer committed May 22, 2020
1 parent 8688f2f commit c960b7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
5 changes: 1 addition & 4 deletions ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ def set_service_url(self, service_url: str) -> None:
'The service url shouldn\'t start or end with curly brackets or quotes. '
'Be sure to remove any {} and \" characters surrounding your service url'
)
if service_url is not None:
self.service_url = service_url.rstrip('/') # remove trailing slash
else:
self.service_url = None
self.service_url = service_url

def get_authenticator(self) -> Authenticator:
"""Get the authenticator currently used by the service.
Expand Down
26 changes: 13 additions & 13 deletions test/test_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,37 +520,37 @@ def test_json():

def test_trailing_slash():
service = AnyServiceV1('2018-11-20', service_url='https://trailingSlash.com/', authenticator=NoAuthAuthenticator())
assert service.service_url == 'https://trailingSlash.com'
assert service.service_url == 'https://trailingSlash.com/'
service.set_service_url('https://trailingSlash.com/')
assert service.service_url == 'https://trailingSlash.com'
assert service.service_url == 'https://trailingSlash.com/'
req = service.prepare_request('POST',
url='/trailingSlashPath/',
headers={'X-opt-out': True},
data={'hello': 'world'})
assert req.get('url') == 'https://trailingSlash.com/trailingSlashPath'
assert req.get('url') == 'https://trailingSlash.com//trailingSlashPath'

service = AnyServiceV1('2018-11-20', service_url='https://trailingSlash.com/', authenticator=NoAuthAuthenticator())
assert service.service_url == 'https://trailingSlash.com'
assert service.service_url == 'https://trailingSlash.com/'
service.set_service_url('https://trailingSlash.com/')
assert service.service_url == 'https://trailingSlash.com'
assert service.service_url == 'https://trailingSlash.com/'
req = service.prepare_request('POST',
url='/',
headers={'X-opt-out': True},
data={'hello': 'world'})
assert req.get('url') == 'https://trailingSlash.com'
assert req.get('url') == 'https://trailingSlash.com/'

service.set_service_url(None)
assert service.service_url is None

service = AnyServiceV1('2018-11-20', service_url='/', authenticator=NoAuthAuthenticator())
assert service.service_url == ''
assert service.service_url == '/'
service.set_service_url('/')
assert service.service_url == ''
with pytest.raises(ValueError): # ValueError thrown because service_url is '' and falsey
req = service.prepare_request('POST',
url='/',
headers={'X-opt-out': True},
data={'hello': 'world'})
assert service.service_url == '/'
req = service.prepare_request('POST',
url='/',
headers={'X-opt-out': True},
data={'hello': 'world'})
assert req.get('url') == '/'

def test_service_url_not_set():
service = BaseService(service_url='', authenticator=NoAuthAuthenticator())
Expand Down

0 comments on commit c960b7d

Please sign in to comment.