import pytest

from app_new.core.models.user import User


def test_user_password_hashing():
    user = User(username='unit', password_hash='')
    user.set_password('monsecret')
    assert user.check_password('monsecret')
    assert not user.check_password('mauvais')


def test_user_legacy_role_does_not_grant_admin():
    user = User(username='admin', role='admin', password_hash='')
    # Le champ historique est conservé uniquement pour compatibilité et ne
    # peut plus accorder de droits sans UserRole/RolePermission.
    assert not user.is_admin()
    user2 = User(username='user', role='user', password_hash='')
    assert not user2.is_admin()
