Exemple #1
0
def test_app() -> Flask:
    """

    PyTest fixture for creating instance of the Flask app for each testing function.

    :return: instance of Flask

    """
    app = create_app({'TESTING': True})
    assert app.config['TESTING'] is True
    return app
Exemple #2
0
def app():
    app = create_app(config="testing")

    # Create the test database.
    # Note that it's very hard to get the test db to teardown after tests.
    # It's much easier to delete and recreate at the start of a test, which is
    # what we do below.
    cli_runner = app.test_cli_runner()
    cli_runner.invoke(app.cli, ["psql", "create", "--overwrite"])
    cli_runner.invoke(app.cli, ["psql", "init"])

    # The app should be ready! Provide the app instance here.
    yield app
Exemple #3
0
def app():
    flask_app = create_app()

    flask_app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL")
    flask_app.config["TESTING"] = True
    flask_app.config["JWT_COOKIE_CSRF_PROTECT"] = True
    flask_app.config["JWT_CSRF_IN_COOKIES"] = True

    with flask_app.test_request_context():
        db.create_all()

        yield flask_app

        db.session.remove()
        db.drop_all()
Exemple #4
0
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from backend import api
app = api.create_app()
app.run(host='0.0.0.0')
Exemple #5
0
import numpy as np
import json

with open('reviews.json') as f:
    reviews = json.load(f)
np.random.seed(316)

dataset = pd.read_csv("item_data.csv")

os.chdir("backend")
try:
    os.remove(os.path.join("api", "database.db"))
except FileNotFoundError as e:
    print("No database to delete")

db.create_all(app=create_app())

os.chdir("api")

# os.system("echo hello; python3 populatedb.py")

conn = sqlite3.connect('database.db')

indices = []
for index, row in dataset.iterrows():
    if '$' not in str(row['Price']):
        indices.append(index)
dataset = dataset.drop(indices)

item_id = 1
companies = {}
Exemple #6
0
from backend.api import create_app

app = create_app()
Exemple #7
0
#!/usr/bin/env python
import glob
import os
import shutil
import subprocess
import click
from flask.cli import FlaskGroup
from backend.config import DevelopmentConfig
from backend.api import db, create_app
from backend.api.models import User

app = create_app(DevelopmentConfig())

cli = FlaskGroup(
    add_app_option=False,
    create_app=lambda _: app,
    help='Time tracker CLI',
)


@cli.command(with_appcontext=False)
def clean():
    """Cleans build files."""
    shutil.rmtree('./dist', ignore_errors=True)
    for path in glob.iglob('./backend/**/__pycache__', recursive=True):
        shutil.rmtree(path, ignore_errors=True)


@cli.command()
def create_db():
    """Create database"""
Exemple #8
0
def get_db_engine():
    db.__init__(app=create_app())
    return db
Exemple #9
0
def initialize_tables():
    db.create_all(app=create_app())
Exemple #10
0
from __future__ import with_statement

import sys
from os.path import dirname, abspath
sys.path.append(dirname(dirname(abspath(__file__))))

from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig

from backend.models import *
from backend.core import db
from backend.api import create_app

app = create_app()

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
Exemple #11
0
 def _create_app(self):
     return create_app(settings, register_security_blueprint=True)
Exemple #12
0
def app():
    app = create_app(TestConfig())
    yield app