Skip to content

Commit 98cd8a4

Browse files
author
kabulov kozim
committed
add tests for credentials
1 parent ba2bbc1 commit 98cd8a4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/test_core.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,57 @@ def ydb_pool(self, ydb_driver):
597597
loop.run_until_complete(session_pool.stop())
598598

599599

600+
class TestCredentials(TestBase):
601+
__backend__ = True
602+
__only_on__ = "yql+ydb"
603+
604+
@pytest.fixture(scope="class")
605+
def table_client_settings(self):
606+
yield (
607+
ydb.TableClientSettings()
608+
.with_native_date_in_result_sets(True)
609+
.with_native_datetime_in_result_sets(True)
610+
.with_native_timestamp_in_result_sets(True)
611+
.with_native_interval_in_result_sets(True)
612+
.with_native_json_in_result_sets(False)
613+
)
614+
615+
@pytest.fixture(scope="class")
616+
def driver_config_for_credentials(self, table_client_settings):
617+
url = config.db_url
618+
endpoint=f"grpc://{url.host}:{url.port}"
619+
database=url.database
620+
621+
yield ydb.DriverConfig(
622+
endpoint=endpoint,
623+
database=database,
624+
table_client_settings=table_client_settings,
625+
)
626+
627+
def test_ydb_credentials_good(self, table_client_settings, driver_config_for_credentials):
628+
credentials_good = ydb.StaticCredentials(
629+
driver_config=driver_config_for_credentials,
630+
user="root",
631+
password="1234",
632+
)
633+
engine = sa.create_engine(config.db_url, connect_args={"credentials": credentials_good})
634+
with engine.connect() as conn:
635+
result = conn.execute(sa.text("SELECT 1 as value"))
636+
assert result.fetchone()
637+
638+
def test_ydb_credentials_bad(self, table_client_settings, driver_config_for_credentials):
639+
credentials_bad = ydb.StaticCredentials(
640+
driver_config=driver_config_for_credentials,
641+
user="root",
642+
password="56",
643+
)
644+
engine = sa.create_engine(config.db_url, connect_args={"credentials": credentials_bad})
645+
with pytest.raises(Exception) as excinfo:
646+
with engine.connect() as conn:
647+
conn.execute(sa.text("SELECT 1 as value"))
648+
assert "Invalid password" in str(excinfo.value)
649+
650+
600651
class TestUpsert(TablesTest):
601652
__backend__ = True
602653

0 commit comments

Comments
 (0)