コード例 #1
0
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()
コード例 #2
0
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()
コード例 #3
0
def client(app):
    with app.test_client() as client:
        _db.app = app
        _db.create_all()
        yield client
        _db.session.rollback()
        _db.drop_all()
コード例 #4
0
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()
コード例 #5
0
def dropdb():
    """
    Drops all the tables to make a fresh start.
    """

    db.drop_all()
    db.session.commit()
コード例 #6
0
def db(app):
    db_.app = app
    with app.app_context():
        db_.create_all()
    yield db_
    db_.session.close()
    db_.drop_all()
コード例 #7
0
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)
コード例 #8
0
def db(app):
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
コード例 #9
0
ファイル: conftest.py プロジェクト: Eleonore9/data-wrangler
def db(app):
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
コード例 #10
0
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
コード例 #11
0
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()
コード例 #12
0
def db(app):
    _db.app = app

    with app.app_context():
        _db.create_all()

    yield _db

    _db.session.close()
    _db.drop_all()
コード例 #13
0
ファイル: conftest.py プロジェクト: bigfang/horn
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()
コード例 #14
0
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()
コード例 #15
0
ファイル: main.py プロジェクト: jasrusable/APG4011F
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()
コード例 #16
0
def db(app):
    _db.app = app

    with app.app_context():
        _db.create_all()

    yield _db

    _db.session.close()
    _db.drop_all()
コード例 #17
0
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()
コード例 #18
0
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()
コード例 #19
0
ファイル: conftest.py プロジェクト: sloria/cookiecutter-flask
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()
コード例 #20
0
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 ☢')
コード例 #21
0
ファイル: conftest.py プロジェクト: AntonOsika/busuu-flask
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()
コード例 #22
0
    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)
コード例 #23
0
    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()
コード例 #24
0
    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()
コード例 #25
0
def init_db():
    db.drop_all()
    db.create_all()
コード例 #26
0
ファイル: db_test_case.py プロジェクト: mgp/streamhighlights
	def tearDown(self):
		db.drop_all()
		unittest.TestCase.tearDown(self)
コード例 #27
0
ファイル: test_db.py プロジェクト: WilliamLP/fitgraphs
 def test_drop_all(self):
     db.drop_all()
     db.rows('select * from data')
コード例 #28
0
 def teardown():
     db.session.remove()
     db.drop_all()
コード例 #29
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
コード例 #30
0
ファイル: sqlal.py プロジェクト: jasrusable/snippets
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)
コード例 #31
0
def dropdb():
    """
    Drops all database tables
    """
    if prompt_bool("Are you sure you want to lose all your data"):
        db.drop_all()
コード例 #32
0
    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()
[]
>>> 
コード例 #33
0
 def teardown():
     db.session.remove()
     db.drop_all()
コード例 #34
0
def drop_db():
	db.drop_all()
コード例 #35
0
def database(app):
    with app.app_context():
        db.drop_all()
        db.create_all()

    yield db
コード例 #36
0
ファイル: test_db.py プロジェクト: WilliamLP/fitgraphs
 def setup(self):
     db.drop_all()
     db.create_all()
コード例 #37
0
ファイル: base.py プロジェクト: touchmenot/cookiecutter-flask
 def tearDown(self):
     db.session.remove()
     db.drop_all()
コード例 #38
0
#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)
コード例 #39
0
def drop():
    """Drops database tables"""
    if prompt_bool('Are you sure you want to lose all your data?'):
        db.drop_all()
コード例 #40
0
def drop_create_tables():
    db.session.commit()
    db.drop_all()
    db.create_all()
    db.session.commit()
コード例 #41
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
コード例 #42
0
 def tearDown(self):
     db.drop_all()
     self.context.pop()
コード例 #43
0
def app():
    app_ = create_app(resolve_config('test'))
    with app_.app_context():
        db.create_all()
        yield app_
        db.drop_all()
コード例 #44
0
def syncdb():
    if prompt_bool('Are you sure, this will delete your database'):
        db.drop_all()
        db.create_all()
    else:
        pass