22from pytest import mark , raises
33
44from firebolt .async_db import Connection , connect
5+ from firebolt .client .auth import ServiceAccount , UsernamePassword
56from firebolt .utils .exception import (
67 AccountNotFoundError ,
7- AuthenticationError ,
88 EngineNotRunningError ,
99 FireboltDatabaseError ,
1010 FireboltEngineError ,
1111 OperationalError ,
1212)
1313
1414
15- async def test_invalid_credentials (
16- engine_url : str , database_name : str , username : str , password : str , api_endpoint : str
17- ) -> None :
18- """Connection properly reacts to invalid credentials error."""
19- async with await connect (
20- engine_url = engine_url ,
21- database = database_name ,
22- username = username + "_" ,
23- password = password + "_" ,
24- api_endpoint = api_endpoint ,
25- ) as connection :
26- with raises (AuthenticationError ) as exc_info :
27- await connection .cursor ().execute ("show tables" )
28-
29- assert str (exc_info .value ).startswith (
30- "Failed to authenticate"
31- ), "Invalid authentication error message."
32-
33-
3415async def test_invalid_account (
3516 database_name : str ,
3617 engine_name : str ,
37- username : str ,
38- password : str ,
18+ password_auth : UsernamePassword ,
3919 api_endpoint : str ,
4020) -> None :
4121 """Connection properly reacts to invalid account error."""
@@ -44,8 +24,7 @@ async def test_invalid_account(
4424 async with await connect (
4525 database = database_name ,
4626 engine_name = engine_name , # Omit engine_url to force account_id lookup.
47- username = username ,
48- password = password ,
27+ auth = password_auth ,
4928 account_name = account_name ,
5029 api_endpoint = api_endpoint ,
5130 ) as connection :
@@ -59,17 +38,15 @@ async def test_invalid_account(
5938async def test_engine_url_not_exists (
6039 engine_url : str ,
6140 database_name : str ,
62- username : str ,
63- password : str ,
41+ service_auth : ServiceAccount ,
6442 account_name : str ,
6543 api_endpoint : str ,
6644) -> None :
6745 """Connection properly reacts to invalid engine url error."""
6846 async with await connect (
6947 engine_url = engine_url + "_" ,
7048 database = database_name ,
71- username = username ,
72- password = password ,
49+ auth = service_auth ,
7350 account_name = account_name ,
7451 api_endpoint = api_endpoint ,
7552 ) as connection :
@@ -80,8 +57,7 @@ async def test_engine_url_not_exists(
8057async def test_engine_name_not_exists (
8158 engine_name : str ,
8259 database_name : str ,
83- username : str ,
84- password : str ,
60+ service_auth : ServiceAccount ,
8561 account_name : str ,
8662 api_endpoint : str ,
8763) -> None :
@@ -90,8 +66,7 @@ async def test_engine_name_not_exists(
9066 async with await connect (
9167 engine_name = engine_name + "_________" ,
9268 database = database_name ,
93- username = username ,
94- password = password ,
69+ auth = service_auth ,
9570 account_name = account_name ,
9671 api_endpoint = api_endpoint ,
9772 ) as connection :
@@ -101,8 +76,7 @@ async def test_engine_name_not_exists(
10176async def test_engine_stopped (
10277 stopped_engine_url : str ,
10378 database_name : str ,
104- username : str ,
105- password : str ,
79+ service_auth : ServiceAccount ,
10680 account_name : str ,
10781 api_endpoint : str ,
10882) -> None :
@@ -111,8 +85,7 @@ async def test_engine_stopped(
11185 async with await connect (
11286 engine_url = stopped_engine_url ,
11387 database = database_name ,
114- username = username ,
115- password = password ,
88+ auth = service_auth ,
11689 account_name = account_name ,
11790 api_endpoint = api_endpoint ,
11891 ) as connection :
@@ -121,15 +94,14 @@ async def test_engine_stopped(
12194
12295@mark .skip (reason = "Behaviour is different in prod vs dev" )
12396async def test_database_not_exists (
124- engine_url : str , database_name : str , username : str , password : str , api_endpoint : str
97+ engine_url : str , database_name : str , service_auth : ServiceAccount , api_endpoint : str
12598) -> None :
12699 """Connection properly reacts to invalid database error."""
127100 new_db_name = database_name + "_"
128101 async with await connect (
129102 engine_url = engine_url ,
130103 database = new_db_name ,
131- username = username ,
132- password = password ,
104+ auth = service_auth ,
133105 api_endpoint = api_endpoint ,
134106 ) as connection :
135107 with raises (FireboltDatabaseError ) as exc_info :
0 commit comments