Introduce product details table
This commit is contained in:
@@ -12,6 +12,7 @@ from allmende_payment_system.models import (
|
||||
Area,
|
||||
Permission,
|
||||
Product,
|
||||
ProductDetails,
|
||||
User,
|
||||
UserGroup,
|
||||
)
|
||||
@@ -219,9 +220,49 @@ def test_add_product(test_db, client, admin_user):
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert response.status_code == 303
|
||||
product = test_db.execute(
|
||||
select(Product).where(Product.name == "Test Product")
|
||||
).scalar()
|
||||
product = test_db.execute(select(Product)).scalar()
|
||||
assert product is not None
|
||||
assert product.name == "Test Product"
|
||||
assert product.price == Decimal("9.99")
|
||||
assert len(product.details_history) == 1
|
||||
assert product.current_details.name == "Test Product"
|
||||
assert product.current_details.price == Decimal("9.99")
|
||||
|
||||
|
||||
def test_change_product(test_db, client, admin_user):
|
||||
area = Area(name="Test Area", description="An area for testing")
|
||||
test_db.add(area)
|
||||
product = Product(
|
||||
area=area,
|
||||
)
|
||||
product.details_history.append(
|
||||
ProductDetails(
|
||||
name="Test Product",
|
||||
price=Decimal("9.99"),
|
||||
unit_of_measure="piece",
|
||||
vat_rate=Decimal("19.00"),
|
||||
)
|
||||
)
|
||||
test_db.add(product)
|
||||
test_db.flush()
|
||||
|
||||
response = client.post(
|
||||
f"/admin/products/edit/{product.id}",
|
||||
data={
|
||||
"name": "Updated Product",
|
||||
"vat_rate": "7.00",
|
||||
"unit_of_measure": "kg",
|
||||
"price": 19.99,
|
||||
"area_id": area.id,
|
||||
},
|
||||
user=admin_user,
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert response.status_code == 303
|
||||
|
||||
updated_product = test_db.execute(
|
||||
select(Product).where(Product.id == product.id)
|
||||
).scalar()
|
||||
|
||||
assert len(updated_product.details_history) == 2
|
||||
assert updated_product.current_details.name == "Updated Product"
|
||||
assert updated_product.current_details.price == Decimal("19.99")
|
||||
assert updated_product.current_details.price == Decimal("19.99")
|
||||
|
||||
Reference in New Issue
Block a user