Backend (FastAPI + PostgreSQL): Chargen mit MHD, FEFO-Auslagern, Einheiten-Umrechnung (Stueck/g/ml + Packungen), Open-Food-Facts-Lookup mit lokalem Fallback, JWT-Auth mit Rollen (Admin/Nutzer), erster Admin beim Setup, Einkaufsliste, Ablaufwarnung, Lagerorte, pytest fuer FEFO. Web-UI (React/Vite): Login, Dashboard, Ein-/Auslagern, Produkte, Lagerorte, Benutzerverwaltung, Einkaufsliste - rollenabhaengig. Deploy: docker-compose + install.sh (Docker-Autoinstall, Secrets), README und Roadmap fuer Schritt 2 (iOS) und Schritt 3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import pytest
|
|
|
|
from app.models import BaseUnit, Product
|
|
from app.services.units import UnitError, base_to_packages, to_base_quantity
|
|
|
|
|
|
def test_base_unit_passthrough(rice):
|
|
assert to_base_quantity(rice, 200, "g") == 200
|
|
assert to_base_quantity(rice, 200, "gramm") == 200
|
|
|
|
|
|
def test_package_conversion(rice):
|
|
# 3 Packungen * 500 g = 1500 g
|
|
assert to_base_quantity(rice, 3, "package") == 1500
|
|
assert to_base_quantity(rice, 2, "packung") == 1000
|
|
|
|
|
|
def test_wrong_unit_rejected(rice):
|
|
with pytest.raises(UnitError):
|
|
to_base_quantity(rice, 1, "ml")
|
|
|
|
|
|
def test_package_without_size_rejected():
|
|
product = Product(name="Ei", base_unit=BaseUnit.piece, package_size=None)
|
|
with pytest.raises(UnitError):
|
|
to_base_quantity(product, 1, "package")
|
|
|
|
|
|
def test_non_positive_quantity_rejected(rice):
|
|
with pytest.raises(UnitError):
|
|
to_base_quantity(rice, 0, "g")
|
|
|
|
|
|
def test_base_to_packages(rice):
|
|
assert base_to_packages(rice, 1500) == 3
|
|
product = Product(name="Ei", base_unit=BaseUnit.piece, package_size=None)
|
|
assert base_to_packages(product, 10) is None
|