fix: ruff lint + format fixes in tests, ESLint fixes in frontend

This commit is contained in:
2026-07-17 21:28:58 +02:00
parent 341d0c6f38
commit fbb1b39b57
56 changed files with 1399 additions and 721 deletions
+53 -24
View File
@@ -5,9 +5,7 @@ import io
import uuid
from datetime import date
from decimal import Decimal
from unittest.mock import patch
import pytest
import pytest_asyncio
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
@@ -56,10 +54,14 @@ async def test_buyer_for_datev(db_session: AsyncSession) -> Contact:
@pytest_asyncio.fixture
async def test_completed_sales(db_session: AsyncSession, test_vehicle_for_datev, test_buyer_for_datev) -> list[Sale]:
async def test_completed_sales(
db_session: AsyncSession, test_vehicle_for_datev, test_buyer_for_datev
) -> list[Sale]:
"""Create test completed sales within a date range."""
sales = []
for i, (day, price) in enumerate([(5, Decimal("30000.00")), (10, Decimal("25000.00")), (15, Decimal("40000.00"))]):
for i, (day, price) in enumerate(
[(5, Decimal("30000.00")), (10, Decimal("25000.00")), (15, Decimal("40000.00"))]
):
sale = Sale(
vehicle_id=test_vehicle_for_datev.id,
buyer_contact_id=test_buyer_for_datev.id,
@@ -81,10 +83,13 @@ class TestDATEVExportAPI:
async def test_create_export(self, admin_client: AsyncClient, test_completed_sales):
"""POST /datev/export with valid date range returns 201."""
response = await admin_client.post("/api/v1/datev/export", json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
})
response = await admin_client.post(
"/api/v1/datev/export",
json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
},
)
assert response.status_code == 201
data = response.json()
assert data["start_date"] == "2025-01-01"
@@ -94,19 +99,25 @@ class TestDATEVExportAPI:
async def test_create_export_invalid_date_range(self, admin_client: AsyncClient):
"""POST /datev/export with start > end returns 422."""
response = await admin_client.post("/api/v1/datev/export", json={
"start_date": "2025-12-31",
"end_date": "2025-01-01",
})
response = await admin_client.post(
"/api/v1/datev/export",
json={
"start_date": "2025-12-31",
"end_date": "2025-01-01",
},
)
assert response.status_code == 422
async def test_list_exports(self, admin_client: AsyncClient, test_completed_sales):
"""GET /datev/exports returns list of exports."""
# First create an export
await admin_client.post("/api/v1/datev/export", json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
})
await admin_client.post(
"/api/v1/datev/export",
json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
},
)
response = await admin_client.get("/api/v1/datev/exports")
assert response.status_code == 200
@@ -116,13 +127,18 @@ class TestDATEVExportAPI:
assert "start_date" in data["items"][0]
assert "end_date" in data["items"][0]
async def test_download_export_csv(self, admin_client: AsyncClient, test_completed_sales):
async def test_download_export_csv(
self, admin_client: AsyncClient, test_completed_sales
):
"""GET /datev/exports/:id/download returns CSV content."""
# Create export
create_response = await admin_client.post("/api/v1/datev/export", json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
})
create_response = await admin_client.post(
"/api/v1/datev/export",
json={
"start_date": "2025-01-01",
"end_date": "2025-01-31",
},
)
assert create_response.status_code == 201
export_id = create_response.json()["id"]
@@ -145,7 +161,9 @@ class TestDATEVExportAPI:
async def test_download_export_not_found(self, admin_client: AsyncClient):
"""GET /datev/exports/:nonexistent/download returns 404."""
response = await admin_client.get(f"/api/v1/datev/exports/{uuid.uuid4()}/download")
response = await admin_client.get(
f"/api/v1/datev/exports/{uuid.uuid4()}/download"
)
assert response.status_code == 404
@@ -154,7 +172,14 @@ class TestDATEVCSVFormat:
def test_datev_csv_headers(self):
"""DATEV CSV has correct headers."""
assert DATEV_HEADERS == ["Datum", "Konto", "Gegenkonto", "Betrag", "Belegfeld", "Buchungstext"]
assert DATEV_HEADERS == [
"Datum",
"Konto",
"Gegenkonto",
"Betrag",
"Belegfeld",
"Buchungstext",
]
def test_generate_datev_csv_empty(self):
"""Generate DATEV CSV with no sales returns only headers."""
@@ -170,6 +195,7 @@ class TestDATEVCSVFormat:
def test_generate_datev_csv_with_sales(self, test_completed_sales):
"""Generate DATEV CSV with sales produces correct rows."""
# test_completed_sales is a fixture but we need to call it differently for sync test
# Instead, create mock objects
class MockVehicle:
@@ -225,6 +251,7 @@ class TestDATEVCSVFormat:
def test_datev_csv_amount_format(self):
"""DATEV CSV amount uses comma as decimal separator."""
class MockVehicle:
make = "VW"
model = "Crafter"
@@ -271,6 +298,8 @@ class TestDATEVExportService:
end_date=date(2025, 1, 31),
)
exports, total = await datev_service.list_exports(db_session, page=1, page_size=2)
exports, total = await datev_service.list_exports(
db_session, page=1, page_size=2
)
assert total >= 3
assert len(exports) <= 2