def app(): config = { "SQLALCHEMY_DATABASE_URI": "sqlite:///../db/test.db", "TESTING": True } app = create_app(config) with app.app_context(): db.create_all() yield app
def db_handle(): db_fd, db_fname = tempfile.mkstemp() app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + db_fname app.config["TESTING"] = True with app.app_context(): db.create_all() yield db os.close(db_fd) os.unlink(db_fname)
def setUp(self): app.config["TESTING"] = True app.config["CSRF_ENABLED"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(defaults.BASEDIR, "db/test.db") self.app = app.test_client() db.create_all() u = models.User("Jelle", "de Jong", "*****@*****.**", "123") db.session.add(u) db.session.commit() d = models.Diary("Mijn dagboek") d.owner_id = u.id db.session.add(d) db.session.commit()
def setUp(self): """ setup database """ app.config["TESTING"] = True app.config["CSRF_ENABLED"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join( defaults.BASEDIR, "db/test.db") self.app = app.test_client() db.create_all() u = models.User("Jelle", "de Jong", "*****@*****.**", "123") db.session.add(u) db.session.commit() d = models.Diary("Mijn dagboek") d.owner_id = u.id db.session.add(d) db.session.commit()
def create(): "Creates database tables from sqlalchemy models" db.create_all()
ST = models.ScheduleTask(schedule=S, task=T) db.session.add(T) db.session.add(ST) for i in s.items: I = models.Item(name=i.name, value=i.value) SI = models.ScheduleItem(schedule=S, item=I) db.session.add(I) db.session.add(SI) db.session.commit() if __name__ == "__main__": config = { "SQLALCHEMY_DATABASE_URI": "sqlite:///../db/test.db", "TESTING": True } app = create_app(config) db.create_all() populator = Populator() s = Populator.Schedule( "testSchedule", datetime.strptime("2019-05-04 08:00:00", "%Y-%m-%d %H:%M:%S"), datetime.strptime("2019-05-04 16:00:00", "%Y-%m-%d %H:%M:%S")) s.add_event(Populator.Event("testEvent", 4, "testNote")) s.add_task(Populator.Task("testTask", 100, "testGoal", "testResult")) s.add_item(Populator.Item("testItem", 50.0)) populator.add_schedule(s) populator.create_all()