diff --git a/airbyte-cdk/python/airbyte_cdk/sources/utils/schema_helpers.py b/airbyte-cdk/python/airbyte_cdk/sources/utils/schema_helpers.py index 85726f11a38a..b33fb8b76afa 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/utils/schema_helpers.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/utils/schema_helpers.py @@ -27,11 +27,11 @@ import os import pkgutil import sys -from logging import Logger from typing import Any, Dict, Mapping import pkg_resources +from airbyte_cdk.logger import AirbyteLogger from airbyte_cdk.models import ConnectorSpecification from jsonschema import RefResolver, validate from jsonschema.exceptions import ValidationError @@ -131,10 +131,10 @@ def get_schema(self, name: str) -> dict: return raw_schema -def check_config_against_spec_or_exit(config: Mapping[str, Any], spec: ConnectorSpecification, logger: Logger): +def check_config_against_spec_or_exit(config: Mapping[str, Any], spec: ConnectorSpecification, logger: AirbyteLogger): """ Check config object against spec. In case of spec is invalid, throws - SystemExit exception causeing application to make system exit call with + SystemExit exception causing application to make system exit call with errorcode 1 :param config - config loaded from file specified over command line :param spec - spec object generated by connector diff --git a/airbyte-cdk/python/unit_tests/destinations/test_destination.py b/airbyte-cdk/python/unit_tests/destinations/test_destination.py index cb04eca0d0e3..a9d604aa4288 100644 --- a/airbyte-cdk/python/unit_tests/destinations/test_destination.py +++ b/airbyte-cdk/python/unit_tests/destinations/test_destination.py @@ -179,8 +179,9 @@ def test_run_check(self, mocker, destination: Destination, tmp_path): parsed_args = argparse.Namespace(**args) destination.run_cmd(parsed_args) - - mocker.patch.object(destination, "spec", return_value=ConnectorSpecification(connectionSpecification={})) + spec_msg = ConnectorSpecification(connectionSpecification={}) + mocker.patch.object(destination, "spec", return_value=spec_msg) + validate_mock = mocker.patch("airbyte_cdk.destinations.destination.check_config_against_spec_or_exit") expected_check_result = AirbyteConnectionStatus(status=Status.SUCCEEDED) mocker.patch.object(destination, "check", return_value=expected_check_result, autospec=True) @@ -190,6 +191,8 @@ def test_run_check(self, mocker, destination: Destination, tmp_path): destination.check.assert_called_once() # type: ignore # Affirm to Mypy that this is indeed a method on this mock destination.check.assert_called_with(logger=ANY, config=dummy_config) # type: ignore + # Check if config validation has been called + validate_mock.assert_called_with(dummy_config, spec_msg, destination.logger) # verify output was correct assert _wrapped(expected_check_result) == returned_check_result @@ -217,7 +220,9 @@ def test_run_write(self, mocker, destination: Destination, tmp_path, monkeypatch mocker.patch.object( destination, "write", return_value=iter(expected_write_result), autospec=True # convert to iterator to mimic real usage ) - mocker.patch.object(destination, "spec", return_value=ConnectorSpecification(connectionSpecification={})) + spec_msg = ConnectorSpecification(connectionSpecification={}) + mocker.patch.object(destination, "spec", return_value=spec_msg) + validate_mock = mocker.patch("airbyte_cdk.destinations.destination.check_config_against_spec_or_exit") # mock input is a record followed by some state messages mocked_input: List[AirbyteMessage] = [_wrapped(_record("s1", {"k1": "v1"})), *expected_write_result] mocked_stdin_string = "\n".join([record.json(exclude_unset=True) for record in mocked_input]) @@ -238,6 +243,8 @@ def test_run_write(self, mocker, destination: Destination, tmp_path, monkeypatch # that iterates over two iterables to check equality input_messages=OrderedIterableMatcher(mocked_input), ) + # Check if config validation has been called + validate_mock.assert_called_with(dummy_config, spec_msg, destination.logger) # verify output was correct assert expected_write_result == returned_write_result