Skip to content

Commit

Permalink
SNOW-1011774: Adding unit tests for _scope_callback, integration test…
Browse files Browse the repository at this point in the history
…s for 'object list' with scope
  • Loading branch information
sfc-gh-davwang committed Jan 31, 2024
1 parent b932b2a commit 87c88bc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/snowflake/cli/plugins/snowpark/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ def _check_if_all_defined_integrations_exists(
):
existing_integrations = {
i["name"].lower()
for i in om.show(
object_type="integration",
cursor_class=DictCursor,
like=None,
scope=(None, None),
)
for i in om.show(object_type="integration", cursor_class=DictCursor, like=None)
if i["type"] == "EXTERNAL_ACCESS"
}
declared_integration: Set[str] = set()
Expand Down
28 changes: 28 additions & 0 deletions tests/object/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest
from snowflake.cli.api.constants import SUPPORTED_OBJECTS, OBJECT_TO_NAMES
from snowflake.cli.plugins.object.commands import _scope_callback
from click import ClickException


@mock.patch("snowflake.connector.connect")
Expand Down Expand Up @@ -116,6 +118,32 @@ def test_show_with_invalid_scope(
assert expected in result.output


@pytest.mark.parametrize(
"input_scope, input_name",
[
(None, None),
("database", "test_db"),
("schema", "test_schema"),
("compute-pool", "test_pool"),
],
)
def test_scope_callback(input_scope, input_name):
assert (input_scope, input_name) == _scope_callback((input_scope, input_name))


@pytest.mark.parametrize(
"input_scope, input_name",
[
("database", "invalid identifier"),
("invalid_scope", "identifier"),
("invalid_scope", "invalid identifier"),
],
)
def test_invalid_scope_callback(input_scope, input_name):
with pytest.raises(ClickException):
_scope_callback((input_scope, input_name))


@mock.patch("snowflake.connector")
@pytest.mark.parametrize("object_type, object_name", TEST_OBJECTS)
def test_describe(
Expand Down
29 changes: 29 additions & 0 deletions tests_integration/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ def test_object_table(runner, test_database, snowflake_session):
assert (
len(row_from_cursor(snowflake_session.execute_string(f"show tables")[-1])) == 0
)


@pytest.mark.integration
def test_list_with_scope(runner, test_database, snowflake_session):
# create a table in a schema other than schema of the current connection
other_schema = "other_schema"
public_table = ObjectNameProvider(
"Test_Object_Table"
).create_and_get_next_object_name()
other_table = object_name = ObjectNameProvider(
"Test_Object_Table"
).create_and_get_next_object_name()
snowflake_session.execute_string(
f"use schema public; create table {public_table} (some_number NUMBER);"
)
snowflake_session.execute_string(
f"create schema {other_schema}; create table {other_table} (some_number NUMBER);"
)
result_list_public = runner.invoke_with_connection_json(
["object", "list", "table", "--schema", "public"]
)
assert result_list_public.exit_code == 0, result_list_public.output
assert result_list_public.json[0]["name"].lower() == public_table.lower()

result_list_other = runner.invoke_with_connection_json(
["object", "list", "table", "--schema", "other_schema"]
)
assert result_list_other.exit_code == 0, result_list_other.output
assert result_list_other.json[0]["name"].lower() == other_table.lower()

0 comments on commit 87c88bc

Please sign in to comment.