Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yerzhaisang Taskali <tasqali1697@gmail.com>
  • Loading branch information
Yerzhaisang committed Nov 26, 2024
1 parent 80dc5ff commit 9ed5ebf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/ml_commons/test_model_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# GitHub history for details.

import os
import warnings

import pytest
from opensearchpy.exceptions import NotFoundError, RequestError
Expand Down Expand Up @@ -74,6 +75,27 @@ def test_create_standalone_connector(client: Connector, connector_body: dict):
client.create_standalone_connector("")


@pytest.mark.parametrize("invalid_body", ["", None, [], 123])
def test_create_standalone_connector_invalid_body(client: Connector, invalid_body):
with pytest.raises(ValueError, match="'body' must be a dictionary"):
client.create_standalone_connector(body=invalid_body)


@pytest.mark.parametrize("invalid_payload", ["", None, [], 123])
def test_create_standalone_connector_invalid_payload(
client: Connector, invalid_payload
):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
with pytest.raises(ValueError, match="'payload' must be a dictionary"):
client.create_standalone_connector(payload=invalid_payload)
assert any(
issubclass(warning.category, DeprecationWarning)
and "payload is deprecated" in str(warning.message)
for warning in w
), "A DeprecationWarning for 'payload' should have been raised."


@pytest.mark.skipif(
OPENSEARCH_VERSION < CONNECTOR_MIN_VERSION,
reason="Connectors are supported in OpenSearch 2.9.0 and above",
Expand Down

0 comments on commit 9ed5ebf

Please sign in to comment.