def setUp(self): """Before each test, set up a blank database""" self.project = create_app() init_app(self.project, 'test') self.app = self.project.test_client() with self.project.test_request_context(): create_db(self.project) clear_db(self.project)
def main(): # initialize database if it doesn't exist current_path = os.path.dirname(os.path.realpath(__file__)) if not os.path.exists(os.path.join(current_path, "entries.db")): create_db() print("Database initialized") # auto-open the application webbrowser.open("http://0.0.0.0:8080/") serve(app, port=8080)
def main(): """ initialize mongodb create jwt secret if does not exist run the webserver """ create_db() create_secret() (create_app().run(host="0.0.0.0", port=5001, debug=True))
def setUp(self): ''' Sets up the testing environment adds a single category and a single question to it ''' self.test_client = app.app.test_client() app.create_db() quest = app.Question("Test Question") category = app.Category("Test Category") app.db.session.add(quest) app.db.session.add(category) app.db.session.commit() qcatassoc = app.QCATAssociation() qcatassoc.category_id = quest.id qcatassoc.question_id = category.id app.db.session.add(qcatassoc) app.db.session.commit()
def setUp(self): app = create_app("settings.TestingConfig") self.db = create_db(app) create_resources(app) self.app = app.test_client() with app.app_context(): create_tables()
def initdb(config=None): """Create DB from scratch""" init_app(flask_app, config) create_db(flask_app)
from app import create_db db = create_db() cur = db.cursor() cur.execute('''CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(32) NOT NULL UNIQUE, password VARCHAR(128) NOT NULL )''') print("Done")
user = register(uid, password) for _ in range(10): session = login(uid, password) logout(session.refresh_token) self.assertEqual(Session.find_with_user(user), []) for _ in range(10): login(uid, password) self.assertTrue(terminate_sessions(uid)) self.assertEqual(Session.find_with_user(user), []) class TestLogout(TestCase): def test_logout(self): uid, password = uuid4().hex, uuid4().hex user = register(uid, password) session = login(uid, password) logout(session.refresh_token) self.assertEqual(Session.find_with_user(user), []) if __name__ == '__main__': create_db() create_secret() main()
def initdb(): # Note: calling this will drop everything in db create_db(app)
from app import create_app, create_db from flask_migrate import Migrate app = create_app() db = create_db(app) migrate = Migrate(app, db, compare_type=True) if __name__ == "__main__": app.run(debug=True)
def setUp(self): """ clear database before each test """ self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp() app.app.config['TESTING'] = True self.app = app.app.test_client() app.create_db()
def setUpClass(cls): app.create_db()
def deploy(): """ 部署项目 """ create_db()
def initdb(env='Development'): # Note: calling this will drop everything in db # on production: heroku run python manage.py initdb -e Production app = create_app(env) create_db(app)
def initdb(env='Development'): # Note: calling this will drop everything in db app = create_app(env, manager=True) create_db(app)
def test_db(): """ Testing the DB engine existence """ assert create_db() != None