From fe5e4eab86a44dc0b1c704b5c90612ed7ebf05cd Mon Sep 17 00:00:00 2001 From: Pankaj Singh <98807258+pankajastro@users.noreply.github.com> Date: Mon, 27 May 2024 20:32:22 +0530 Subject: [PATCH] Set correct default_conn_name in class (#95) --- fivetran_provider_async/hooks.py | 2 +- fivetran_provider_async/operators.py | 2 +- fivetran_provider_async/sensors.py | 2 +- tests/hooks/test_fivetran.py | 3 ++- tests/operators/test_fivetran.py | 10 ++++++++++ tests/sensors/test_fivetran.py | 3 ++- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fivetran_provider_async/hooks.py b/fivetran_provider_async/hooks.py index 8a07ed1..d5a15b7 100644 --- a/fivetran_provider_async/hooks.py +++ b/fivetran_provider_async/hooks.py @@ -84,7 +84,7 @@ def _get_airflow_version() -> str: def __init__( self, - fivetran_conn_id: str = "fivetran", + fivetran_conn_id: str = "fivetran_default", fivetran_conn: Connection | None = None, timeout_seconds: int = 180, retry_limit: int = 3, diff --git a/fivetran_provider_async/operators.py b/fivetran_provider_async/operators.py index 87fb7a8..7003415 100644 --- a/fivetran_provider_async/operators.py +++ b/fivetran_provider_async/operators.py @@ -62,7 +62,7 @@ def __init__( self, connector_id: str, run_name: Optional[str] = None, - fivetran_conn_id: str = "fivetran", + fivetran_conn_id: str = "fivetran_default", fivetran_retry_limit: int = 3, fivetran_retry_delay: int = 1, poll_frequency: int = 15, diff --git a/fivetran_provider_async/sensors.py b/fivetran_provider_async/sensors.py index 364f6fb..0f268c6 100644 --- a/fivetran_provider_async/sensors.py +++ b/fivetran_provider_async/sensors.py @@ -80,7 +80,7 @@ class FivetranSensor(BaseSensorOperator): def __init__( self, connector_id: str, - fivetran_conn_id: str = "fivetran", + fivetran_conn_id: str = "fivetran_default", poke_interval: int = 60, fivetran_retry_limit: int = 3, fivetran_retry_delay: int = 1, diff --git a/tests/hooks/test_fivetran.py b/tests/hooks/test_fivetran.py index e5d4cd7..b1398c2 100644 --- a/tests/hooks/test_fivetran.py +++ b/tests/hooks/test_fivetran.py @@ -251,10 +251,11 @@ class TestFivetranHookAsync: @mock.patch("fivetran_provider_async.hooks.FivetranHookAsync._do_api_call_async") async def test_fivetran_hook_get_connector_async(self, mock_api_call_async_response): """Tests that the get_connector_async method fetches the details of a connector""" - hook = FivetranHookAsync(fivetran_conn_id="conn_fivetran") + hook = FivetranHookAsync() mock_api_call_async_response.return_value = MOCK_FIVETRAN_RESPONSE_PAYLOAD_SHEETS result = await hook.get_connector_async(connector_id="interchangeable_revenge") assert result["status"]["setup_state"] == "connected" + assert hook.conn_id == hook.default_conn_name @pytest.mark.asyncio @mock.patch("fivetran_provider_async.hooks.FivetranHookAsync._do_api_call_async") diff --git a/tests/operators/test_fivetran.py b/tests/operators/test_fivetran.py index 46dedb3..7b62e23 100644 --- a/tests/operators/test_fivetran.py +++ b/tests/operators/test_fivetran.py @@ -6,6 +6,7 @@ import requests_mock from airflow.exceptions import AirflowException, TaskDeferred +from fivetran_provider_async.hooks import FivetranHook from fivetran_provider_async.operators import FivetranOperator from tests.common.static import ( MOCK_FIVETRAN_DESTINATIONS_RESPONSE_PAYLOAD_SHEETS, @@ -185,3 +186,12 @@ def test_fivetran_operator_get_openlineage_facets_on_start(self, m): assert schema_field.name == "column_1_dest" assert schema_field.type == "VARCHAR(256)" assert schema_field.description is None + + def test_default_conn_name(self): + task = FivetranOperator( + task_id="fivetran_op_async", + connector_id="interchangeable_revenge", + reschedule_wait_time=60, + schedule_type="manual", + ) + assert task.fivetran_conn_id == FivetranHook.default_conn_name diff --git a/tests/sensors/test_fivetran.py b/tests/sensors/test_fivetran.py index abf2f43..36f61ed 100644 --- a/tests/sensors/test_fivetran.py +++ b/tests/sensors/test_fivetran.py @@ -4,6 +4,7 @@ import pytest from airflow.exceptions import AirflowException, TaskDeferred +from fivetran_provider_async.hooks import FivetranHook from fivetran_provider_async.sensors import FivetranSensor from fivetran_provider_async.triggers import FivetranTrigger @@ -63,13 +64,13 @@ def test_fivetran_sensor_async(self, mock_poke): mock_poke.return_value = False task = FivetranSensor( task_id=TASK_ID, - fivetran_conn_id="fivetran_default", connector_id="test_connector", poke_interval=5, ) with pytest.raises(TaskDeferred) as exc: task.execute(context) assert isinstance(exc.value.trigger, FivetranTrigger), "Trigger is not a FivetranTrigger" + assert task.fivetran_conn_id == FivetranHook.default_conn_name @mock.patch("fivetran_provider_async.sensors.FivetranSensor.poke") def test_fivetran_sensor_async_with_response_wait_time(self, mock_poke):