-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79049e5
commit 35843cb
Showing
2 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,64 @@ | ||
import pytest | ||
|
||
from psqlpy import PSQLPool | ||
from psqlpy import Cursor | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_cursor_fetch( | ||
psql_pool: PSQLPool, | ||
table_name: str, | ||
number_database_records: int, | ||
test_cursor: Cursor, | ||
) -> None: | ||
connection = await psql_pool.connection() | ||
transaction = connection.transaction() | ||
await transaction.begin() | ||
await transaction.cursor( | ||
querystring=f"SELECT * FROM {table_name}", | ||
"""Test cursor fetch with custom number of fetch.""" | ||
result = await test_cursor.fetch(fetch_number=number_database_records // 2) | ||
assert len(result.result()) == number_database_records // 2 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_cursor_fetch_next( | ||
test_cursor: Cursor, | ||
) -> None: | ||
"""Test cursor fetch next.""" | ||
result = await test_cursor.fetch_next() | ||
assert len(result.result()) == 1 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_cursor_fetch_prior( | ||
test_cursor: Cursor, | ||
) -> None: | ||
"""Test cursor fetch prior.""" | ||
result = await test_cursor.fetch_prior() | ||
assert len(result.result()) == 0 | ||
|
||
await test_cursor.fetch(fetch_number=2) | ||
result = await test_cursor.fetch_prior() | ||
assert len(result.result()) == 1 | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_cursor_fetch_first( | ||
test_cursor: Cursor, | ||
) -> None: | ||
"""Test cursor fetch first.""" | ||
fetch_first = await test_cursor.fetch(fetch_number=1) | ||
|
||
await test_cursor.fetch(fetch_number=3) | ||
|
||
first = await test_cursor.fetch_first() | ||
|
||
assert fetch_first.result() == first.result() | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_cursor_fetch_last( | ||
test_cursor: Cursor, | ||
number_database_records: int, | ||
) -> None: | ||
"""Test cursor fetch last.""" | ||
all_res = await test_cursor.fetch( | ||
fetch_number=number_database_records, | ||
) | ||
|
||
await transaction.commit() | ||
last_res = await test_cursor.fetch_last() | ||
|
||
assert all_res.result()[-1] == last_res.result()[0] |