Skip to content

Commit

Permalink
fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Rezchykov committed Aug 19, 2021
1 parent 86e7457 commit e29552e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions airbyte-cdk/python/unit_tests/destinations/test_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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])
Expand All @@ -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
Expand Down

0 comments on commit e29552e

Please sign in to comment.