From 234ba6180da404f5143607862683d213fd608f22 Mon Sep 17 00:00:00 2001 From: alafanechere Date: Fri, 2 Dec 2022 12:27:22 +0100 Subject: [PATCH] make connector_configuration_path optional in ContainerRunner --- .../utils/connector_runner.py | 7 +++---- .../unit_tests/test_container_runner.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/utils/connector_runner.py b/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/utils/connector_runner.py index b5d193bc5a6d..ef859723d229 100644 --- a/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/utils/connector_runner.py +++ b/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/utils/connector_runner.py @@ -17,7 +17,7 @@ class ConnectorRunner: - def __init__(self, image_name: str, volume: Path, connector_configuration_path: Optional[Path], should_persist_new_configurations=True): + def __init__(self, image_name: str, volume: Path, connector_configuration_path: Optional[Path] = None): self._client = docker.from_env() try: self._image = self._client.images.get(image_name) @@ -28,7 +28,6 @@ def __init__(self, image_name: str, volume: Path, connector_configuration_path: self._runs = 0 self._volume_base = volume self._connector_configuration_path = connector_configuration_path - self._should_persist_new_configurations = should_persist_new_configurations @property def output_folder(self) -> Path: @@ -182,8 +181,8 @@ def entry_point(self): return self._image.attrs["Config"]["Entrypoint"] def _persist_new_configuration(self, new_configuration: dict, configuration_emitted_at: int) -> Optional[Path]: - if not self._should_persist_new_configurations: - logging.warning("New configuration persistence is disabled. The new configuration was not persisted") + if self._connector_configuration_path is None: + logging.warning("No configuration path was passed to the ConnectorRunner. The new configuration was not persisted") return None with open(self._connector_configuration_path) as old_configuration_file: diff --git a/airbyte-integrations/bases/source-acceptance-test/unit_tests/test_container_runner.py b/airbyte-integrations/bases/source-acceptance-test/unit_tests/test_container_runner.py index 6959988fd684..eee26a3763d0 100644 --- a/airbyte-integrations/bases/source-acceptance-test/unit_tests/test_container_runner.py +++ b/airbyte-integrations/bases/source-acceptance-test/unit_tests/test_container_runner.py @@ -38,12 +38,12 @@ def test_run_call_persist_configuration(self, mocker, tmp_path): mocker.patch.object(connector_runner.ConnectorRunner, "read", mocker.Mock(return_value=records_reads)) mocker.patch.object(connector_runner.ConnectorRunner, "_persist_new_configuration") - runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path) + runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, connector_configuration_path=old_configuration_path) list(runner.run("dummy_cmd")) runner._persist_new_configuration.assert_called_once_with(new_configuration, 1) @pytest.mark.parametrize( - "should_persist_new_configurations, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration", + "pass_configuration_path, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration", [ pytest.param( True, @@ -70,17 +70,20 @@ def test_persist_new_configuration( self, mocker, tmp_path, - should_persist_new_configurations, + pass_configuration_path, old_configuration, new_configuration, new_configuration_emitted_at, expect_new_configuration, ): - old_configuration_path = tmp_path / "config.json" - with open(old_configuration_path, "w") as old_configuration_file: - json.dump(old_configuration, old_configuration_file) + if pass_configuration_path: + old_configuration_path = tmp_path / "config.json" + with open(old_configuration_path, "w") as old_configuration_file: + json.dump(old_configuration, old_configuration_file) + else: + old_configuration_path = None mocker.patch.object(connector_runner, "docker") - runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path, should_persist_new_configurations) + runner = connector_runner.ConnectorRunner("source-test:dev", tmp_path, old_configuration_path) new_configuration_path = runner._persist_new_configuration(new_configuration, new_configuration_emitted_at) if not expect_new_configuration: assert new_configuration_path is None