Browse Source

split example user generation in two functions

master
Holger Frey 7 years ago
parent
commit
15ff848305
  1. 42
      tests/__init__.py

42
tests/__init__.py

@ -13,32 +13,40 @@ APP_SETTINGS = { @@ -13,32 +13,40 @@ APP_SETTINGS = {
'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
def create_users(db):
''' set up some well known example users '''
def create_user(db, role_name):
''' set up one well known example users '''
from ordr2.models import Role, User
stubs = [
('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
id_, first_name, last_name = EXAMPLE_USERS[role_name]
user = User(
id=i+1,
id=id_,
username=first_name + last_name,
first_name = first_name,
last_name = last_name,
email = last_name.lower() + '@example.com',
role=role,
password_hash = first_name.lower()
role=Role(role_name)
)
user.set_password(first_name)
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
@ -49,6 +57,10 @@ def app_config(): @@ -49,6 +57,10 @@ def app_config():
with testing.testConfig(settings=APP_SETTINGS) as config:
config.include('pyramid_jinja2')
#config.include('pyramid_mailer.testing')
from ordr2.models.users import passlib_context
passlib_context.update(schemes=['argon2'])
yield config