From 5fa3752d0bd6650981be524701e42a032ebb5114 Mon Sep 17 00:00:00 2001 From: Satish Chinthanippu Date: Wed, 10 Jul 2024 03:18:32 -0700 Subject: [PATCH] Teradata Profile Mapping Issue - Credentials in profile "generated_profile", target "dev" invalid: Runtime Error Must specify `schema` in Teradata profile (#1088) `TeradataUserPassword` profile mapping throws below error for mock profile ``` Credentials in profile "generated_profile", target "dev" invalid: Runtime Error Must specify the schema in Teradata profile ``` Closes https://github.com/astronomer/astronomer-cosmos/issues/1087 --- cosmos/profiles/teradata/user_pass.py | 7 +++++++ tests/profiles/teradata/test_teradata_user_pass.py | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/cosmos/profiles/teradata/user_pass.py b/cosmos/profiles/teradata/user_pass.py index 059e4a9f0..535a7c717 100644 --- a/cosmos/profiles/teradata/user_pass.py +++ b/cosmos/profiles/teradata/user_pass.py @@ -49,3 +49,10 @@ def profile(self) -> dict[str, Any]: profile["schema"] = profile["user"] return self.filter_null(profile) + + @property + def mock_profile(self) -> dict[str, Any | None]: + """Gets mock profile. Assigning user to schema as default""" + mock_profile = super().mock_profile + mock_profile["schema"] = mock_profile["user"] + return mock_profile diff --git a/tests/profiles/teradata/test_teradata_user_pass.py b/tests/profiles/teradata/test_teradata_user_pass.py index ff28977fe..795e461a4 100644 --- a/tests/profiles/teradata/test_teradata_user_pass.py +++ b/tests/profiles/teradata/test_teradata_user_pass.py @@ -96,6 +96,12 @@ def test_profile_mapping_selected( assert isinstance(profile_mapping, TeradataUserPasswordProfileMapping) +def test_profile_mapping_schema_validation(mock_teradata_conn: Connection) -> None: + # port is not handled in airflow connection so adding it as profile_args + profile = TeradataUserPasswordProfileMapping(mock_teradata_conn.conn_id) + assert profile.profile["schema"] == "my_user" + + def test_profile_mapping_keeps_port(mock_teradata_conn: Connection) -> None: # port is not handled in airflow connection so adding it as profile_args profile = TeradataUserPasswordProfileMapping(mock_teradata_conn.conn_id, profile_args={"port": 1025}) @@ -174,3 +180,6 @@ def test_mock_profile() -> None: """ profile = TeradataUserPasswordProfileMapping("mock_conn_id") assert profile.mock_profile.get("host") == "mock_value" + assert profile.mock_profile.get("user") == "mock_value" + assert profile.mock_profile.get("password") == "mock_value" + assert profile.mock_profile.get("schema") == "mock_value"