Browse Source

added model for account roles

rework
Holger Frey 7 years ago
parent
commit
2be8692625
  1. 23
      ordr/models/account.py
  2. 27
      ordr/tests/account.py
  3. 6
      ordr/tests/models/meta.py
  4. 4
      ordr/tests/resources/root_resource.py
  5. 2
      ordr/tests/views/__init__.py

23
ordr/models/account.py

@ -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()

27
ordr/tests/account.py

@ -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

6
ordr/tests/models/meta.py

@ -5,7 +5,7 @@ import pytest
'value,expected', [ 'value,expected', [
(None, None), (None, None),
([1, 2, 3], '[1, 2, 3]'), ([1, 2, 3], '[1, 2, 3]'),
({'a':1, 'b':2}, '{"a": 1, "b": 2}'), ({'a': 1, 'b': 2}, '{"a": 1, "b": 2}'),
] ]
) )
def test_json_encoder_bind(value, expected): def test_json_encoder_bind(value, expected):
@ -18,7 +18,7 @@ def test_json_encoder_bind(value, expected):
'value,expected', [ 'value,expected', [
(None, None), (None, None),
('[1, 2, 3]', [1, 2, 3]), ('[1, 2, 3]', [1, 2, 3]),
('{"a": 1, "b":2}', {'a':1, 'b':2}), ('{"a": 1, "b":2}', {'a': 1, 'b': 2}),
] ]
) )
def test_json_encoder_result(value, expected): def test_json_encoder_result(value, expected):
@ -27,7 +27,7 @@ def test_json_encoder_result(value, expected):
assert encoder.process_result_value(value, None) == expected assert encoder.process_result_value(value, None) == expected
@pytest.mark.parametrize('value', [None, [1, 2, 3], {'a':1, 'b':2}]) @pytest.mark.parametrize('value', [None, [1, 2, 3], {'a': 1, 'b': 2}])
def test_json_encoder_bind_and_result(value): def test_json_encoder_bind_and_result(value):
from ordr.models.meta import JsonEncoder from ordr.models.meta import JsonEncoder
encoder = JsonEncoder() encoder = JsonEncoder()

4
ordr/tests/resources/root_resource.py

@ -2,8 +2,8 @@
def test_root_init(): def test_root_init():
from ordr.resources import RootResource from ordr.resources import RootResource
root = RootResource('request') root = RootResource('request')
assert root.__name__ == None assert root.__name__ is None
assert root.__parent__ == None assert root.__parent__ is None
assert root.request == 'request' assert root.request == 'request'

2
ordr/tests/views/__init__.py

@ -1 +1 @@
# package