Skip to content

Commit

Permalink
Added X-Total-Count test asserts
Browse files Browse the repository at this point in the history
Fixed issue with incorrect total count for vendors
  • Loading branch information
Donkie committed Sep 8, 2023
1 parent b36bd83 commit 3f2af9b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spoolman/database/filament.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def find(
total_count = None

if limit is not None:
total_count_stmt = stmt.with_only_columns(func.count())
total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True)
total_count = (await db.execute(total_count_stmt)).scalar()

stmt = stmt.offset(offset).limit(limit)
Expand Down
2 changes: 1 addition & 1 deletion spoolman/database/spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def find(
total_count = None

if limit is not None:
total_count_stmt = stmt.with_only_columns(func.count())
total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True)
total_count = (await db.execute(total_count_stmt)).scalar()

stmt = stmt.offset(offset).limit(limit)
Expand Down
2 changes: 1 addition & 1 deletion spoolman/database/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def find(
total_count = None

if limit is not None:
total_count_stmt = stmt.with_only_columns(func.count())
total_count_stmt = stmt.with_only_columns(func.count(), maintain_column_froms=True)
total_count = (await db.execute(total_count_stmt)).scalar()

stmt = stmt.offset(offset).limit(limit)
Expand Down
5 changes: 5 additions & 0 deletions tests_integration/tests/filament/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_find_all_filaments_limit_asc(filaments: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
filaments_result = result.json()
assert len(filaments_result) == 2
assert filaments_result == [filaments.filaments[0], filaments.filaments[1]]
Expand All @@ -176,6 +177,7 @@ def test_find_all_filaments_limit_desc(filaments: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
filaments_result = result.json()
assert len(filaments_result) == 2
assert filaments_result == [filaments.filaments[-1], filaments.filaments[-2]]
Expand All @@ -187,6 +189,7 @@ def test_find_all_filaments_limit_asc_offset(filaments: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
filaments_result = result.json()
assert len(filaments_result) == 2
assert filaments_result == [filaments.filaments[1], filaments.filaments[2]]
Expand All @@ -198,6 +201,7 @@ def test_find_all_filaments_limit_desc_offset(filaments: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
filaments_result = result.json()
assert len(filaments_result) == 2
assert filaments_result == [filaments.filaments[-2], filaments.filaments[-3]]
Expand All @@ -209,6 +213,7 @@ def test_find_all_filaments_limit_asc_offset_outside_range(filaments: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
filaments_result = result.json()
assert len(filaments_result) == 0

Expand Down
5 changes: 5 additions & 0 deletions tests_integration/tests/spool/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_find_all_spools_limit_asc(spools: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "4"
spools_result = result.json()
assert len(spools_result) == 2
assert spools_result == [spools.spools[0], spools.spools[1]]
Expand All @@ -173,6 +174,7 @@ def test_find_all_spools_limit_desc(spools: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "4"
spools_result = result.json()
assert len(spools_result) == 2
assert spools_result == [spools.spools[-1], spools.spools[-2]]
Expand All @@ -184,6 +186,7 @@ def test_find_all_spools_limit_asc_offset(spools: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
spools_result = result.json()
assert len(spools_result) == 2
assert spools_result == [spools.spools[1], spools.spools[2]]
Expand All @@ -195,6 +198,7 @@ def test_find_all_spools_limit_desc_offset(spools: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "5"
spools_result = result.json()
assert len(spools_result) == 2
assert spools_result == [spools.spools[-2], spools.spools[-3]]
Expand All @@ -206,6 +210,7 @@ def test_find_all_spools_limit_asc_offset_outside_range(spools: Fixture): # noq
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "4"
spools_result = result.json()
assert len(spools_result) == 0

Expand Down
5 changes: 5 additions & 0 deletions tests_integration/tests/vendor/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_find_all_vendors_limit_asc(vendors: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "3"
vendors_result = result.json()
assert len(vendors_result) == 2
assert vendors_result == [vendors.vendors[0], vendors.vendors[1]]
Expand All @@ -104,6 +105,7 @@ def test_find_all_vendors_limit_desc(vendors: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "3"
vendors_result = result.json()
assert len(vendors_result) == 2
assert vendors_result == [vendors.vendors[-1], vendors.vendors[-2]]
Expand All @@ -115,6 +117,7 @@ def test_find_all_vendors_limit_asc_offset(vendors: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "3"
vendors_result = result.json()
assert len(vendors_result) == 2
assert vendors_result == [vendors.vendors[1], vendors.vendors[2]]
Expand All @@ -126,6 +129,7 @@ def test_find_all_vendors_limit_desc_offset(vendors: Fixture):
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "3"
vendors_result = result.json()
assert len(vendors_result) == 2
assert vendors_result == [vendors.vendors[-2], vendors.vendors[-3]]
Expand All @@ -137,6 +141,7 @@ def test_find_all_vendors_limit_asc_offset_outside_range(vendors: Fixture): # n
result.raise_for_status()

# Verify
assert result.headers["X-Total-Count"] == "3"
vendors_result = result.json()
assert len(vendors_result) == 0

Expand Down

0 comments on commit 3f2af9b

Please sign in to comment.