-
Notifications
You must be signed in to change notification settings - Fork 58
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
+23
−7
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c68e154
add quotes for 'use' sql queries
sfc-gh-pczajka b24f5df
update release notes
sfc-gh-pczajka 695bdc0
review fix
sfc-gh-pczajka 5f0ef74
review fix
sfc-gh-pczajka afe69cf
Merge branch 'main' into SNOW-1292755-fix-dashes-in-connection-specif…
sfc-gh-pczajka 9c08030
fix schema override in connections test
sfc-gh-pczajka 3203d36
review fix
sfc-gh-pczajka 62f0157
fix unit tests
sfc-gh-pczajka 5f03961
fix unit tests
sfc-gh-pczajka 5dfcfb7
fix integration tests
sfc-gh-pczajka 4d87149
Merge branch 'main' into SNOW-1292755-fix-dashes-in-connection-specif…
sfc-gh-pczajka 0ad98c6
Merge branch 'SNOW-1292755-fix-dashes-in-connection-specification' in…
sfc-gh-pczajka 3de504c
merge fixes
sfc-gh-pczajka 08ba876
Merge branch 'main' into SNOW-1313805-fix-connection-test
sfc-gh-pczajka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,3 @@ | |
[connections.integration] | ||
schema = "public" | ||
role = "INTEGRATION_TESTS" | ||
|
||
[cli.features] | ||
enable_snowgit = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,51 @@ | |
import pytest | ||
from snowflake import connector | ||
from snowflake.cli.api.exceptions import EnvironmentVariableNotFoundError | ||
from contextlib import contextmanager | ||
|
||
_ENV_PARAMETER_PREFIX = "SNOWFLAKE_CONNECTIONS_INTEGRATION" | ||
SCHEMA_ENV_PARAMETER = f"{_ENV_PARAMETER_PREFIX}_SCHEMA" | ||
DATABASE_ENV_PARAMETER = f"{_ENV_PARAMETER_PREFIX}_DATABASE" | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def test_database(snowflake_session): | ||
database_name = f"db_{uuid.uuid4().hex}" | ||
def add_uuid_to_name(name: str) -> str: | ||
return f"{name}_{uuid.uuid4().hex}" | ||
|
||
|
||
@contextmanager | ||
def set_env(env_name: str, value: str): | ||
os.environ[env_name] = value | ||
yield | ||
del os.environ[env_name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #971 |
||
|
||
|
||
@contextmanager | ||
def setup_test_database(snowflake_session, database_name: str): | ||
database_name = f'"{database_name}"' | ||
snowflake_session.execute_string( | ||
f"create database {database_name}; use database {database_name}; use schema public;" | ||
) | ||
os.environ[f"{_ENV_PARAMETER_PREFIX}_DATABASE"] = database_name | ||
with set_env(DATABASE_ENV_PARAMETER, value=database_name): | ||
yield | ||
snowflake_session.execute_string(f"drop database {database_name}") | ||
|
||
|
||
@contextmanager | ||
def setup_test_schema(snowflake_session, schema_name: str): | ||
schema_name = f'"{schema_name}"' | ||
snowflake_session.execute_string( | ||
f"create schema {schema_name}; use schema {schema_name};" | ||
) | ||
with set_env(SCHEMA_ENV_PARAMETER, value=schema_name): | ||
yield | ||
snowflake_session.execute_string(f"drop schema {schema_name}") | ||
|
||
yield database_name | ||
|
||
snowflake_session.execute_string(f"drop database {database_name}") | ||
del os.environ[f"{_ENV_PARAMETER_PREFIX}_DATABASE"] | ||
@pytest.fixture(scope="function") | ||
def test_database(snowflake_session): | ||
database_name = add_uuid_to_name("db") | ||
with setup_test_database(snowflake_session, database_name): | ||
yield database_name | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from tests_integration.snowflake_connector import ( | ||
setup_test_database, | ||
setup_test_schema, | ||
add_uuid_to_name, | ||
set_env, | ||
SCHEMA_ENV_PARAMETER, | ||
) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_connection_test_simple(runner): | ||
result = runner.invoke_with_connection_json(["connection", "test"]) | ||
assert result.exit_code == 0, result.output | ||
assert result.json["Status"] == "OK" | ||
|
||
|
||
@pytest.mark.integration | ||
def test_connection_dashed_database(runner, snowflake_session): | ||
database = add_uuid_to_name("dashed-database") | ||
with setup_test_database(snowflake_session, database): | ||
result = runner.invoke_with_connection_json(["connection", "test"]) | ||
assert result.exit_code == 0, result.output | ||
assert result.json["Database"] == database | ||
|
||
|
||
@pytest.mark.integration | ||
def test_connection_dashed_schema( | ||
runner, test_database, snowflake_session, snowflake_home | ||
): | ||
schema = "dashed-schema-name" | ||
with setup_test_schema(snowflake_session, 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 set_env(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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How it was passing previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't :] - fized in #971