def rebuild_after(app): with app.app_context() as ctx: yield ctx try: db.session.commit() # prevents hangs except DatabaseError: db.session.rollback() raise db.drop_all() db.create_all() # Apparently you shouldn't change the database structure while # the app is running. But I'm doing it. seeds.build_testing_objects() db.session.commit() # The following is temporary for testing. from app.models.exports import County assert County.query.get(1) is not None
def test_one_to_one(ctx): base = declarative_base(cls=Base) class Account(base): belongs_to("Supplier") class Supplier(base): has_one("Account") db.create_all() account = Account() try: account.supplier except AttributeError: pytest.fail("relationship was not defined.") supplier = Supplier() try: supplier.account except AttributeError: pytest.fail('relationship was not defined.')
def test_one_to_many(ctx): base = declarative_base(cls=Base) class Building(base): belongs_to("Infrastructure") class Infrastructure(base): has_many("Buildings") db.create_all() infrastructure = Infrastructure() try: infrastructure.buildings except AttributeError: pytest.fail("relationship was not defined.") building = Building() try: building.infrastructure except AttributeError: pytest.fail('relationship was not defined.')
def setup_app(): """Create an configure an app.""" app = udk.app app.config.from_object(config.TestingConfig) # overwrite dev config. engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI']) if not database_exists(engine.url): create_database(engine.url) with app.app_context(): db.drop_all() db.create_all() # Create the game world # objs = None objs = seeds.build_testing_objects() db.session.commit() yield (app, objs) app.config['SQLALCHEMY_ECHO'] = False with app.app_context(): db.drop_all()
def init_db(): """Initialize the database.""" with app.app_context(): db.create_all() print("Create all tables.")
def db_init(): """Initialize the database.""" db.create_all() click.echo("Create all tables.")