Add multi account support to shpping cart
This commit is contained in:
@@ -147,19 +147,30 @@ def test_remove_item_from_cart_wrong_user(client: APSTestClient, test_db, produc
|
||||
def test_finalize_order(client: APSTestClient, test_db, product):
|
||||
|
||||
user = create_user_with_account(test_db, "test", balance=100.0)
|
||||
second_account = Account(name=f"Another account")
|
||||
second_account.transactions.append(
|
||||
Transaction(total_amount=Decimal(50.0), type="deposit")
|
||||
)
|
||||
test_db.add(second_account)
|
||||
user.accounts.append(second_account)
|
||||
|
||||
user.shopping_cart.items.append(
|
||||
OrderItem(product=product, quantity=2, total_amount=product.price * 2)
|
||||
)
|
||||
test_db.flush()
|
||||
|
||||
response = client.get("/shop/finalize_order", follow_redirects=False)
|
||||
response = client.post(
|
||||
"/shop/finalize_order",
|
||||
follow_redirects=False,
|
||||
data={"account_id": second_account.id},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
|
||||
assert len(user.shopping_cart.items) == 0
|
||||
assert len(user.orders) == 2 # shopping cart + finalized order
|
||||
|
||||
assert user.accounts[0].balance == Decimal(100.0) - (product.price * 2)
|
||||
assert user.accounts[0].balance == Decimal(100.0)
|
||||
assert user.accounts[1].balance == Decimal(50.0) - (product.price * 2)
|
||||
|
||||
|
||||
def test_view_order(client: APSTestClient, test_db, product):
|
||||
|
||||
Reference in New Issue
Block a user