Пример #1
0
def app():
    # load 'TestConfig' from config.py
    app = create_app(config_name='test')
    from api.extensions import db

    with app.app_context():
        db.create_all()
        yield app
        db.drop_all()
Пример #2
0
def db_setup():
    """create tables
    """
    db.create_all()


# @click.command()
# @with_appcontext
# def db():
#     manager.add_command('db', MigrateCommand)
Пример #3
0
def db(app):
    _db.app = app

    with app.app_context():
        _db.create_all()

    yield _db

    _db.session.close()
    _db.drop_all()
Пример #4
0
def create_db_tables():
    """
    Create the required database tables if they do not exist.
    """

    if click.confirm('Create tables in this DB? : ' +
                     current_app.config["SQLALCHEMY_DATABASE_URI"]):
        db.create_all()
        click.echo('Done.')
    else:
        click.echo('Canceled.')
Пример #5
0
    def setUp(self):
        self.app = create_app(config['test'])
        self.client = self.app.test_client

        self.headers = {
            'Content-Type': 'application/json',
            'Authorization': None
        }
        self.username = '******'
        self.serialized_user = json.dumps({'username': '******'})

        with self.app.app_context():
            db.create_all()
Пример #6
0
    def setUpClass(self):
        self.app = FLASKR.test_client()
        db.init_app(FLASKR)
        with FLASKR.app_context():
            db.create_all()
        self.app.post(
            "/api/v1/auth/register",
            data=json.dumps(
                dict(
                    name=USER_DATA["name"],
                    email=USER_DATA["email"],
                    username=USER_DATA["username"],
                    password=USER_DATA["password1"],
                    password2=USER_DATA["password2"],
                )),
            content_type="application/json",
            follow_redirects=True,
        )
        response = self.app.post(
            "/api/v1/auth/login",
            data=json.dumps(
                dict(email=USER_DATA["email"],
                     password=USER_DATA["password1"])),
            content_type="application/json",
            follow_redirects=True,
        )
        res = response.data.decode("ASCII")
        res = json.loads(res)
        self.auth_token = res["access_token"]

        response = self.app.post(
            "/api/v1/project/create",
            data=json.dumps(
                dict(project_name=PROJECT_DATA["project_name"],
                     project_description=PROJECT_DATA["project_description"])),
            headers={
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json',
                'Authorization': "Bearer " + self.auth_token
            },
            follow_redirects=True,
        )
        res = response.data.decode("ASCII")
        res = json.loads(res)
        self.project_id = str(res["body"]["project"]["id"])
Пример #7
0
def init():
    """Init application, create database tables
    and create a new user named admin with password admin
    """
    from api.extensions import db
    from api.models import User
    click.echo("create database")
    db.create_all()
    click.echo("done")

    click.echo("create user")
    user = User(username='******',
                email='*****@*****.**',
                password='******',
                active=True)
    db.session.add(user)
    db.session.commit()
    click.echo("created user admin")
Пример #8
0
 def setUpClass(self):
     self.app = FLASKR.test_client()
     db.init_app(FLASKR)
     with FLASKR.app_context():
         db.create_all()
     self.app.post(
         "/api/v1/auth/register",
         data=json.dumps(
             dict(
                 name=USER_DATA["name"],
                 email=USER_DATA["email"],
                 username=USER_DATA["username"],
                 password=USER_DATA["password1"],
                 password2=USER_DATA["password2"],
             )),
         content_type="application/json",
         follow_redirects=True,
     )
Пример #9
0
 def setUpClass(self):
     self.app = FLASKR.test_client()
     db.init_app(FLASKR)
     with FLASKR.app_context():
         db.create_all()
     self.app.post(
         "/api/v1/auth/register",
         data=json.dumps(
             dict(
                 name=USER_DATA["name"],
                 email=USER_DATA["email"],
                 username=USER_DATA["username"],
                 password=USER_DATA["password1"],
                 password2=USER_DATA["password2"],
             )),
         content_type="application/json",
         follow_redirects=True,
     )
     self.app.post(
         "/api/v1/auth/register",
         data=json.dumps(
             dict(
                 name=USER_DATA["name2"],
                 email=USER_DATA["email2"],
                 username=USER_DATA["username2"],
                 password=USER_DATA["password1"],
                 password2=USER_DATA["password2"],
             )),
         content_type="application/json",
         follow_redirects=True,
     )
     response = self.app.post(
         "/api/v1/auth/login",
         data=json.dumps(
             dict(email=USER_DATA["email"],
                  password=USER_DATA["password1"])),
         content_type="application/json",
         follow_redirects=True,
     )
     res = response.data.decode("ASCII")
     res = json.loads(res)
     self.auth_token = res["access_token"]
Пример #10
0
def create_app():
    flask_app = Flask(__name__)
    CORS(flask_app)

    flask_app.register_blueprint(auth_views)
    flask_app.register_blueprint(db_views)

    # TODO: Need to change some of these to environment variables.
    flask_app.config[
        'SECRET_KEY'] = 'the quick brown fox jumps over the lazy dog'
    flask_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
    flask_app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(flask_app)
    with flask_app.app_context():
        db.create_all()
        create_test_admin()

    return flask_app
Пример #11
0
def setup_db():
    teardown_db()
    db.create_all()
Пример #12
0
 def setUp(self):
     db.create_all()
     g.identity = AnonymousIdentity()
Пример #13
0
import os
from dotenv import load_dotenv
from flask import render_template

from api.app import create_app
from api.extensions import db

dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
    load_dotenv(dotenv_path)

app = create_app(os.getenv('FLASK_CONFIG') or 'default')


@app.route('/')
def default_route():
    return render_template('index.html')


db.create_all(app=create_app(os.getenv('FLASK_CONFIG') or 'default'))
Пример #14
0
def db_setup():
    """create tables
    """
    db.create_all()
Пример #15
0
 def create_tables():
     db.create_all()
Пример #16
0
 def setUpClass(self):
     self.app = FLASKR.test_client()
     db.init_app(FLASKR)
     with FLASKR.app_context():
         db.create_all()
Пример #17
0
def createall():
    "Creates database tables"
    db.create_all()
Пример #18
0
def create_app():
    flask_app = Flask(__name__)
    CORS(flask_app)

    flask_app.register_blueprint(auth_views)
    flask_app.register_blueprint(db_views)

    # TODO: Need to change some of these to environment variables.
    flask_app.config[
        'SECRET_KEY'] = 'the quick brown fox jumps over the lazy dog'
    flask_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
    flask_app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(flask_app)
    with flask_app.app_context():
        db.create_all()
        create_test_admin()

    return flask_app


app = create_app()

if __name__ == '__main__':
    if not os.path.exists('db.sqlite'):
        db.create_all()

    app.run(debug=True)