From d9110aa236828501c974e1a9eece0758040179fd Mon Sep 17 00:00:00 2001 From: MariusWirtz Date: Fri, 17 Dec 2021 19:55:25 +0100 Subject: [PATCH] Drop obsolute ssl argument when base_url is given Fixes #652 --- TM1py/Services/RestService.py | 11 ++++++++++- Tests/ElementService_test.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/TM1py/Services/RestService.py b/TM1py/Services/RestService.py index 68919efa..bde31235 100644 --- a/TM1py/Services/RestService.py +++ b/TM1py/Services/RestService.py @@ -152,7 +152,7 @@ def __init__(self, **kwargs): :param impersonate: Name of user to impersonate """ self._kwargs = kwargs - self._ssl = self.translate_to_boolean(kwargs['ssl']) + self._ssl = self.translate_to_boolean(kwargs.get('ssl', True)) self._address = kwargs.get('address', None) self._port = kwargs.get('port', None) self._verify = False @@ -180,6 +180,7 @@ def __init__(self, **kwargs): if 'base_url' in kwargs: self._base_url = kwargs['base_url'] + self._ssl = self._determine_ssl_based_on_base_url() else: self._base_url = "http{}://{}:{}".format( 's' if self._ssl else '', @@ -581,6 +582,14 @@ def wait_time_generator(timeout: int): while True: yield 1 + def _determine_ssl_based_on_base_url(self) -> bool: + if self._base_url.startswith("https"): + return True + elif self._base_url.startswith("http"): + return False + else: + raise ValueError(f"Invalid base_url: '{self._base_url}'") + class BytesIOSocket: """ used in urllib3_response_from_bytes method to construct urllib3 response from raw bytes diff --git a/Tests/ElementService_test.py b/Tests/ElementService_test.py index 51aa3198..f1003749 100644 --- a/Tests/ElementService_test.py +++ b/Tests/ElementService_test.py @@ -463,7 +463,7 @@ def test_execute_set_mdx_attribute_with_space(self): element_properties=None, parent_properties=None) - self.assertEqual(members, [[{'Name': '1990', 'Attributes': {'Previous Year': '1990'}}]]) + self.assertEqual(members, [[{'Name': '1990', 'Attributes': {'Previous Year': '1989'}}]]) @classmethod def tearDownClass(cls):