def drop_tables(flask_app): """Drop all tables defined by {{cookiecutter.service_slug}}.models. Requires a flask application context to work. TODO - check for application context """ db.drop_all()
def app(scope="function"): app = create_app() app.config['TESTING'] = True with app.app_context(): db.drop_all(app=app) db.create_all(app=app) yield app.test_client()
def client(app): with app.test_client() as client: _db.app = app _db.create_all() yield client _db.session.rollback() _db.drop_all()
def dropdb(force=False): """ Drops all database tables """ if force or prompt_bool("Are you sure you want to lose all your data"): db.drop_all()
def dropdb(): """ Drops all the tables to make a fresh start. """ db.drop_all() db.session.commit()
def db(app): db_.app = app with app.app_context(): db_.create_all() yield db_ db_.session.close() db_.drop_all()
def app(): os.environ["FLASK_ENV"] = "testing" app = create_app() with app.app_context(): db.create_all(app=app) # flask_migrate.upgrade(revision="heads") yield app db.drop_all(app=app)
def db(app): _db.app = app with app.app_context(): _db.create_all() yield _db _db.drop_all()
def db(app): """A database for the tests.""" _db.app = app with app.app_context(): _db.create_all() yield _db _db.drop_all()
def recreate_db(): """ Recreates a database. This should only be used once when there's a new database instance. This shouldn't be used when you migrate your database. """ drop_all() init_db()
def db(app): _db.app = app with app.app_context(): _db.create_all() yield _db _db.session.close() _db.drop_all()
def testdb(app): _db.app = app with app.app_context(): _db.create_all() yield _db # Explicitly close DB connection _db.session.close() _db.drop_all()
def app(): from {{ cookiecutter.project_slug }}.app import app as _app, db with _app.app_context(): db.create_all() yield _app db.session.remove() db.drop_all()
def init(): db.drop_all() db.create_all() camera = Camera(focal_length=0.9, height=0.23, width=0.23) pc_1 = PerspectiveCenterPoint(x=100, y=0, z=4000) pc_2 = PerspectiveCenterPoint(x=900, y=0, z=3000) image_1 = Image(tag='image_1', camera=camera, perspective_center=pc_1, rx=0, ry=0, rz=0) image_2 = Image(tag='image_2', camera=camera, perspective_center=pc_2, rx=0, ry=0, rz=0) db.session.add(camera) db.session.commit()
def db(app): from {{cookiecutter.project_slug}} import db as _db with app.app_context(): _db.create_all() yield _db _db.session.remove() _db.drop_all()
def client(): with tempfile.NamedTemporaryFile() as dbf: app = create_app(test_db=f"sqlite:///{dbf.name}") with app.app_context(): from flask_migrate import upgrade as _upgrade _upgrade() with app.test_client() as test_client: yield test_client with app.app_context(): db.drop_all()
def db(app): """A database for the tests.""" _db.app = app with app.app_context(): _db.create_all() yield _db # Explicitly close DB connection _db.session.close() _db.drop_all()
def recreate_db(): """Run only in dev environment""" from utils.colorprint import ColorPrint as _ env = os.getenv('FLASK_ENV') or 'default' if env == 'development' or env == 'default': _.print_warn('⚠ Recreating database ⚠') db.drop_all() db.create_all() db.session.commit() else: _.print_fail('☢ You should not run this in production ☢')
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.app = app.test_client() db.drop_all() db.create_all() self.assertEqual(app.debug, False)
def setUp(self): """Set up test variables.""" self.app = app.test_client() # This is the user test json data with a predefined email and password self.user_data = { 'email': '*****@*****.**', 'password': '******' } with self.client.app_context(): # create all tables db.session.close() db.drop_all() db.create_all()
def setUp(self): super({{cookiecutter.app_name|title}}AppTestCase, self).setUp() self.app = self._create_app() self.client = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() from {{cookiecutter.app_name}}.extensions import db db.app = self.app db.drop_all() db.create_all() self.db = db self._create_fixtures()
def init_db(): db.drop_all() db.create_all()
def tearDown(self): db.drop_all() unittest.TestCase.tearDown(self)
def test_drop_all(self): db.drop_all() db.rows('select * from data')
def teardown(): db.session.remove() db.drop_all()
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
from sqlalchemy.orm import relationship, backref from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base import db from db import Base class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) #children = relationship('Child') class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey('parent.id')) parent = relationship('Parent', backref=backref('children')) db.drop_all() db.create_all() parent = Parent() child_1 = Child() child_2 = Child() db.session.add(parent) db.session.add(child_1) db.session.add(child_2) db.session.commit() print(parent.children)
def dropdb(): """ Drops all database tables """ if prompt_bool("Are you sure you want to lose all your data"): db.drop_all()
user.posts File "D:\Programs\Sublime Text 3\flaskblog.py", line 30, in __repr__ return "Post('{1)','{0}')".format(self.date_posted,self.title) ValueError: unmatched '{' in format >>> user.posts Traceback (most recent call last): File "<pyshell#20>", line 1, in <module> user.posts File "D:\Programs\Sublime Text 3\flaskblog.py", line 30, in __repr__ return "Post('{1)','{0}')".format(self.date_posted,self.title) ValueError: unmatched '{' in format >>> post = Post.query.first() >>> post Traceback (most recent call last): File "<pyshell#22>", line 1, in <module> post File "D:\Programs\Sublime Text 3\flaskblog.py", line 30, in __repr__ return "Post('{1)','{0}')".format(self.date_posted,self.title) ValueError: unmatched '{' in format >>> post.author User('{self.username)','{self.email}','{self.image_file}') >>> db.drop_all() >>> db.create_all() >>> User.query.all() [] >>> Post.query.all() [] >>>
def drop_db(): db.drop_all()
def database(app): with app.app_context(): db.drop_all() db.create_all() yield db
def setup(self): db.drop_all() db.create_all()
def tearDown(self): db.session.remove() db.drop_all()
#coding=utf-8 import sys reload(sys) sys.setdefaultencoding("utf8") from Util import Math u = Math() import db from Table import Role from Table import User from Table import Calc db = db.db db.drop_all() db.create_all() role_admin = Role() role_mod = Role() role_user = Role() user_john = User(username='******', role=role_admin) user_susan = User(username='******', role=role_user) user_david = User(username='******', role=role_user) db.session.add(role_admin) db.session.add(role_mod) db.session.add(role_user) db.session.add(user_john) db.session.add(user_susan) db.session.add(user_david)
def drop(): """Drops database tables""" if prompt_bool('Are you sure you want to lose all your data?'): db.drop_all()
def drop_create_tables(): db.session.commit() db.drop_all() db.create_all() db.session.commit()
def tearDown(self): db.drop_all() self.context.pop()
def app(): app_ = create_app(resolve_config('test')) with app_.app_context(): db.create_all() yield app_ db.drop_all()
def syncdb(): if prompt_bool('Are you sure, this will delete your database'): db.drop_all() db.create_all() else: pass