def client(app): # db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() app.config["TESTING"] = True with app.test_client() as client: with app.app_context(): db.drop_all() db.create_all() yield client
def recreate_db(): try: db.reflect() db.drop_all() except SQLAlchemyError as e: raise ValueError(e) db.create_all() db.session.commit()
def tearDownClass(cls): if cls.client: # stop the flask server and the browser cls.client.get('http://localhost:5000/shutdown') cls.client.quit() cls.server_thread.join() # destroy database db.drop_all() db.session.remove() # remove application context cls.app_context.pop()
def create_db(): db.drop_all() db.create_all() db.session.commit() # Add the admin hashed_password = bcrypt.generate_password_hash(PASS_ADMIN).decode('utf-8') coordo = Coordinateur(nom="admin", email="*****@*****.**", password=hashed_password) db.session.add(coordo) db.session.commit() # Get the data credentials = GOOGLE_APP_CREDS client = connect_to_drive(credentials) coordo_sheet = client.open("flask-Coordo/Mediation").worksheet( "Accueillants") liste_accueillants_raw = coordo_sheet.get_all_values() # Handle poorly formatted emails emails_re = "([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)" tel_re = "([0-9][0-9])" liste_accueillants_to_add = \ [Accueillant( disponibilite=row[0], nom=row[1].title(), tel=''.join("; " if i % 15 == 0 else char for i, char in enumerate( ".".join(re.findall(tel_re, row[2])), 1)), adresse=row[3], email="; ".join(re.findall(emails_re, row[4])).lower(), next_action=row[5], remarques=row[6]) for i, row in enumerate(liste_accueillants_raw) if i > 1] for acc in liste_accueillants_to_add: try: db.session.add(acc) db.session.commit() except: db.session.close()
def clear_db_implementation(): db.drop_all()
def tearDown(self): db.session.remove() db.drop_all()
#!/usr/bin/env python # -*- coding: utf-8 -*- from flask_app import db db.drop_all() db.create_all()
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
from flask_app import db, models, app app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../stage.db' db.drop_all() db.create_all() newuser = models.User('parton', '*****@*****.**') db.session.add(newuser) newuser = models.User('chodera', '*****@*****.**') db.session.add(newuser) db.session.commit()
def setUp(self): db.drop_all() db.create_all()