Skip to content

Commit 64ad166

Browse files
committed
Add tests
1 parent 559533a commit 64ad166

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_execute.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Integration tests for client.execute() DML row count reporting.
3+
4+
Verifies that execute() correctly returns the number of rows
5+
affected by INSERT, UPDATE, and DELETE statements.
6+
"""
7+
8+
from altertable_flightsql import Client
9+
from tests.conftest import TableInfo
10+
11+
12+
class TestExecuteRowCount:
13+
"""Test that execute() returns the correct number of affected rows."""
14+
15+
def test_insert_returns_row_count(self, altertable_client: Client, test_table: TableInfo):
16+
"""Test that INSERT returns the number of inserted rows."""
17+
rows = altertable_client.execute(
18+
f"INSERT INTO {test_table.full_name} (id, name, value) VALUES (4, 'Dave', 400), (5, 'Eve', 500)"
19+
)
20+
assert rows == 2
21+
22+
def test_update_returns_row_count(self, altertable_client: Client, test_table: TableInfo):
23+
"""Test that UPDATE returns the number of updated rows."""
24+
rows = altertable_client.execute(
25+
f"UPDATE {test_table.full_name} SET value = 999 WHERE value >= 200"
26+
)
27+
assert rows == 2
28+
29+
def test_delete_returns_row_count(self, altertable_client: Client, test_table: TableInfo):
30+
"""Test that DELETE returns the number of deleted rows."""
31+
rows = altertable_client.execute(
32+
f"DELETE FROM {test_table.full_name} WHERE id IN (1, 2)"
33+
)
34+
assert rows == 2
35+
36+
def test_delete_no_match_returns_zero(self, altertable_client: Client, test_table: TableInfo):
37+
"""Test that DELETE with no matching rows returns 0."""
38+
rows = altertable_client.execute(
39+
f"DELETE FROM {test_table.full_name} WHERE id = 9999"
40+
)
41+
assert rows == 0
42+
43+
def test_update_no_match_returns_zero(self, altertable_client: Client, test_table: TableInfo):
44+
"""Test that UPDATE with no matching rows returns 0."""
45+
rows = altertable_client.execute(
46+
f"UPDATE {test_table.full_name} SET value = 0 WHERE id = 9999"
47+
)
48+
assert rows == 0

0 commit comments

Comments
 (0)