Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion airflow/providers/airbyte/hooks/airbyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def __init__(
async def get_headers_tenants_from_connection(self) -> tuple[dict[str, Any], str]:
"""Get Headers, tenants from the connection details."""
connection: Connection = await sync_to_async(self.get_connection)(self.http_conn_id)
base_url = connection.host
# schema defaults to HTTP
schema = connection.schema if connection.schema else "http"
base_url = f"{schema}://{connection.host}"

if connection.port:
base_url += f":{connection.port}"

if self.api_type == "config":
credentials = f"{connection.login}:{connection.password}"
Expand Down
17 changes: 17 additions & 0 deletions tests/providers/airbyte/hooks/test_airbyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ def test_submit_sync_connection(self, requests_mock):
assert resp.status_code == 200
assert resp.json() == self._mock_sync_conn_success_response_body

@pytest.mark.asyncio
@pytest.mark.parametrize(
"host, port, schema, expected_base_url, description",
[
("test-airbyte", 8001, "http", "http://test-airbyte:8001", "uri_with_port_and_schema"),
("test-airbyte", None, "https", "https://test-airbyte", "uri_with_schema"),
("test-airbyte", None, None, "http://test-airbyte", "uri_without_port_and_schema"),
],
)
async def test_get_base_url(self, host, port, schema, expected_base_url, description):
conn_id = f"test_conn_{description}"
conn = Connection(conn_id=conn_id, conn_type="airbyte", host=host, port=port, schema=schema)
hook = AirbyteHook(airbyte_conn_id=conn_id)
db.merge_conn(conn)
_, base_url = await hook.get_headers_tenants_from_connection()
assert base_url == expected_base_url

def test_get_job_status(self, requests_mock):
requests_mock.post(
self.get_job_endpoint, status_code=200, json=self._mock_job_status_success_response_body
Expand Down