def create_db(): """ Initialize new database """ from flask_app import user_datastore db.drop_all() # Empty database db.create_all() # Creates all tables from models # Create roles to separate between administrators and regular users user_datastore.create_role(name="instructor", description="Code club instructor") user_datastore.create_role(name="admin", description="Site administrator") # Create a default admin user to start off with # This should only be used to create a new admin user in production and then deleted user_datastore.create_user(email="*****@*****.**", password="******") user_datastore.add_role_to_user("*****@*****.**", "admin") db.session.commit() # Commit changes to database
def client(request): """ Creates the test client """ client = app.test_client() app.config.from_pyfile("config/testing.py") # Update celery app config for testing current_app.conf.update(app.config) # Add email and password as globals for easy ref. global EMAIL EMAIL = app.config["TEST_EMAIL"] global PASSWORD PASSWORD = app.config["TEST_PASSWORD"] # Initialize db and add a test user create_db() user_datastore.create_user(email=EMAIL, password=PASSWORD) db.session.commit() return client