@@ -83,6 +83,11 @@ def test_sa_crud(self, connection):
8383 (5 , "c" ),
8484 ]
8585
86+ def test_sa_crud_with_add_declare (self ):
87+ engine = sa .create_engine (config .db_url , _add_declare_for_yql_stmt_vars = True )
88+ with engine .connect () as connection :
89+ self .test_sa_crud (connection )
90+
8691
8792class TestSimpleSelect (TablesTest ):
8893 __backend__ = True
@@ -597,6 +602,57 @@ def ydb_pool(self, ydb_driver):
597602 loop .run_until_complete (session_pool .stop ())
598603
599604
605+ class TestCredentials (TestBase ):
606+ __backend__ = True
607+ __only_on__ = "yql+ydb"
608+
609+ @pytest .fixture (scope = "class" )
610+ def table_client_settings (self ):
611+ yield (
612+ ydb .TableClientSettings ()
613+ .with_native_date_in_result_sets (True )
614+ .with_native_datetime_in_result_sets (True )
615+ .with_native_timestamp_in_result_sets (True )
616+ .with_native_interval_in_result_sets (True )
617+ .with_native_json_in_result_sets (False )
618+ )
619+
620+ @pytest .fixture (scope = "class" )
621+ def driver_config_for_credentials (self , table_client_settings ):
622+ url = config .db_url
623+ endpoint = f"grpc://{ url .host } :{ url .port } "
624+ database = url .database
625+
626+ yield ydb .DriverConfig (
627+ endpoint = endpoint ,
628+ database = database ,
629+ table_client_settings = table_client_settings ,
630+ )
631+
632+ def test_ydb_credentials_good (self , table_client_settings , driver_config_for_credentials ):
633+ credentials_good = ydb .StaticCredentials (
634+ driver_config = driver_config_for_credentials ,
635+ user = "root" ,
636+ password = "1234" ,
637+ )
638+ engine = sa .create_engine (config .db_url , connect_args = {"credentials" : credentials_good })
639+ with engine .connect () as conn :
640+ result = conn .execute (sa .text ("SELECT 1 as value" ))
641+ assert result .fetchone ()
642+
643+ def test_ydb_credentials_bad (self , table_client_settings , driver_config_for_credentials ):
644+ credentials_bad = ydb .StaticCredentials (
645+ driver_config = driver_config_for_credentials ,
646+ user = "root" ,
647+ password = "56" ,
648+ )
649+ engine = sa .create_engine (config .db_url , connect_args = {"credentials" : credentials_bad })
650+ with pytest .raises (Exception ) as excinfo :
651+ with engine .connect () as conn :
652+ conn .execute (sa .text ("SELECT 1 as value" ))
653+ assert "Invalid password" in str (excinfo .value )
654+
655+
600656class TestUpsert (TablesTest ):
601657 __backend__ = True
602658
0 commit comments