|
|
@ -1,4 +1,4 @@ |
|
|
|
''' Test package for ordr2.models.users ''' |
|
|
|
''' Test package for ordr2.models.account ''' |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
|
@ -7,7 +7,7 @@ import pytest |
|
|
|
|
|
|
|
|
|
|
|
def test_role_principals(): |
|
|
|
def test_role_principals(): |
|
|
|
''' test Role.principal, a caluclated property ''' |
|
|
|
''' test Role.principal, a caluclated property ''' |
|
|
|
from ordr2.models.users import Role |
|
|
|
from ordr2.models.account import Role |
|
|
|
|
|
|
|
|
|
|
|
assert Role.UNVALIDATED.principal == 'role:unvalidated' |
|
|
|
assert Role.UNVALIDATED.principal == 'role:unvalidated' |
|
|
|
assert Role.NEW.principal == 'role:new' |
|
|
|
assert Role.NEW.principal == 'role:new' |
|
|
@ -19,7 +19,7 @@ def test_role_principals(): |
|
|
|
|
|
|
|
|
|
|
|
def test_role_str(): |
|
|
|
def test_role_str(): |
|
|
|
''' test the string representation of roles ''' |
|
|
|
''' test the string representation of roles ''' |
|
|
|
from ordr2.models.users import Role |
|
|
|
from ordr2.models.account import Role |
|
|
|
|
|
|
|
|
|
|
|
assert str(Role.UNVALIDATED) == 'Unvalidated' |
|
|
|
assert str(Role.UNVALIDATED) == 'Unvalidated' |
|
|
|
assert str(Role.NEW) == 'New' |
|
|
|
assert str(Role.NEW) == 'New' |
|
|
@ -33,7 +33,7 @@ def test_role_str(): |
|
|
|
|
|
|
|
|
|
|
|
def test_user_principal(): |
|
|
|
def test_user_principal(): |
|
|
|
''' test the user principal calculated property ''' |
|
|
|
''' test the user principal calculated property ''' |
|
|
|
from ordr2.models.users import User |
|
|
|
from ordr2.models.account import User |
|
|
|
|
|
|
|
|
|
|
|
user = User(id=3) |
|
|
|
user = User(id=3) |
|
|
|
|
|
|
|
|
|
|
@ -52,7 +52,7 @@ def test_user_principal(): |
|
|
|
) |
|
|
|
) |
|
|
|
def test_user_role_principals(role_name, principals): |
|
|
|
def test_user_role_principals(role_name, principals): |
|
|
|
''' test the user's role principals calculated property ''' |
|
|
|
''' test the user's role principals calculated property ''' |
|
|
|
from ordr2.models.users import User, Role |
|
|
|
from ordr2.models.account import User, Role |
|
|
|
|
|
|
|
|
|
|
|
role = Role[role_name] |
|
|
|
role = Role[role_name] |
|
|
|
user = User(role=role) |
|
|
|
user = User(role=role) |
|
|
@ -72,7 +72,7 @@ def test_user_role_principals(role_name, principals): |
|
|
|
) |
|
|
|
) |
|
|
|
def test_user_is_active(role_name, is_active): |
|
|
|
def test_user_is_active(role_name, is_active): |
|
|
|
''' test if is_active returns correct value based on the user's role ''' |
|
|
|
''' test if is_active returns correct value based on the user's role ''' |
|
|
|
from ordr2.models.users import User, Role |
|
|
|
from ordr2.models.account import User, Role |
|
|
|
|
|
|
|
|
|
|
|
role = Role[role_name] |
|
|
|
role = Role[role_name] |
|
|
|
user = User(role=role) |
|
|
|
user = User(role=role) |
|
|
@ -82,7 +82,7 @@ def test_user_is_active(role_name, is_active): |
|
|
|
|
|
|
|
|
|
|
|
def test_user_set_password(): |
|
|
|
def test_user_set_password(): |
|
|
|
''' test password hash generation ''' |
|
|
|
''' test password hash generation ''' |
|
|
|
from ordr2.models.users import User, passlib_context |
|
|
|
from ordr2.models.account import User, passlib_context |
|
|
|
|
|
|
|
|
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt']) |
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt']) |
|
|
|
user = User(password_hash=None) |
|
|
|
user = User(password_hash=None) |
|
|
@ -101,7 +101,7 @@ def test_user_set_password(): |
|
|
|
) |
|
|
|
) |
|
|
|
def test_user_check_password_ok(password): |
|
|
|
def test_user_check_password_ok(password): |
|
|
|
''' test password check ''' |
|
|
|
''' test password check ''' |
|
|
|
from ordr2.models.users import User, passlib_context |
|
|
|
from ordr2.models.account import User, passlib_context |
|
|
|
|
|
|
|
|
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt'], deprecated='auto') |
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt'], deprecated='auto') |
|
|
|
user = User(password_hash=None) |
|
|
|
user = User(password_hash=None) |
|
|
@ -112,7 +112,7 @@ def test_user_check_password_ok(password): |
|
|
|
|
|
|
|
|
|
|
|
def test_user_check_password_deprecated_hash(): |
|
|
|
def test_user_check_password_deprecated_hash(): |
|
|
|
''' test password check updates deprecated hash with new algorithm ''' |
|
|
|
''' test password check updates deprecated hash with new algorithm ''' |
|
|
|
from ordr2.models.users import User |
|
|
|
from ordr2.models.account import User |
|
|
|
from ordr2.security import passlib_context |
|
|
|
from ordr2.security import passlib_context |
|
|
|
|
|
|
|
|
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt'], deprecated='auto') |
|
|
|
passlib_context.update(schemes=['argon2', 'bcrypt'], deprecated='auto') |
|
|
@ -125,10 +125,9 @@ def test_user_check_password_deprecated_hash(): |
|
|
|
assert user.password_hash.startswith('$argon2') |
|
|
|
assert user.password_hash.startswith('$argon2') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_user_string_representation(): |
|
|
|
def test_user_string_representation(): |
|
|
|
''' test the string representation of the user ''' |
|
|
|
''' test the string representation of the user ''' |
|
|
|
from ordr2.models.users import User, Role |
|
|
|
from ordr2.models.account import User, Role |
|
|
|
|
|
|
|
|
|
|
|
user = User(username='FooBar') |
|
|
|
user = User(username='FooBar') |
|
|
|
|
|
|
|
|