|
2 | 2 |
|
3 | 3 |
|
4 | 4 | def test_driver_works(driver: ydb.Driver):
|
| 5 | + """Tests the functionality of the YDB driver. |
| 6 | +
|
| 7 | + Waits for the driver to become ready and executes a simple SQL query to verify that the driver works as expected. |
| 8 | +
|
| 9 | + Args: |
| 10 | + driver (ydb.Driver): The YDB driver instance to test. |
| 11 | +
|
| 12 | + Raises: |
| 13 | + AssertionError: If the SQL query does not return the expected result. |
| 14 | + """ |
5 | 15 | driver.wait(5)
|
6 | 16 | pool = ydb.QuerySessionPool(driver)
|
7 | 17 | result = pool.execute_with_retries("SELECT 1 as cnt")
|
8 | 18 | assert result[0].rows[0].cnt == 1
|
9 | 19 |
|
10 | 20 |
|
11 |
| -def auth_with_static_credentials(endpoint: str, database: str, user: str, password: str): |
| 21 | +def auth_with_static_credentials(endpoint: str, database: str, user: str, password: str, ca_path: str): |
| 22 | + """Authenticate using static credentials. |
| 23 | +
|
| 24 | + Args: |
| 25 | + endpoint (str): Accepts a string in the format `grpcs://<node-fqdn>:2136` or `grpcs://<node-ip>:2136`. |
| 26 | + database (str): Accepts a string, the database name in the format `/Root/<database-name>`. |
| 27 | + user (str): Username. |
| 28 | + password (str): User password. |
| 29 | + ca_path (str): Path to CA cert |
| 30 | +
|
| 31 | + Notes: |
| 32 | + The argument `root_certificates` of the function `ydb.DriverConfig` takes the content of the cluster's root certificate |
| 33 | + for connecting to cluster nodes via TLS. |
| 34 | + Note that the VM from which you are connecting must be in the cluster's domain for which the CA certificate is issued. |
| 35 | + """ |
12 | 36 | driver_config = ydb.DriverConfig(
|
13 | 37 | endpoint=endpoint,
|
14 | 38 | database=database,
|
15 | 39 | credentials=ydb.StaticCredentials.from_user_password(user, password),
|
| 40 | + root_certificates=ydb.load_ydb_root_certificate(ca_path), |
16 | 41 | )
|
17 | 42 |
|
18 | 43 | with ydb.Driver(driver_config=driver_config) as driver:
|
|
0 commit comments