|
1 | 1 | import pytest
|
2 | 2 |
|
3 |
| -from psqlpy import PSQLPool |
| 3 | +from psqlpy import Cursor |
4 | 4 |
|
5 | 5 |
|
6 | 6 | @pytest.mark.anyio
|
7 | 7 | async def test_cursor_fetch(
|
8 |
| - psql_pool: PSQLPool, |
9 |
| - table_name: str, |
10 | 8 | number_database_records: int,
|
| 9 | + test_cursor: Cursor, |
11 | 10 | ) -> None:
|
12 |
| - connection = await psql_pool.connection() |
13 |
| - transaction = connection.transaction() |
14 |
| - await transaction.begin() |
15 |
| - await transaction.cursor( |
16 |
| - querystring=f"SELECT * FROM {table_name}", |
| 11 | + """Test cursor fetch with custom number of fetch.""" |
| 12 | + result = await test_cursor.fetch(fetch_number=number_database_records // 2) |
| 13 | + assert len(result.result()) == number_database_records // 2 |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.anyio |
| 17 | +async def test_cursor_fetch_next( |
| 18 | + test_cursor: Cursor, |
| 19 | +) -> None: |
| 20 | + """Test cursor fetch next.""" |
| 21 | + result = await test_cursor.fetch_next() |
| 22 | + assert len(result.result()) == 1 |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.anyio |
| 26 | +async def test_cursor_fetch_prior( |
| 27 | + test_cursor: Cursor, |
| 28 | +) -> None: |
| 29 | + """Test cursor fetch prior.""" |
| 30 | + result = await test_cursor.fetch_prior() |
| 31 | + assert len(result.result()) == 0 |
| 32 | + |
| 33 | + await test_cursor.fetch(fetch_number=2) |
| 34 | + result = await test_cursor.fetch_prior() |
| 35 | + assert len(result.result()) == 1 |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.anyio |
| 39 | +async def test_cursor_fetch_first( |
| 40 | + test_cursor: Cursor, |
| 41 | +) -> None: |
| 42 | + """Test cursor fetch first.""" |
| 43 | + fetch_first = await test_cursor.fetch(fetch_number=1) |
| 44 | + |
| 45 | + await test_cursor.fetch(fetch_number=3) |
| 46 | + |
| 47 | + first = await test_cursor.fetch_first() |
| 48 | + |
| 49 | + assert fetch_first.result() == first.result() |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.anyio |
| 53 | +async def test_cursor_fetch_last( |
| 54 | + test_cursor: Cursor, |
| 55 | + number_database_records: int, |
| 56 | +) -> None: |
| 57 | + """Test cursor fetch last.""" |
| 58 | + all_res = await test_cursor.fetch( |
| 59 | + fetch_number=number_database_records, |
17 | 60 | )
|
18 | 61 |
|
19 |
| - await transaction.commit() |
| 62 | + last_res = await test_cursor.fetch_last() |
| 63 | + |
| 64 | + assert all_res.result()[-1] == last_res.result()[0] |
0 commit comments