def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['BASEDIR'] = os.getcwd() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(app.config['BASEDIR'], TEST_DB) self.client = app.test_client() db.drop_all() db.create_all() self.airport1 = Airport( **{ "name": "name1", "city": "city", "country": "country", "iata": "iata", "tz": "tz", "type": "type", "source": "source", }) self.airport2 = Airport( **{ "name": "name2", "city": "city1", "country": "country", "iata": "iata", "tz": "tz3", "type": "type", "source": "source", }) db.session.add(self.airport1) db.session.add(self.airport2) db.session.commit() self.handle = 'test'
def test_context(): ''' Test Configuration ''' app = create_app('testing') app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgres://*****:*****@localhost:5432/verse_testing' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.app_context().push() test_client = app.test_client() with app.app_context(): db.create_all() dummy_user = UserModel({ 'username': '******', 'email': '*****@*****.**', 'password': '******' }) dummy_user.save() token = Auth.generate_token(dummy_user.id) yield test_client, dummy_user, token db.session.close() db.drop_all()
def create(): print "Creating tables..." db.create_all() print "Fixture: Creating Frontier's system account" if User.create(account_id="aabacd", secret_key="123", email="*****@*****.**"): print "Fixture: Create Success!"
def db(app): # Create the tables _db.app = app _db.create_all() yield _db _db.drop_all()
def client(): """Test client for Flask WSGI application""" app = create_app(TestConfig) with app.app_context(): t_client = app.test_client() db.create_all() yield t_client db.drop_all()
def create_app(): flask_app = Flask(__name__) flask_app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_CONNECTION_URI flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False flask_app.app_context().push() db.init_app(flask_app) db.create_all() return flask_app
def init_dev_data(): """Initializes database with data for development and testing""" db.drop_all() db.create_all() print("Initialized Freelance-Tracker Database.") db.session.commit() print("Added dummy data.")
def client(): app = create_app() app.config['TESTING'] = True with app.test_client() as client: with app.app_context(): db.create_all() seed_db() yield client
def setUpModule(): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' app.config['TESTING'] = True app.config['DEBUG'] = True app.config['JWT_SECRET_KEY'] = 'TESTING' with app.app_context(): models_db.create_all() populatedb()
def db(app, request): def teardown(): _db.drop_all() _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def db(app, request): """Testable application databases.""" def teardown(): _db.drop_all() _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def db(app, request): """ Session-wide test DB """ def teardown(): _db.drop_all() _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def setUp(self): db.create_all() # example task t = Task() t.name = 'test added task' db.session.add(t) db.session.commit() self.task = Task.query.filter_by(name=t.name).first()
def resetdb_command(): """Destroys and creates the database + tables.""" from sqlalchemy_utils import database_exists, create_database, drop_database if database_exists(DB_URL): print('Deleting database.') drop_database(DB_URL) if not database_exists(DB_URL): print('Creating database.') create_database(DB_URL) print('Creating tables.') db.create_all() print('ResetDB completed')
def setUpClass(cls): from src.app import application from src.models import db from src import settings application.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://{0:s}:{1:s}@{2:s}:{3:d}/{4:s}'.format( settings.DB_USER, settings.DB_PASS, settings.DB_HOST, settings.DB_PORT, settings.DB_NAME) application.config['TESTING'] = True db.init_app(application) db.create_all(app=application) cls.test_app = application.test_client() cls.db = db cls.application = application
def db(app, request): """Session-wide test database.""" if os.path.exists(TESTDB_PATH): os.unlink(TESTDB_PATH) def teardown(): _db.drop_all() os.unlink(TESTDB_PATH) _db.app = app _db.create_all() mock_database(_db) request.addfinalizer(teardown) return _db
def main(): core = os.environ["CORE"] db_path = os.path.join(core, "backend/database.db") os.environ["DATABASE_FILE_PATH"] = f"/{db_path}" app = Flask(__name__) app.app_context().push() init_app(app) db.create_all() print("seeding admin users") seed_admins(db, "users.tsv") print("seeding lifts") seed_class(db, "lifts.tsv", Lift)
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False db.init_app(app) with app.app_context(): db.create_all() example_user = User(id=1, email="*****@*****.**", username="******") example_user.set_password("111") db.session.merge(example_user) db.session.commit() self.app = app.test_client()
def setUpClass(self): """Excuted in the beginning of the test, the target of this test is that all tests run in order at once """ """Define test variables and initialize src.""" self.app = create_app() self.client = self.app.test_client self.database_name = "casting_agency_test" self.database_path = "postgresql://*****:*****@{}/{}".format('localhost:5432', self.database_name) # binds the src to the current context self.new_actor = {"name": "Markos24", "age": 23, "gender": "Male"} self.new_movie = {"title": "the real stuff", "release_date": "08/20/2020"} setup_db(self.app, self.database_path) with self.app.app_context(): db.init_app(self.app) # create all tables db.drop_all() db.create_all()
def setUp(self): db.create_all() sampleuser = Users(user_name="test", password="******") db.session.add(sampleuser) sampletechnique = Techniques(name="test", difficulty="test", description="test") db.session.add(sampletechnique) samplemember = Members(name="test", level="test", affiliation="test") db.session.add(samplemember) date = datetime.datetime.now() sampleclass = Classes(date=date) db.session.add(sampleclass) db.session.commit() techniqueintersect = ClassesTechnique(class_id=sampleclass.id, technique_id=sampletechnique.id) db.session.add(techniqueintersect) memberintersect = ClassesMember(class_id=sampleclass.id, member_id=samplemember.id) db.session.add(memberintersect) db.session.commit()
def create_db(): db.drop_all() db.create_all() db.session.commit() click.echo("\nDatabase created.\n")
def create_db(): db.create_all()
# /run.py import os from dotenv import load_dotenv from src.app import create_app, create_db from src.models import db if __name__ == '__main__': # Load the environment variables load_dotenv(override=True) env_name = os.getenv('FLASK_ENV') db_url = os.getenv('DATABASE_URL') # Create database if doesn't exist create_db(db_url) # Create the application app = create_app(env_name) # Create the tables with app.app_context(): db.create_all() # Run the application app.run()
#!/usr/local/bin/python3 """ RESTful API """ import logging import connexion from src import SWAGGER_PATH from src import settings from src.config import log from src.models import db log.init() logger = logging.getLogger('app') logger.info('Path of swagger file: {path}'.format(path=SWAGGER_PATH)) app = connexion.App(__name__, specification_dir=SWAGGER_PATH) app.add_api('employee.yaml') application = app.app application.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://{0:s}:{1:s}@{2:s}:{3:d}/{4:s}'.format( settings.DB_USER, settings.DB_PASS, settings.DB_HOST, settings.DB_PORT, settings.DB_NAME) application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(application) db.create_all(app=application) if __name__ == '__main__': application.run(port=settings.APP_PORT)
def create_db(): db.create_all() return "DB Created!"
def setUp(self): app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" db.create_all() app.config["WTF_CSRF_ENABLED"] = False app.config["DEBUG"] = False self.client = app.test_client()
def db(app, request): """Returns session-wide initialised database""" with app.app_context(): _db.create_all()
def setUp(self): db.create_all()
def create_tables(): db.create_all()
def init_db(): db.drop_all() db.create_all()
def init_db(): """Initializes database and any model objects necessary for assignment""" db.drop_all() db.create_all() print("Initialized Freelance-Tracker Database.")