diff --git a/src/snowflake/cli/plugins/snowpark/commands.py b/src/snowflake/cli/plugins/snowpark/commands.py index 68106b6e06..043d6cd734 100644 --- a/src/snowflake/cli/plugins/snowpark/commands.py +++ b/src/snowflake/cli/plugins/snowpark/commands.py @@ -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() diff --git a/tests/object/test_object.py b/tests/object/test_object.py index 39b8f9486d..c1b1df95f0 100644 --- a/tests/object/test_object.py +++ b/tests/object/test_object.py @@ -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") @@ -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( diff --git a/tests_integration/test_object.py b/tests_integration/test_object.py index 5c2ee8d7ca..fbd7b4e436 100644 --- a/tests_integration/test_object.py +++ b/tests_integration/test_object.py @@ -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()