Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snow 1313805 fix connection test #972

Merged
merged 14 commits into from
Apr 9, 2024
Merged
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* Adding support for any source supported by `pip` in `snow snowpark`.
* Fixed version parsing for packages lookup on Snowflake Anaconda Channel
* Fix handling database/schema/role identifiers containing dashes
* Fix schema override bug in `snow connection test`

# v2.1.2

Expand Down
9 changes: 7 additions & 2 deletions src/snowflake/cli/plugins/connection/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,19 @@ def test(
# Test session attributes
om = ObjectManager()
try:
# "use database" operation changes schema to default "public",
# so to test schema set up by user we need to copy it here:
schema = conn.schema

if conn.role:
om.use(object_type=ObjectType.ROLE, name=f'"{conn.role}"')
if conn.database:
om.use(object_type=ObjectType.DATABASE, name=f'"{conn.database}"')
if conn.schema:
om.use(object_type=ObjectType.SCHEMA, name=f'"{conn.schema}"')
if schema:
om.use(object_type=ObjectType.SCHEMA, name=f'"{schema}"')
if conn.warehouse:
om.use(object_type=ObjectType.WAREHOUSE, name=f'"{conn.warehouse}"')

except ProgrammingError as err:
raise ClickException(str(err))

Expand Down
4 changes: 2 additions & 2 deletions tests_integration/snowflake_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def setup_test_database(snowflake_session, database_name: str):
snowflake_session.execute_string(
f"create database {database_name}; use database {database_name}; use schema public;"
)
with mock_single_env_var(DATABASE_ENV_PARAMETER, database_name):
with mock_single_env_var(DATABASE_ENV_PARAMETER, value=database_name):
yield
snowflake_session.execute_string(f"drop database {database_name}")

Expand All @@ -49,7 +49,7 @@ def setup_test_schema(snowflake_session, schema_name: str):
snowflake_session.execute_string(
f"create schema {schema_name}; use schema {schema_name};"
)
with mock_single_env_var(SCHEMA_ENV_PARAMETER, schema_name):
with mock_single_env_var(SCHEMA_ENV_PARAMETER, value=schema_name):
yield
snowflake_session.execute_string(f"drop schema {schema_name}")

Expand Down
16 changes: 13 additions & 3 deletions tests_integration/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
setup_test_database,
setup_test_schema,
add_uuid_to_name,
mock_single_env_var,
SCHEMA_ENV_PARAMETER,
)


Expand All @@ -23,9 +25,6 @@ def test_connection_dashed_database(runner, snowflake_session):


@pytest.mark.integration
@pytest.mark.skip(
reason="BUG: connections test command seem to override every setting with schema PUBLIC"
)
def test_connection_dashed_schema(
runner, test_database, snowflake_session, snowflake_home
):
Expand All @@ -34,3 +33,14 @@ def test_connection_dashed_schema(
result = runner.invoke_with_connection(["connection", "test", "--debug"])
assert result.exit_code == 0, result.output
assert f'use schema "{schema}"' in result.output


@pytest.mark.integration
def test_connection_not_existing_schema(
runner, test_database, snowflake_session, snowflake_home
):
schema = "schema_which_does_not_exist"
with mock_single_env_var(SCHEMA_ENV_PARAMETER, value=schema):
result = runner.invoke_with_connection(["connection", "test"])
assert result.exit_code == 1, result.output
assert "Object does not exist" in result.output
Loading