def _initTestingDB(): from sqlalchemy import create_engine from myproject.models import (DBSession, Page, Base) # jiawzhang: 'sqlite://' means specify the db persistence as memory. engine = create_engine('sqlite://', echo=True) Base.metadata.create_all(engine) DBSession.configure(bind=engine) # jiawzhang: you have to introduce "transaction.manager" here because this is the unit test context instead of the web context, see details in ./models.py with transaction.manager: model = Page('FrontPage', 'This is the front page') DBSession.add(model) return DBSession
from pyramid.authentication import SessionAuthenticationPolicy from pyramid.config import Configurator from sqlalchemy import create_engine from pyramid.httpexceptions import HTTPNotFound from sqlalchemy.pool import NullPool from myproject.models import (DBSession, Base, register, all_users, User, del_all, del_user, all_guys, add_guy) engine = create_engine('sqlite:///gen_tree.db') DBSession.configure(bind=engine) Base.metadata.bind = engine Base.metadata.create_all(engine) #register("123123","123123","ccccc") register("sdf,", "sdf", "sdf") #del_user("123") all_guys() all_users() #del_all()