- Item: price_cents + currency (Kaufpreis rappen-/centgenau). Migration ergaenzt. - Neue Tabelle item_documents (mehrere Belege je Stueck, PDF oder Bild); Blob wird verzoegert geladen, damit Item-Listen leicht bleiben. - Endpunkte: Upload (POST), Ansehen/Download (GET), Loeschen (DELETE) je Stueck. Dateiname beim Download gehaertet (keine Header-Injektion). - services/warranty.py: schaetzt aus PDF-Text lokal ein Garantieende (Zeitraum + Kaufdatum, oder Datum nahe Garantie-Stichwort); pypdf ergaenzt. Der Upload liefert den Vorschlag zurueck. 10 neue Tests, Suite 136 gruen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""Einzelstücke: Kaufpreis und Belege (Metadaten in der Ausgabe, Dateinamen-Härtung)."""
|
|
|
|
import pytest
|
|
|
|
from app.models import Category, CategoryTracking, Item, ItemDocument, Product, Role, User
|
|
from app.routers.items import _safe_filename, create_items, get_item
|
|
from app.schemas import ItemCreate
|
|
|
|
|
|
@pytest.fixture()
|
|
def admin(db):
|
|
person = User(username="admin", password_hash="x", role=Role.admin)
|
|
db.add(person)
|
|
db.commit()
|
|
db.refresh(person)
|
|
return person
|
|
|
|
|
|
def _product(db):
|
|
cat = Category(name="Elektronik", tracking=CategoryTracking.object.value)
|
|
db.add(cat)
|
|
db.flush()
|
|
product = Product(name="Kamera", category_id=cat.id, individual=True)
|
|
db.add(product)
|
|
db.commit()
|
|
db.refresh(product)
|
|
return product
|
|
|
|
|
|
def test_item_kaufpreis_round_trip(db, admin):
|
|
product = _product(db)
|
|
out = create_items(
|
|
product.id, ItemCreate(count=1, price_cents=49900, currency="CHF"), db=db, _=admin
|
|
)
|
|
assert out[0].price_cents == 49900
|
|
assert out[0].currency == "CHF"
|
|
|
|
|
|
def test_item_out_listet_belege(db, admin):
|
|
product = _product(db)
|
|
item_id = create_items(product.id, ItemCreate(count=1), db=db, _=admin)[0].id
|
|
db.add(ItemDocument(item_id=item_id, filename="rechnung.pdf",
|
|
content_type="application/pdf", data=b"%PDF-1.4 x"))
|
|
db.commit()
|
|
|
|
fresh = get_item(item_id, db=db, _=admin)
|
|
assert len(fresh.documents) == 1
|
|
assert fresh.documents[0].filename == "rechnung.pdf"
|
|
assert fresh.documents[0].content_type == "application/pdf"
|
|
|
|
|
|
def test_safe_filename_entfernt_header_zeichen():
|
|
assert _safe_filename('a"b\r\nc.pdf') == "abc.pdf"
|
|
assert _safe_filename(" ") == "beleg"
|
|
assert _safe_filename(None) == "beleg"
|