Skip to content

Commit

Permalink
SNOW-1011766: Removing error coloring that interfered with equality c…
Browse files Browse the repository at this point in the history
…hecks in testing
  • Loading branch information
sfc-gh-davwang committed Feb 7, 2024
1 parent 8b1cb3b commit 9658712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/snowflake/cli/plugins/spcs/image_repository/manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Dict
from urllib.parse import urlparse

import click
from click import ClickException
from snowflake.cli.api.project.util import (
escape_like_pattern,
Expand Down Expand Up @@ -39,14 +38,13 @@ def get_repository_row(self, repo_name: str) -> Dict:
)
results = result_set.fetchall()

colored_repo_name = click.style(f"'{repo_name}'", fg="green")
if len(results) == 0:
raise ClickException(
f"Image repository {colored_repo_name} does not exist in database {self.get_database()} and schema {self.get_schema()} or not authorized."
f"Image repository '{repo_name}' does not exist in database '{self.get_database()}' and schema '{self.get_schema()}' or not authorized."
)
elif len(results) > 1:
raise ClickException(
f"Found more than one image repository with name matching {colored_repo_name}. This is unexpected."
f"Found more than one image repository with name matching '{repo_name}'. This is unexpected."
)
return results[0]

Expand Down
15 changes: 11 additions & 4 deletions tests/spcs/test_image_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ def test_get_repository_row(mock_execute, mock_cursor):
@mock.patch(
"snowflake.cli.plugins.spcs.image_repository.manager.ImageRepositoryManager._conn"
)
def test_get_repository_row_no_repo_found(mock_execute, mock_connection, mock_cursor):
def test_get_repository_row_no_repo_found(mock_conn, mock_execute, mock_cursor):
mock_execute.return_value = mock_cursor(
rows=[],
columns=MOCK_COLUMNS,
)

mock_conn.database = "DB"
mock_conn.schema = "SCHEMA"
with pytest.raises(ClickException) as expected_error:
ImageRepositoryManager().get_repository_row("IMAGES")
assert "does not exist in database" in expected_error.value.message
assert (
"Image repository 'IMAGES' does not exist in database 'DB' and schema 'SCHEMA' or not authorized."
== expected_error.value.message
)


@mock.patch(
Expand All @@ -173,7 +177,10 @@ def test_get_repository_row_more_than_one_repo(mock_execute, mock_cursor):
)
with pytest.raises(ClickException) as expected_error:
ImageRepositoryManager().get_repository_row("IMAGES")
assert "Found more than one image repository" in expected_error.value.message
assert (
"Found more than one image repository with name matching 'IMAGES'. This is unexpected."
== expected_error.value.message
)


@mock.patch(
Expand Down

0 comments on commit 9658712

Please sign in to comment.