Skip to content

Commit

Permalink
fix(#1670): validate client config and create proper error message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bossenti authored Oct 16, 2023
1 parent b8d38da commit 857edb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions streampipes-client-python/streampipes/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class StreamPipesClient:
dataStreamApi: DataStreamEndpoint
Instance of the data stream endpoint
Raises
------
AttributeError:
In case an invalid configuration of the `StreamPipesClientConfig` is passed
Examples
--------
Expand Down Expand Up @@ -117,6 +122,15 @@ def __init__(
client_config: StreamPipesClientConfig,
logging_level: Optional[int] = logging.INFO,
):
# validate client config
# `https_disabled` and `port` 443 is an invalid configuration
if client_config.https_disabled and client_config.port == 443:
raise AttributeError(
"Invalid configuration passed! The given client configuration has "
"`https_disabled` set to `True` and `port` set to `443`.\n "
"If you want to connect to port 443, use `https_disabled=False` or "
"alternatively connect to port `80`."
)
self.client_config = client_config

# set up a requests session
Expand Down
12 changes: 12 additions & 0 deletions streampipes-client-python/tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def test_client_create(self, server_version: MagicMock):
self.assertTrue(isinstance(result.dataLakeMeasureApi, DataLakeMeasureEndpoint))
self.assertEqual(result.base_api_path, "https://localhost:443/streampipes-backend/")

def test_client_create_invalid_config(self):

with self.assertRaises(AttributeError):
StreamPipesClient.create(
client_config=StreamPipesClientConfig(
credential_provider=StreamPipesApiKeyCredentials(username="user", api_key="key"),
host_address="localhost",
https_disabled=True,
port=443,
)
)

@patch("streampipes.client.client.logger", autospec=True)
@patch("streampipes.endpoint.endpoint.APIEndpoint._make_request", autospec=True)
def test_client_describe(self, make_request: MagicMock, mocked_logger: MagicMock):
Expand Down

0 comments on commit 857edb3

Please sign in to comment.