Exemplo n.º 1
0
def app():
    app = create_app()
    db.init_app(app)
    with app.app_context():
        db.drop_all()
        db.create_all()
        initialize_test_data()
        yield app
Exemplo n.º 2
0
def plain_client():
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

        yield client
Exemplo n.º 3
0
def login_client():
    """
    This fixture create the database consisting one user
    :return:
    """
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

            create_user(email='*****@*****.**', password='******')

        yield client
Exemplo n.º 4
0
def create_tables():
    db.create_all()
    # Check if the existing company table contain data, if not then initialise with csv
    s = db.session()
    if len(s.query(CompanyModel).all()) == 0:
        print('No data in the companies table detected.')
        print('Initialising the companies table in database.')
        engine = s.get_bind()
        df = read_csv('./companies.csv')
        # reset column names in dataframe to correspond with table column names
        # this must be done to insert the data properly into the table
        df.rename(columns={'Unnamed: 0': 'id',
                           'company_name': 'name',
                           'company_logo': 'logo_url',
                           'company_website': 'website_url'}, inplace=True)
        df['review_count'] = 0
        df.to_sql('companies',
                  con=engine,
                  if_exists='append',
                  chunksize=1000,
                  index=False)
Exemplo n.º 5
0
def auth_client():
    """
    This fixture provide a authorized client, with some initial database
    :return:
    """
    load_dotenv()

    app = create_app('testing')

    with app.test_client() as client:
        with app.app_context():
            db.init_app(app)

            db.drop_all()
            db.create_all()

            user_id = create_test_db()
            access_token = create_access_token(identity=user_id)
            client.environ_base[
                'HTTP_AUTHORIZATION'] = 'Bearer ' + access_token

        yield client
Exemplo n.º 6
0
def create_table():
    db.create_all()
Exemplo n.º 7
0
def client():
    with app.app_context():
        db.drop_all()
        db.create_all(app=app)
    return app.test_client()
Exemplo n.º 8
0
def create_tables():
    db.create_all()  # create the data.db unless it's already existed
def create_tables():
    with app.app_context():
        db.create_all()