|
20 | 20 | from typing import Any |
21 | 21 |
|
22 | 22 | import asyncpg |
| 23 | +import pytest |
23 | 24 | import sqlalchemy |
24 | 25 | import sqlalchemy.ext.asyncio |
25 | 26 |
|
@@ -283,3 +284,52 @@ async def test_lazy_connection_with_asyncpg() -> None: |
283 | 284 | assert res[0][0] == 1 |
284 | 285 |
|
285 | 286 | await connector.close_async() |
| 287 | + |
| 288 | + |
| 289 | +async def test_AIDE_sqlalchemy_connection_with_asyncpg() -> None: |
| 290 | + """Basic test to get time from database using AIDE instance.""" |
| 291 | + if "POSTGRES_AIDE_CONNECTION_NAME" not in os.environ: |
| 292 | + pytest.skip("POSTGRES_AIDE_CONNECTION_NAME not set") |
| 293 | + inst_conn_name = os.environ["POSTGRES_AIDE_CONNECTION_NAME"] |
| 294 | + user = os.environ.get("POSTGRES_AIDE_USER", os.environ.get("POSTGRES_USER", "postgres")) |
| 295 | + password = os.environ.get("POSTGRES_AIDE_PASS", os.environ.get("POSTGRES_PASS", "")) |
| 296 | + db = os.environ.get("POSTGRES_AIDE_DB", os.environ.get("POSTGRES_DB", "postgres")) |
| 297 | + |
| 298 | + pool, connector = await create_sqlalchemy_engine( |
| 299 | + inst_conn_name, |
| 300 | + user, |
| 301 | + password, |
| 302 | + db, |
| 303 | + ip_type="sqldata", |
| 304 | + ) |
| 305 | + |
| 306 | + async with pool.connect() as conn: |
| 307 | + res = (await conn.execute(sqlalchemy.text("SELECT 1"))).fetchone() |
| 308 | + assert res[0] == 1 |
| 309 | + |
| 310 | + await connector.close_async() |
| 311 | + |
| 312 | + |
| 313 | +async def test_AIDE_connection_with_asyncpg() -> None: |
| 314 | + """Basic test to get time from database using AIDE instance.""" |
| 315 | + if "POSTGRES_AIDE_CONNECTION_NAME" not in os.environ: |
| 316 | + pytest.skip("POSTGRES_AIDE_CONNECTION_NAME not set") |
| 317 | + inst_conn_name = os.environ["POSTGRES_AIDE_CONNECTION_NAME"] |
| 318 | + user = os.environ.get("POSTGRES_AIDE_USER", os.environ.get("POSTGRES_USER", "postgres")) |
| 319 | + password = os.environ.get("POSTGRES_AIDE_PASS", os.environ.get("POSTGRES_PASS", "")) |
| 320 | + db = os.environ.get("POSTGRES_AIDE_DB", os.environ.get("POSTGRES_DB", "postgres")) |
| 321 | + |
| 322 | + pool, connector = await create_asyncpg_pool( |
| 323 | + inst_conn_name, |
| 324 | + user, |
| 325 | + password, |
| 326 | + db, |
| 327 | + ip_type="sqldata", |
| 328 | + ) |
| 329 | + |
| 330 | + async with pool.acquire() as conn: |
| 331 | + res = await conn.fetch("SELECT 1") |
| 332 | + assert res[0][0] == 1 |
| 333 | + |
| 334 | + await connector.close_async() |
| 335 | + |
0 commit comments