47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import pytest
|
|
|
|
from allmende_payment_system.models import Account, Permission, User, UserGroup
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def test_user(test_db):
|
|
user = User(username="test", display_name="Test User")
|
|
test_db.add(user)
|
|
test_db.flush()
|
|
return user
|
|
|
|
|
|
def test_user_model(test_db, test_user):
|
|
assert test_user.id is not None
|
|
|
|
account = Account(name="Test Account")
|
|
account.users.append(test_user)
|
|
test_db.add(account)
|
|
test_db.flush()
|
|
|
|
assert len(test_user.accounts) == 1
|
|
|
|
|
|
def test_user_shopping_cart_new(test_db, test_user):
|
|
cart = test_user.shopping_cart
|
|
|
|
assert len(cart.items) == 0
|
|
|
|
|
|
def test_user_permissions(test_db):
|
|
user = User(username="normie", display_name="Normal User")
|
|
admin = User(username="admin", display_name="Admin User")
|
|
test_db.add(user)
|
|
|
|
group = UserGroup(name="Admins", description="A group for admins")
|
|
group.permissions.append(Permission(scope="area", action="edit"))
|
|
test_db.add(group)
|
|
|
|
admin.user_groups.append(group)
|
|
test_db.flush()
|
|
|
|
assert len(admin.user_groups) == 1
|
|
|
|
assert not user.has_permission("area", "edit")
|
|
assert admin.has_permission("area", "edit")
|