1- from pytest import mark , raises
1+ from pytest import raises
22
33from firebolt .client .auth import ClientCredentials
44from firebolt .db import Connection , connect
55from firebolt .utils .exception import (
66 AccountNotFoundOrNoAccessError ,
7- FireboltDatabaseError ,
87 FireboltStructuredError ,
9- OperationalError ,
108)
119
1210
@@ -63,7 +61,7 @@ def test_engine_name_not_exists(
6361 api_endpoint : str ,
6462) -> None :
6563 """Connection properly reacts to invalid engine name error."""
66- with raises (OperationalError ) :
64+ with raises (FireboltStructuredError ) as exc_info :
6765 with connect (
6866 account_name = account_name ,
6967 engine_name = engine_name + "_________" ,
@@ -73,53 +71,39 @@ def test_engine_name_not_exists(
7371 ) as connection :
7472 connection .cursor ().execute ("show tables" )
7573
74+ assert f"Engine '{ engine_name } _________' does not exist" in str (
75+ exc_info .value
76+ ), "Invalid engine error message."
77+
7678
77- @mark .skip (reason = "Behaviour is different in prod vs dev" )
7879def test_database_not_exists (
79- engine_url : str ,
80+ engine_name : str ,
8081 database_name : str ,
8182 auth : ClientCredentials ,
82- account_name : str ,
8383 api_endpoint : str ,
84+ account_name : str ,
8485) -> None :
8586 """Connection properly reacts to invalid database error."""
8687 new_db_name = database_name + "_"
87- with connect (
88- account_name = account_name ,
89- engine_url = engine_url ,
90- database = new_db_name ,
91- auth = auth ,
92- api_endpoint = api_endpoint ,
93- ) as connection :
94- with raises ( FireboltDatabaseError ) as exc_info :
88+ with raises ( FireboltStructuredError ) as exc_info :
89+ with connect (
90+ engine_name = engine_name ,
91+ database = new_db_name ,
92+ auth = auth ,
93+ account_name = account_name ,
94+ api_endpoint = api_endpoint ,
95+ ) as connection :
9596 connection .cursor ().execute ("show tables" )
9697
97- assert (
98- str (exc_info .value )
99- == f"Engine { engine_name } is attached to { database_name } instead of { new_db_name } "
100- ), "Invalid database name error message"
98+ assert f"Database '{ new_db_name } ' does not exist or not authorized" in str (
99+ exc_info .value
100+ ), "Invalid database error message."
101101
102102
103103def test_sql_error (connection : Connection ) -> None :
104104 """Connection properly reacts to sql execution error."""
105105 with connection .cursor () as c :
106- with raises (OperationalError ) as exc_info :
107- c .execute ("select ]" )
108-
109- assert str (exc_info .value ).startswith (
110- "Error executing query"
111- ), "Invalid SQL error message"
112-
113-
114- def test_structured_error (connection_system_engine_no_db : Connection ) -> None :
115- """Connection properly reacts to structured error."""
116- with connection_system_engine_no_db .cursor () as c :
117- c .execute ("SET advanced_mode=1" )
118- c .execute ("SET enable_json_error_output_format=true" )
119-
120106 with raises (FireboltStructuredError ) as exc_info :
121- c .execute ("select 'dummy'::int " )
107+ c .execute ("select ] " )
122108
123- assert "Cannot parse string" in str (
124- exc_info .value
125- ), "Invalid structured error message"
109+ assert "syntax error" in str (exc_info .value ), "Invalid SQL error message."
0 commit comments