Browse Source

split example user generation in two functions

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

56
tests/__init__.py

@ -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), user = User(
('John', 'Cleese', Role.NEW), id=id_,
('Terry', 'Gilliam', Role.USER), username=first_name + last_name,
('Eric', 'Idle', Role.PURCHASER), first_name = first_name,
('Terry', 'Jones', Role.ADMIN), last_name = last_name,
('Michael', 'Palin', Role.INACTIVE) email = last_name.lower() + '@example.com',
] role=Role(role_name)
for i, stub in enumerate(stubs): )
first_name, last_name, role = stub user.set_password(first_name)
user = User( db.add(user)
id=i+1, return user
username=first_name + last_name,
first_name = first_name,
last_name = last_name, def create_users(db):
email = last_name.lower() + '@example.com', ''' set up all well known example users '''
role=role, from ordr2.models import Role
password_hash = first_name.lower() for role in Role:
) create_user(db, role.value)
db.add(user)
# 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