Skip to content

Commit ae3f8f9

Browse files
committed
add unit tests to static credentials
1 parent 257f5c4 commit ae3f8f9

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/auth/test_static_credentials.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
import ydb
3+
4+
from concurrent.futures import TimeoutError
5+
6+
7+
USERNAME = "root"
8+
PASSWORD = "1234"
9+
10+
11+
def check_driver_works(driver):
12+
driver.wait(timeout=15)
13+
pool = ydb.QuerySessionPool(driver)
14+
result = pool.execute_with_retries("SELECT 1 as cnt")
15+
assert result[0].rows[0].cnt == 1
16+
17+
18+
def test_static_credentials_default(endpoint, database):
19+
driver_config = ydb.DriverConfig(
20+
endpoint,
21+
database
22+
)
23+
credentials = ydb.StaticCredentials(driver_config, USERNAME, PASSWORD)
24+
25+
with ydb.Driver(driver_config=driver_config, credentials=credentials) as driver:
26+
check_driver_works(driver)
27+
28+
29+
def test_static_credentials_classmethod(endpoint, database):
30+
driver_config = ydb.DriverConfig(
31+
endpoint,
32+
database,
33+
credentials=ydb.StaticCredentials.from_user_password(USERNAME, PASSWORD)
34+
)
35+
36+
with ydb.Driver(driver_config=driver_config) as driver:
37+
check_driver_works(driver)
38+
39+
40+
def test_static_credentials_wrong_creds(endpoint, database):
41+
driver_config = ydb.DriverConfig(
42+
endpoint,
43+
database,
44+
credentials=ydb.StaticCredentials.from_user_password(USERNAME, PASSWORD*2)
45+
)
46+
47+
with pytest.raises(TimeoutError):
48+
with ydb.Driver(driver_config=driver_config) as driver:
49+
driver.wait(5)
50+

0 commit comments

Comments
 (0)