|
|
|
@ -1,19 +1,31 @@
@@ -1,19 +1,31 @@
|
|
|
|
|
''' Test package for ordr2. ''' |
|
|
|
|
|
|
|
|
|
import os.path |
|
|
|
|
import pytest |
|
|
|
|
import transaction |
|
|
|
|
|
|
|
|
|
from pyramid import testing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# some path mangling to get the path to passlib.ini |
|
|
|
|
currrent_dir = os.path.dirname(__file__) |
|
|
|
|
ordr2_dir = os.path.dirname(currrent_dir) |
|
|
|
|
passlib_config_path = os.path.join(ordr2_dir, 'passlib.ini') |
|
|
|
|
assert os.path.isfile(passlib_config_path) |
|
|
|
|
|
|
|
|
|
APP_SETTINGS = { |
|
|
|
|
'sqlalchemy.url': 'sqlite:///:memory:', |
|
|
|
|
'auth.secret': 'not-very-secure', |
|
|
|
|
'session.secret': 'not-very-secure', |
|
|
|
|
'session.auto_csrf': True |
|
|
|
|
'session.secret': |
|
|
|
|
'4d72ee16df8cf1238048ade32e3ce4d51757af8ada4a962cfae5cea5c08421a0', |
|
|
|
|
'session.auto_csrf': True, |
|
|
|
|
'passlib.config': passlib_config_path, |
|
|
|
|
'pyramid.includes': [ |
|
|
|
|
'pyramid_jinja2', |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EXAMPLE_USERS = { |
|
|
|
|
EXAMPLE_USER_DATA = { |
|
|
|
|
'unvalidated': (1, 'Graham', 'Chapman'), |
|
|
|
|
'new': (2, 'John', 'Cleese'), |
|
|
|
|
'user': (3, 'Terry', 'Gilliam'), |
|
|
|
@ -25,10 +37,10 @@ EXAMPLE_USERS = {
@@ -25,10 +37,10 @@ EXAMPLE_USERS = {
|
|
|
|
|
|
|
|
|
|
# helpers |
|
|
|
|
|
|
|
|
|
def create_user(db, role_name): |
|
|
|
|
''' set up one well known example users ''' |
|
|
|
|
def get_user(role_name): |
|
|
|
|
''' get the user model for one well known user ''' |
|
|
|
|
from ordr2.models import Role, User |
|
|
|
|
id_, first_name, last_name = EXAMPLE_USERS[role_name] |
|
|
|
|
id_, first_name, last_name = EXAMPLE_USER_DATA[role_name] |
|
|
|
|
user = User( |
|
|
|
|
id=id_, |
|
|
|
|
username=first_name + last_name, |
|
|
|
@ -38,7 +50,6 @@ def create_user(db, role_name):
@@ -38,7 +50,6 @@ def create_user(db, role_name):
|
|
|
|
|
role=Role(role_name) |
|
|
|
|
) |
|
|
|
|
user.set_password(first_name) |
|
|
|
|
db.add(user) |
|
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,7 +57,8 @@ def create_users(db):
@@ -46,7 +57,8 @@ 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) |
|
|
|
|
user = get_user(role.value) |
|
|
|
|
db.add(user) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# fixtures |
|
|
|
@ -55,7 +67,6 @@ def create_users(db):
@@ -55,7 +67,6 @@ def create_users(db):
|
|
|
|
|
def app_config(): |
|
|
|
|
''' fixture for tests requiring a pyramid.testing setup ''' |
|
|
|
|
with testing.testConfig(settings=APP_SETTINGS) as config: |
|
|
|
|
config.include('pyramid_jinja2') |
|
|
|
|
#config.include('pyramid_mailer.testing') |
|
|
|
|
|
|
|
|
|
from ordr2.models.users import passlib_context |
|
|
|
|