def create_db(): db.session.rollback() db.drop_all() db.create_all() if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): api.create(SQLALCHEMY_MIGRATE_REPO, 'database_repository') api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) else: api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
def setUp(self): """called before any test""" #create tables self.client = self.app.test_client() self.product = { 'name': 'testproduct', 'price': 56.0, 'category': 'ipods' } db.create_all()
def setUp(self): """ Sets up the default configurations, and in this case creates the database to be used """ with self.app.test_client(): db.session.close() db.drop_all() db.create_all() self.populate_db()
def create_db(test_app): try: db.create_all(app=test_app) except: sqlalchemy_utils.create_database(TestConfig.SQLALCHEMY_DATABASE_URI) db.create_all(app=test_app) yield db #db.session.close() db.session.remove() db.drop_all(app=test_app)
def home(): db.create_all() page = request.args.get('page', 1, type=int) events = Event.query.filter().order_by(Event.title).paginate(page=page, per_page=3) epoch = datetime(1970, 1, 1, 0, 0, 0) return render_template('home.html', title='Home', events=events, current_time=datetime.utcnow(), epoch=epoch, sidebar=True)
def setUp(self): """ Will be called before every test """ db.create_all() admin = Employee(username="******", password="******", is_admin=True) employee = Employee(username="******", password="******") db.session.add(admin) db.session.add(employee) db.session.commit()
def init_database(): # Create the database and the database table db.create_all() # Insert user data user1 = User(username='******', plaintext_password='******') user2 = User(email='anotheruser', plaintext_password='******') db.session.add(user1) db.session.add(user2) # Commit the changes for the users db.session.commit() yield db # this is where the testing happens! db.drop_all()
def create_populate_db(): from models import Account, Milestone, Timeline # Creation de la database db.drop_all() db.create_all() # Creation des comptes livretA = Account('Livret A', '3900') livretJeune = Account('Livret Jeune', '1600') db.session.add(livretA) db.session.add(livretJeune) june = Timeline(datetime.datetime.strptime('01 06 2015', "%d %m %Y").date(), '350') july = Timeline(datetime.datetime.strptime('01 07 2015', "%d %m %Y").date(), '330') august = Timeline(datetime.datetime.strptime('01 08 2015', "%d %m %Y").date(), '1000') september = Timeline(datetime.datetime.strptime('01 09 2015', "%d %m %Y").date(), '1500') october = Timeline(datetime.datetime.strptime('01 10 2015', "%d %m %Y").date(), '2500') november = Timeline(datetime.datetime.strptime('01 11 2015', "%d %m %Y").date(), '3100') december = Timeline(datetime.datetime.strptime('01 12 2015', "%d %m %Y").date(), '5500') db.session.add(june) db.session.add(july) db.session.add(august) db.session.add(september) db.session.add(october) db.session.add(november) db.session.add(december) # Creation des milestones mille = Milestone('1000 !!', '1000') cinqmille = Milestone('5000 !!', '5000') dixmille = Milestone('10 000 !!', '10000') vingtmille = Milestone('20 000 !!', '20000') cinquantemille = Milestone('50 000 !!', '50000') centmille = Milestone('100 000 !!', '100000') db.session.add(mille) db.session.add(cinqmille) db.session.add(dixmille) db.session.add(vingtmille) db.session.add(cinquantemille) db.session.add(centmille) #commit db.session.commit()
def create_admin(admin, password): db.create_all() admin_name = Nickname.query.first() if admin_name is not None: click.echo('updating...') admin_name.admin = admin admin_name.set_password(password) else: click.echo('creating admin...') admin_name = Nickname(admin=admin, name='houshanyun') admin_name.set_password(password) db.session.add(admin_name) db.session.commit() click.echo('Done')
def setUp(self): app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' app.check_auth = Mock(return_value=False) self.app = app.test_client() db.create_all() self.app = app.test_client() self.non_existing_user = '******' self.creds = ('service2', 'simple') self.owner = 'foobar' self.resources = ['321aa00a', '3432aaaa', 'fobara'] u = User(id=self.owner) for i in self.resources: u.resources.append(Resource(id=i)) db.session.add(u) db.session.commit()
def db_handle(db): db.drop_all() db.create_all()
def create_db(): """Creates the db tables.""" db.create_all(bind=None)
#!/usr/bin/env python3 from myapp import app, db db.create_all(app=app) app.run(debug=True)
__tablename__='oplog' id=db.Column(db.Integer,primary_key=True) # admin_id=db.Column(db.Integer,db.ForeignKey("admin.id")) admin_id=db.Column(db.Integer) ip=db.Column(db.String(100)) reason=db.Column(db.String(600)) addtime=db.Column(db.DATETIME,index=True,default=datetime.datetime.now) def __repr__(self): return "<oplog %s>"%self.id def add_log(log): db.session.add(log) db.session.commit() if __name__=='__main__': # pass # 创建表 db.drop_all(User) db.create_all(User) # from werkzeug.security import generate_password_hash # role=Admin( # # name='李不搭', # pwd=generate_password_hash('zslswmz'), # is_super=1, # # ) # db.session.add(role) # db.session.commit() # #
def setUp(self): db.create_all()
def create_tables(): db.create_all()
def create_all_db(app): with app.app_context(): db.create_all()
def init_db(): """ Initialize the database.""" db.drop_all() db.create_all() create_admin_users()
def create_database(): print "begin create database" db.create_all() return "OK"
def schema_update(): db.create_all() print('you had update all tables')
#!/usr/bin/env python from myapp import create_app, db from myapp.models import User if __name__ == '__main__': app = create_app('development') with app.app_context(): db.create_all() app.run()
def init_db(): db.drop_all() db.create_all()
def initdb(): db.create_all() download_initial_nbp_rates_and_update_db()
def create_db(): db.create_all()
#!/usr/bin/env python from migrate.versioning import api from config import SQLALCHEMY_DATABASE_URI from config import SQLALCHEMY_MIGRATE_REPO from myapp import db import os.path # Create the database, based on models db.create_all() # Version control directory if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository') api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) else: api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' db.create_all()
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('重置資料庫')
def setUp(self): app.config['TESTING'] = True app.app_context() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test1.db' self.app = app.test_client() db.create_all()
def client(): with app.app_context(): db.create_all() app.testing = True app.debug = True return app.test_client()
def setUp(self): self.app = self.create_app() db.create_all()
def initdb(): db.create_all()
def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def deploy(): from flask.ext.migrate import upgrade from myapp.models import Role, User db.create_all() Role.insert_roles()