def test_db(test_client): # Create the database and the database table db.create_all() yield db # this is where the testing happens! # anything after yield is teardown code db.session.rollback() db.session.remove() db.drop_all()
#!/usr/bin/env python # -*- coding: utf-8 -*- from hasjob import app, init_for, models from hasjob.models import db from hasjob.search import configure as search_configure from hasjob.uploads import configure as uploads_configure if __name__ == '__main__': import sys init_for('dev') # Create database table db.create_all() # Seed with sample data with app.test_request_context(): if models.JobType.query.count() == 0: print >> sys.stderr, "Adding some job types" db.session.add(models.JobType(seq=10, slug='fulltime', title=u'Full-time employment')) db.session.add(models.JobType(seq=20, slug='contract', title=u'Short-term contract')) db.session.add(models.JobType(seq=30, slug='freelance', title=u'Freelance or consulting')) db.session.add(models.JobType(seq=40, slug='volunteer', title=u'Volunteer contributor')) db.session.add(models.JobType(seq=50, slug='partner', title=u'Partner for a venture')) db.session.commit() if models.JobCategory.query.count() == 0: print >> sys.stderr, "Adding some job categories" db.session.add(models.JobCategory(seq=10, slug='programming', title=u'Programming')) db.session.add(models.JobCategory(seq=20, slug='ux', title=u'Interaction Design')) db.session.add(models.JobCategory(seq=30, slug='design', title=u'Graphic Design')) db.session.add(models.JobCategory(seq=40, slug='testing', title=u'Testing')) db.session.add(models.JobCategory(seq=50, slug='sysadmin', title=u'Systems Administration')) db.session.add(models.JobCategory(seq=60, slug='business', title=u'Business/Management'))
def create(env): "Creates database tables from sqlalchemy models" init_for(env) db.create_all()
def create_app(self): app.config['TESTING'] = True db.create_all() init_for('testing') return app
#!/usr/bin/env python # -*- coding: utf-8 -*- from hasjob import app, init_for, models from hasjob.models import db from hasjob.search import configure as search_configure from hasjob.uploads import configure as uploads_configure if __name__ == '__main__': import sys init_for('dev') # Create database table db.create_all() # Seed with sample data with app.test_request_context(): if models.JobType.query.count() == 0: print >> sys.stderr, "Adding some job types" db.session.add( models.JobType(seq=10, slug='fulltime', title=u'Full-time employment')) db.session.add( models.JobType(seq=20, slug='contract', title=u'Short-term contract')) db.session.add( models.JobType(seq=30, slug='freelance', title=u'Freelance or consulting')) db.session.add( models.JobType(seq=40,
def create_app(self): app.config["TESTING"] = True db.create_all() init_for("testing") return app