Holger Frey
7 years ago
5 changed files with 58 additions and 8 deletions
@ -0,0 +1,23 @@ |
|||||||
|
''' Models for User Accounts and Roles ''' |
||||||
|
|
||||||
|
import enum |
||||||
|
|
||||||
|
|
||||||
|
class Role(enum.Enum): |
||||||
|
''' roles of user accounts ''' |
||||||
|
|
||||||
|
UNVALIDATED = 'unvalidated' #: new user, email not validated |
||||||
|
NEW = 'new' #: new user, email validated, not active |
||||||
|
USER = 'user' #: standard user, may place and view orders |
||||||
|
PURCHASER = 'purchaser' #: privileged user, may edit orders |
||||||
|
ADMIN = 'admin' #: fully privileged user |
||||||
|
INACTIVE = 'inactive' #: user that is no longer active ("deleted") |
||||||
|
|
||||||
|
@property |
||||||
|
def principal(self): |
||||||
|
''' returns the principal identifier of the role ''' |
||||||
|
return 'role:' + self.name.lower() |
||||||
|
|
||||||
|
def __str__(self): |
||||||
|
''' string representation ''' |
||||||
|
return self.name.capitalize() |
@ -0,0 +1,27 @@ |
|||||||
|
'UNVALIDATED' |
||||||
|
'NEW' |
||||||
|
'USER' |
||||||
|
'PURCHASER' |
||||||
|
'ADMIN' |
||||||
|
'INACTIVE' |
||||||
|
|
||||||
|
import pytest |
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize( |
||||||
|
'key,result', [('NEW', 'role:new'), ('USER', 'role:user')] |
||||||
|
) |
||||||
|
def test_role_principal(key, result): |
||||||
|
from ordr.models.account import Role |
||||||
|
subject = Role[key] |
||||||
|
assert subject.principal == result |
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize( |
||||||
|
'key,result', [('NEW', 'New'), ('USER', 'User')] |
||||||
|
) |
||||||
|
def test_role__str__(key, result): |
||||||
|
from ordr.models.account import Role |
||||||
|
subject = Role[key] |
||||||
|
assert str(subject) == result |
||||||
|
|
Reference in new issue