Introduce product details table

This commit is contained in:
2026-04-22 12:25:35 +02:00
parent 6e6636e941
commit e8266ffdc1
11 changed files with 416 additions and 168 deletions

View File

@@ -32,9 +32,9 @@ def create_user_with_account(test_db, username: str, balance: float | None = Non
return user
def add_finalized_order_to_user(test_db, user, product) -> Order:
def add_finalized_order_to_user(test_db, user, product: Product) -> Order:
order = Order(user=user)
total_amount = product.price
total_amount = product.current_details.price
order.items.append(
OrderItem(product=product, quantity=1, total_amount=total_amount)
)
@@ -49,7 +49,7 @@ def add_finalized_order_to_user(test_db, user, product) -> Order:
def product(test_db):
area = Area(**fake.area())
test_db.add(area)
product = Product(**fake.product())
product = Product.create(**fake.product())
product.area = area
test_db.add(product)
test_db.flush()
@@ -96,15 +96,17 @@ def test_edit_item_in_cart(client: APSTestClient, test_db, product):
cart = test_db.scalar(select(Order))
assert len(cart.items) == 1
assert cart.items[0].quantity == 3
assert cart.items[0].total_amount == product.price * 3
assert cart.items[0].total_amount == product.current_details.price * 3
def test_remove_item_from_cart(client: APSTestClient, test_db, product):
def test_remove_item_from_cart(client: APSTestClient, test_db, product: Product):
user = create_user_with_account(test_db, "test")
user.shopping_cart.items.append(
OrderItem(product=product, quantity=2, total_amount=product.price * 2)
OrderItem(
product=product, quantity=2, total_amount=product.current_details.price * 2
)
)
test_db.flush()
@@ -122,11 +124,15 @@ def test_remove_item_from_cart(client: APSTestClient, test_db, product):
assert len(test_db.scalars(select(OrderItem)).all()) == 0
def test_remove_item_from_cart_wrong_user(client: APSTestClient, test_db, product):
def test_remove_item_from_cart_wrong_user(
client: APSTestClient, test_db, product: Product
):
user = create_user_with_account(test_db, "test")
user.shopping_cart.items.append(
OrderItem(product=product, quantity=2, total_amount=product.price * 2)
OrderItem(
product=product, quantity=2, total_amount=product.current_details.price * 2
)
)
test_db.flush()
@@ -144,7 +150,7 @@ def test_remove_item_from_cart_wrong_user(client: APSTestClient, test_db, produc
assert len(cart.items) == 1
def test_finalize_order(client: APSTestClient, test_db, product):
def test_finalize_order(client: APSTestClient, test_db, product: Product):
user = create_user_with_account(test_db, "test", balance=100.0)
second_account = Account(name=f"Another account")
@@ -155,7 +161,9 @@ def test_finalize_order(client: APSTestClient, test_db, product):
user.accounts.append(second_account)
user.shopping_cart.items.append(
OrderItem(product=product, quantity=2, total_amount=product.price * 2)
OrderItem(
product=product, quantity=2, total_amount=product.current_details.price * 2
)
)
test_db.flush()
@@ -170,10 +178,12 @@ def test_finalize_order(client: APSTestClient, test_db, product):
assert len(user.orders) == 2 # shopping cart + finalized order
assert user.accounts[0].balance == Decimal(100.0)
assert user.accounts[1].balance == Decimal(50.0) - (product.price * 2)
assert user.accounts[1].balance == Decimal(50.0) - (
product.current_details.price * 2
)
def test_view_order(client: APSTestClient, test_db, product):
def test_view_order(client: APSTestClient, test_db, product: Product):
user = create_user_with_account(test_db, "test")
order = add_finalized_order_to_user(test_db, user, product)
@@ -181,10 +191,10 @@ def test_view_order(client: APSTestClient, test_db, product):
response = client.get(f"/shop/order/{order.id}")
assert response.status_code == 200
assert f"Einkauf #{order.id}" in response.text
assert product.name in response.text
assert product.current_details.name in response.text
def test_view_order_wrong_user(client: APSTestClient, test_db, product):
def test_view_order_wrong_user(client: APSTestClient, test_db, product: Product):
user = create_user_with_account(test_db, "test")
order = add_finalized_order_to_user(test_db, user, product)