Skip to content

Commit

Permalink
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 9, 2023
1 parent 14d5e0b commit f8ad2ae
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions tests/profiles/athena/test_athena_access_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
token="my_aws_assumed_token",
)


class MockAwsGenericHook:
def get_connection() -> ReadOnlyCredentials:
return mock_assumed_credentials


with patch(
"airflow.providers.amazon.aws.hooks.base_aws.AwsGenericHook",
return_value=MockAwsGenericHook,
):

@pytest.fixture()
def mock_athena_assume_role_conn(): # type: ignore
"""
Expand All @@ -48,7 +51,6 @@ def mock_athena_assume_role_conn(): # type: ignore
with patch("airflow.hooks.base.BaseHook.get_connection", return_value=conn):
yield conn


@pytest.fixture()
def mock_athena_conn(): # type: ignore
"""
Expand All @@ -74,7 +76,6 @@ def mock_athena_conn(): # type: ignore
with patch("airflow.hooks.base.BaseHook.get_connection", return_value=conn):
yield conn


def test_athena_connection_claiming() -> None:
"""
Tests that the Athena profile mapping claims the correct connection type.
Expand Down Expand Up @@ -102,8 +103,6 @@ def test_athena_connection_claiming() -> None:
),
}



# if we're missing any of the values, it shouldn't claim
for key in potential_values:
values = potential_values.copy()
Expand All @@ -123,29 +122,25 @@ def test_athena_connection_claiming() -> None:
profile_mapping = AthenaAccessKeyProfileMapping(conn, {})
assert profile_mapping.can_claim_connection()


def test_athena_profile_mapping_selected(
mock_athena_conn: Connection,
) -> None:
"""
Tests that the correct profile mapping is selected for Athena.
"""


profile_mapping = get_automatic_profile_mapping(
mock_athena_conn.conn_id,
)
assert isinstance(profile_mapping, AthenaAccessKeyProfileMapping)


def test_athena_profile_args(
mock_athena_conn: Connection,
) -> None:
"""
Tests that the profile values get set correctly for Athena.
"""


profile_mapping = get_automatic_profile_mapping(
mock_athena_conn.conn_id,
)
Expand All @@ -161,18 +156,20 @@ def test_athena_profile_args(
"schema": mock_athena_conn.extra_dejson.get("schema"),
}


def test_athena_profile_args_overrides(
mock_athena_conn: Connection,
) -> None:
"""
Tests that you can override the profile values for Athena.
"""


profile_mapping = get_automatic_profile_mapping(
mock_athena_conn.conn_id,
profile_args={"schema": "my_custom_schema", "database": "my_custom_db", "aws_session_token": "override_token"},
profile_args={
"schema": "my_custom_schema",
"database": "my_custom_db",
"aws_session_token": "override_token",
},
)

assert profile_mapping.profile_args == {
Expand All @@ -192,15 +189,13 @@ def test_athena_profile_args_overrides(
"schema": "my_custom_schema",
}


def test_athena_profile_env_vars(
mock_athena_conn: Connection,
) -> None:
"""
Tests that the environment variables get set correctly for Athena.
"""


profile_mapping = get_automatic_profile_mapping(
mock_athena_conn.conn_id,
)
Expand All @@ -210,13 +205,11 @@ def test_athena_profile_env_vars(
"COSMOS_CONN_AWS_AWS_SESSION_TOKEN": mock_athena_conn.extra_dejson.get("aws_session_token"),
}


def test_athena_profile_assume_role(mock_athena_assume_role_conn: Connection) -> None:
"""
Tests that the profile values get set correctly for Athena.
"""


profile_mapping = get_automatic_profile_mapping(
mock_athena_assume_role_conn.conn_id,
)
Expand Down

0 comments on commit f8ad2ae

Please sign in to comment.