|
|
@ -13,32 +13,40 @@ APP_SETTINGS = { |
|
|
|
'session.auto_csrf': True |
|
|
|
'session.auto_csrf': True |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLE_USERS = { |
|
|
|
|
|
|
|
'unvalidated': (1, 'Graham', 'Chapman'), |
|
|
|
|
|
|
|
'new': (2, 'John', 'Cleese'), |
|
|
|
|
|
|
|
'user': (3, 'Terry', 'Gilliam'), |
|
|
|
|
|
|
|
'purchaser': (4, 'Eric', 'Idle'), |
|
|
|
|
|
|
|
'admin': (5, 'Terry', 'Jones'), |
|
|
|
|
|
|
|
'inactive': (6, 'Michael', 'Palin'), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# helpers |
|
|
|
# helpers |
|
|
|
|
|
|
|
|
|
|
|
def create_users(db): |
|
|
|
def create_user(db, role_name): |
|
|
|
''' set up some well known example users ''' |
|
|
|
''' set up one well known example users ''' |
|
|
|
from ordr2.models import Role, User |
|
|
|
from ordr2.models import Role, User |
|
|
|
stubs = [ |
|
|
|
id_, first_name, last_name = EXAMPLE_USERS[role_name] |
|
|
|
('Graham', 'Chapman', Role.UNVALIDATED), |
|
|
|
|
|
|
|
('John', 'Cleese', Role.NEW), |
|
|
|
|
|
|
|
('Terry', 'Gilliam', Role.USER), |
|
|
|
|
|
|
|
('Eric', 'Idle', Role.PURCHASER), |
|
|
|
|
|
|
|
('Terry', 'Jones', Role.ADMIN), |
|
|
|
|
|
|
|
('Michael', 'Palin', Role.INACTIVE) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
for i, stub in enumerate(stubs): |
|
|
|
|
|
|
|
first_name, last_name, role = stub |
|
|
|
|
|
|
|
user = User( |
|
|
|
user = User( |
|
|
|
id=i+1, |
|
|
|
id=id_, |
|
|
|
username=first_name + last_name, |
|
|
|
username=first_name + last_name, |
|
|
|
first_name = first_name, |
|
|
|
first_name = first_name, |
|
|
|
last_name = last_name, |
|
|
|
last_name = last_name, |
|
|
|
email = last_name.lower() + '@example.com', |
|
|
|
email = last_name.lower() + '@example.com', |
|
|
|
role=role, |
|
|
|
role=Role(role_name) |
|
|
|
password_hash = first_name.lower() |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
user.set_password(first_name) |
|
|
|
db.add(user) |
|
|
|
db.add(user) |
|
|
|
|
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_users(db): |
|
|
|
|
|
|
|
''' set up all well known example users ''' |
|
|
|
|
|
|
|
from ordr2.models import Role |
|
|
|
|
|
|
|
for role in Role: |
|
|
|
|
|
|
|
create_user(db, role.value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# fixtures |
|
|
|
# fixtures |
|
|
@ -49,6 +57,10 @@ def app_config(): |
|
|
|
with testing.testConfig(settings=APP_SETTINGS) as config: |
|
|
|
with testing.testConfig(settings=APP_SETTINGS) as config: |
|
|
|
config.include('pyramid_jinja2') |
|
|
|
config.include('pyramid_jinja2') |
|
|
|
#config.include('pyramid_mailer.testing') |
|
|
|
#config.include('pyramid_mailer.testing') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ordr2.models.users import passlib_context |
|
|
|
|
|
|
|
passlib_context.update(schemes=['argon2']) |
|
|
|
|
|
|
|
|
|
|
|
yield config |
|
|
|
yield config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|