Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 5
0
def dropdb():
    """
    Drops all the tables to make a fresh start.
    """

    db.drop_all()
    db.session.commit()
Ejemplo n.º 6
0
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)
Ejemplo n.º 8
0
def db(app):
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
Ejemplo n.º 9
0
def db(app):
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    _db.drop_all()
Ejemplo n.º 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()
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()
Ejemplo n.º 12
0
def db(app):
    _db.app = app

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

    yield _db

    _db.session.close()
    _db.drop_all()
Ejemplo n.º 13
0
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()
Ejemplo n.º 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()
Ejemplo n.º 15
0
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()
Ejemplo n.º 16
0
def db(app):
    _db.app = app

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

    yield _db

    _db.session.close()
    _db.drop_all()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 19
0
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 ☢')
Ejemplo n.º 21
0
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()
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 25
0
def init_db():
    db.drop_all()
    db.create_all()
Ejemplo n.º 26
0
	def tearDown(self):
		db.drop_all()
		unittest.TestCase.tearDown(self)
Ejemplo n.º 27
0
 def test_drop_all(self):
     db.drop_all()
     db.rows('select * from data')
Ejemplo n.º 28
0
 def teardown():
     db.session.remove()
     db.drop_all()
Ejemplo n.º 29
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Ejemplo n.º 30
0
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)
Ejemplo n.º 31
0
def dropdb():
    """
    Drops all database tables
    """
    if prompt_bool("Are you sure you want to lose all your data"):
        db.drop_all()
Ejemplo n.º 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()
[]
>>> 
Ejemplo n.º 33
0
 def teardown():
     db.session.remove()
     db.drop_all()
Ejemplo n.º 34
0
def drop_db():
	db.drop_all()
Ejemplo n.º 35
0
def database(app):
    with app.app_context():
        db.drop_all()
        db.create_all()

    yield db
Ejemplo n.º 36
0
 def setup(self):
     db.drop_all()
     db.create_all()
Ejemplo n.º 37
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Ejemplo n.º 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)
Ejemplo n.º 39
0
def drop():
    """Drops database tables"""
    if prompt_bool('Are you sure you want to lose all your data?'):
        db.drop_all()
Ejemplo n.º 40
0
def drop_create_tables():
    db.session.commit()
    db.drop_all()
    db.create_all()
    db.session.commit()
Ejemplo n.º 41
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Ejemplo n.º 42
0
 def tearDown(self):
     db.drop_all()
     self.context.pop()
Ejemplo n.º 43
0
def app():
    app_ = create_app(resolve_config('test'))
    with app_.app_context():
        db.create_all()
        yield app_
        db.drop_all()
Ejemplo n.º 44
0
def syncdb():
    if prompt_bool('Are you sure, this will delete your database'):
        db.drop_all()
        db.create_all()
    else:
        pass