def addUser(self): if not (DBSession.query(User).filter( User.name == 'distractionbike').first()): md5 = hashlib.md5('secret'.encode()).hexdigest() user = User(name='distractionbike', password_md5=md5) DBSession.add(user) return user
def addPost(self): post = Post(journal_name='distractionbike', title='First Post', lede='First lede', text='<b>My body</b>') DBSession.add(post) DBSession.flush() return post
def addUser(self): if not (DBSession .query(User) .filter(User.name == 'distractionbike') .first()): md5 = hashlib.md5('secret'.encode()).hexdigest() user = User(name='distractionbike', password_md5=md5) DBSession.add(user) return user
def addPost(self): post = Post( journal_name='distractionbike', title='First Post', lede='First lede', text='<b>My body</b>') DBSession.add(post) DBSession.flush() return post
def addComment(self): comment = Comment(post_id=1, user_id='bob', text='First Comment') DBSession.add(comment) DBSession.flush() return comment
def addJournal(self): journal = Journal(name='distractionbike') DBSession.add(journal) return journal
def setUpDb(self): engine = create_engine('sqlite://') Base.metadata.create_all(engine) DBSession.configure(bind=engine)
def tearDown(self): DBSession.remove()
) if __name__ == '__main__': from okarchive.models import siteRoot import transaction import sys from sqlalchemy import engine_from_config from pyramid.paster import ( get_appsettings, setup_logging, ) from okarchive.models import ( DBSession, Base, Journal, Post, User, ) config_uri = sys.argv[1] settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.create_all(engine) journal = siteRoot['journals']['distractionbike'] import_post(journal) transaction.commit()