Skip to content

Commit 63ce723

Browse files
committed
Added fetch method, changed parameters annotations. Added tests
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent f25d817 commit 63ce723

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

python/tests/test_connection.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ async def test_connection_execute(
2626
assert len(conn_result.result()) == number_database_records
2727

2828

29+
async def test_connection_fetch(
30+
psql_pool: ConnectionPool,
31+
table_name: str,
32+
number_database_records: int,
33+
) -> None:
34+
"""Test that single connection can fetch queries."""
35+
connection = await psql_pool.connection()
36+
37+
conn_result = await connection.fetch(
38+
querystring=f"SELECT * FROM {table_name}",
39+
)
40+
assert isinstance(conn_result, QueryResult)
41+
assert len(conn_result.result()) == number_database_records
42+
43+
2944
async def test_connection_connection(
3045
psql_pool: ConnectionPool,
3146
) -> None:

python/tests/test_connection_pool.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ async def test_pool_execute(
4949
assert len(inner_result) == number_database_records
5050

5151

52+
async def test_pool_fetch(
53+
psql_pool: ConnectionPool,
54+
table_name: str,
55+
number_database_records: int,
56+
) -> None:
57+
"""Test that ConnectionPool can fetch queries."""
58+
select_result = await psql_pool.fetch(
59+
f"SELECT * FROM {table_name}",
60+
)
61+
62+
assert type(select_result) == QueryResult
63+
64+
inner_result = select_result.result()
65+
assert isinstance(inner_result, list)
66+
assert len(inner_result) == number_database_records
67+
68+
5269
async def test_pool_connection(
5370
psql_pool: ConnectionPool,
5471
) -> None:

python/tests/test_transaction.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ async def test_transaction_cursor(
205205
assert isinstance(cursor, Cursor)
206206

207207

208+
async def test_transaction_fetch(
209+
psql_pool: ConnectionPool,
210+
table_name: str,
211+
number_database_records: int,
212+
) -> None:
213+
"""Test that single connection can fetch queries."""
214+
connection = await psql_pool.connection()
215+
216+
async with connection.transaction() as transaction:
217+
conn_result = await transaction.fetch(
218+
querystring=f"SELECT * FROM {table_name}",
219+
)
220+
assert len(conn_result.result()) == number_database_records
221+
222+
208223
@pytest.mark.parametrize(
209224
("insert_values"),
210225
[

0 commit comments

Comments
 (0)