Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#1670): validate client config and create proper error message #2026

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading