Skip to content

Commit

Permalink
Set correct default_conn_name in class (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajastro authored May 27, 2024
1 parent 9e77c0f commit fe5e4ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fivetran_provider_async/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion fivetran_provider_async/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion fivetran_provider_async/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tests/hooks/test_fivetran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions tests/operators/test_fivetran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/sensors/test_fivetran.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit fe5e4ea

Please sign in to comment.