Files
face-attendance/tests/test_auth.py
2026-05-01 21:24:21 +03:30

56 lines
1.5 KiB
Python

from __future__ import annotations
from app.models import Account, Role
from tests.conftest import create_account, login
def test_passwords_are_hashed(app):
with app.app_context():
account = create_account()
assert account.password_hash != "Password12345"
assert account.check_password("Password12345")
def test_login_redirects_to_dashboard(app, client):
with app.app_context():
create_account()
response = login(client)
assert response.status_code == 200
assert b"Dashboard" in response.data
def test_admin_can_create_operator_account(app, client):
with app.app_context():
create_account()
login(client)
response = client.post(
"/admin/accounts/new",
data={
"full_name": "Operations User",
"username": "operator",
"email": "operator@example.com",
"role": Role.OPERATOR.value,
"password": "Password12345",
"confirm_password": "Password12345",
},
follow_redirects=True,
)
assert response.status_code == 200
with app.app_context():
account = Account.query.filter_by(username="operator").one()
assert account.role == Role.OPERATOR.value
def test_operator_cannot_manage_accounts(app, client):
with app.app_context():
create_account(username="operator", role=Role.OPERATOR.value)
login(client, "operator")
response = client.get("/admin/accounts")
assert response.status_code == 403