feat(admin): Add group admin and test for admin views
This commit is contained in:
@@ -2,9 +2,9 @@ from decimal import Decimal
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from conftest import APSTestClient
|
||||
from fake_data import fake
|
||||
from sqlalchemy import select
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from allmende_payment_system.database import ensure_user
|
||||
from allmende_payment_system.models import (
|
||||
@@ -56,7 +56,7 @@ def product(test_db):
|
||||
return product
|
||||
|
||||
|
||||
def test_add_item_to_cart(client: TestClient, test_db, product):
|
||||
def test_add_item_to_cart(client: APSTestClient, test_db, product):
|
||||
|
||||
form_data = {"product_id": product.id, "quantity": 2, "area_id": product.area.id}
|
||||
|
||||
@@ -72,7 +72,7 @@ def test_add_item_to_cart(client: TestClient, test_db, product):
|
||||
assert len(cart.items) == 1
|
||||
|
||||
|
||||
def test_edit_item_in_cart(client: TestClient, test_db, product):
|
||||
def test_edit_item_in_cart(client: APSTestClient, test_db, product):
|
||||
form_data = {"product_id": product.id, "quantity": 2, "area_id": product.area.id}
|
||||
|
||||
response = client.post(
|
||||
@@ -99,7 +99,7 @@ def test_edit_item_in_cart(client: TestClient, test_db, product):
|
||||
assert cart.items[0].total_amount == product.price * 3
|
||||
|
||||
|
||||
def test_remove_item_from_cart(client: TestClient, test_db, product):
|
||||
def test_remove_item_from_cart(client: APSTestClient, test_db, product):
|
||||
|
||||
user = create_user_with_account(test_db, "test")
|
||||
|
||||
@@ -122,7 +122,7 @@ def test_remove_item_from_cart(client: TestClient, test_db, product):
|
||||
assert len(test_db.scalars(select(OrderItem)).all()) == 0
|
||||
|
||||
|
||||
def test_remove_item_from_cart_wrong_user(client: TestClient, test_db, product):
|
||||
def test_remove_item_from_cart_wrong_user(client: APSTestClient, test_db, product):
|
||||
user = create_user_with_account(test_db, "test")
|
||||
|
||||
user.shopping_cart.items.append(
|
||||
@@ -135,15 +135,16 @@ def test_remove_item_from_cart_wrong_user(client: TestClient, test_db, product):
|
||||
|
||||
id_ = user.shopping_cart.items[0].id
|
||||
|
||||
with mock.patch.dict("os.environ", {"APS_username": "other_user"}):
|
||||
response = client.get(f"/shop/cart/remove/{id_}", follow_redirects=False)
|
||||
response = client.get(
|
||||
f"/shop/cart/remove/{id_}", follow_redirects=False, user="other_user"
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
cart = test_db.scalar(select(Order))
|
||||
assert len(cart.items) == 1
|
||||
|
||||
|
||||
def test_finalize_order(client: TestClient, test_db, product):
|
||||
def test_finalize_order(client: APSTestClient, test_db, product):
|
||||
|
||||
user = create_user_with_account(test_db, "test", balance=100.0)
|
||||
|
||||
@@ -161,7 +162,7 @@ def test_finalize_order(client: TestClient, test_db, product):
|
||||
assert user.accounts[0].balance == Decimal(100.0) - (product.price * 2)
|
||||
|
||||
|
||||
def test_view_order(client: TestClient, test_db, product):
|
||||
def test_view_order(client: APSTestClient, test_db, product):
|
||||
user = create_user_with_account(test_db, "test")
|
||||
|
||||
order = add_finalized_order_to_user(test_db, user, product)
|
||||
@@ -172,11 +173,12 @@ def test_view_order(client: TestClient, test_db, product):
|
||||
assert product.name in response.text
|
||||
|
||||
|
||||
def test_view_order_wrong_user(client: TestClient, test_db, product):
|
||||
def test_view_order_wrong_user(client: APSTestClient, test_db, product):
|
||||
user = create_user_with_account(test_db, "test")
|
||||
|
||||
order = add_finalized_order_to_user(test_db, user, product)
|
||||
|
||||
with mock.patch.dict("os.environ", {"APS_username": "other_user"}):
|
||||
response = client.get(f"/shop/order/{order.id}")
|
||||
response = client.get(
|
||||
f"/shop/order/{order.id}", follow_redirects=False, user="other_user"
|
||||
)
|
||||
assert response.status_code == 403
|
||||
|
||||
Reference in New Issue
Block a user