Ejemplo n.º 1
0
def create_app(config_class=DevConfig):
    """
    Creates an application instance to run
    :return: A Flask object
    """
    app = Flask(__name__)

    # Configure langbridge wth the settings from config.py
    app.config.from_object(config_class)

    # Initialise plugins
    db.init_app(app)
    login_manager.init_app(app)

    from populate_db import populate_db
    from langbridge.models import Teacher, User, BankAccount, Wallet, Language, Lesson, LessonReview
    with app.app_context():
        db.create_all()
        populate_db()

    # Register error handlers
    app.register_error_handler(404, page_not_found)
    app.register_error_handler(500, internal_server_error)

    # Register Blueprints
    from langbridge.main.routes import bp_main
    app.register_blueprint(bp_main)

    from langbridge.auth.routes import bp_auth
    app.register_blueprint(bp_auth)

    return app
Ejemplo n.º 2
0
def create_app(config_class=DevConfig):
    app = Flask(__name__)
    app.config.from_object(config_class)
    global images
    images = UploadSet('image', IMAGES)
    app.config['UPLOADED_IMAGE_DEST'] = 'static/images'
    configure_uploads(app, images)
    db.init_app(app)
    login_manager.init_app(app)

    # The following is needed if you want to map classes to an existing database
    # with app.app_context():
    #     db.Model.metadata.reflect(db.engine)

    from populate_db import populate_db
    from app.models import Member  # , Art, Artist, ContributingArtists, Subscriptions, Events, Portfolio
    with app.app_context():
        db.create_all()
        populate_db()
    # Register Blueprints
    from app.main.routes import bp_main
    app.register_blueprint(bp_main)

    from app.auth.routes import bp_auth
    app.register_blueprint(bp_auth)

    return app
Ejemplo n.º 3
0
def create_db():

    # Creates or opens a file called mydb with a SQLite3 DB
    db = sqlite3.connect('data/mydb')

    cursor = db.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS genes(id INTEGER PRIMARY KEY, mirtarbase_id TEXT, mirna TEXT,
                                         species TEXT, mirna_target_gene TEXT, target_gene INTEGER,
                                         species_target_gene TEXT, experiments TEXT, support_type TEXT, refs TEXT)
    ''')

    cursor.execute('''
        CREATE TABLE IF NOT EXISTS human_gene_coords(id INTEGER PRIMARY KEY, gene_name TEXT,
                                                     chromosome_name TEXT, gene_start INTEGER, gene_end INTEGER)
    ''')

    cursor.execute('''
        CREATE TABLE IF NOT EXISTS human_mirna_coords(id INTEGER PRIMARY KEY, gene_name TEXT,
                                                     mirbase_id TEXT, chromosome_name TEXT, 
                                                     gene_start INTEGER, gene_end INTEGER)
    ''')

    populate_db()
    db.commit()
    db.close()
Ejemplo n.º 4
0
def create_app(config_class=DevConfig):
    """
    Creates an application instance to run
    :return: A Flask object
    """
    app = Flask(__name__)

    # Configure app wth the settings from config.py
    app.config.from_object(config_class)

    # Initialise the database and create tables
    db.init_app(app)

    from populate_db import populate_db
    from app.models import Teacher, Student, Course, Grade
    with app.app_context():
        db.create_all()
        populate_db()

    # Register error handlers
    app.register_error_handler(404, page_not_found)
    app.register_error_handler(500, internal_server_error)

    # Register Blueprints
    from app.main.routes import bp_main
    app.register_blueprint(bp_main)

    return app
Ejemplo n.º 5
0
def fill_db(config):
    set_config(config)
    from recastfrontend.server import app
    with app.app_context():
        from recastfrontend.server import db
        populate_db.populate_db(db)
        click.secho('filled database at: {}'.format(db.engine.url), fg='green')
Ejemplo n.º 6
0
def test_populate_db_populates_users():
    engine = sqlalchemy.create_engine('sqlite://')
    session = create_session(engine)

    try:
        populate_db(session, total_users=10)

        connection = session.connection().connection
        cursor = connection.cursor()
        cursor.execute('SELECT COUNT(*) FROM Users')
        assert cursor.fetchone()[0] == 10
        cursor.execute('SELECT COUNT(*) FROM UserSessions')
        assert cursor.fetchone()[0] >= 10
    finally:
        session.close()
Ejemplo n.º 7
0
def create_app(config_class=DevConfig):
    """
    Creates an application instance to run using settings from config.py
    :return: A Flask object
    """
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)

    from populate_db import populate_db
    from app.models import User, City, Forecast

    with app.app_context():
        db.create_all()
        populate_db()

    from app.main import bp
    app.register_blueprint(bp)

    return app
Ejemplo n.º 8
0
def refresh_db():

    # Creates or opens a file called mydb with a SQLite3 DB
    db = sqlite3.connect('data/mydb')

    cursor = db.cursor()
    cursor.execute('''
        DELETE FROM genes
    ''')

    cursor.execute('''
        DELETE FROM human_gene_coords
    ''')

    cursor.execute('''
        DELETE FROM human_mirna_coords
    ''')

    db.commit()
    populate_db()
    db.close()
def create_app(config_class=DevConfig):
    """
    Creates an application instance to run
    :return: A Flask object
    """
    app = Flask(__name__)
    app.config.from_object(config_class)
    db.init_app(app)

    from populate_db import populate_db
    from app.models import Teacher, Student, Course, Grade
    with app.app_context():
        db.create_all()
        populate_db()

    app.register_error_handler(404, page_not_found)
    app.register_error_handler(500, internal_server_error)

    from app.main.routes import bp_main
    app.register_blueprint(bp_main)

    return app
Ejemplo n.º 10
0
def create_app(config_class=DevConfig):
    """Creates an application instance to run using settings from config.py
    :return: A Flask object"""

    app = Flask(__name__)

    app.config.from_object(config_class)

    from populate_db import populate_db
    db.init_app(app)

    # The following is needed if you want to map classes to an existing database
    from app.models3 import User, City, Forecast
    with app.app_context():
        # db.Model.metadata.reflect(db.engine)
        db.create_all()
        populate_db()

    # Register Blueprints
    from app.main.routes import bp_main
    app.register_blueprint(bp_main)

    return app
Ejemplo n.º 11
0
    def setUp(self):
        self.maxDiff = None
        self.client = MongoClient()
        self.db = self.client[TEST_DB]
        self.app = TestApp(app.shopping_cart_app)
        app.db = self.db
        # Populate database with random data
        populate_db(TEST_DB)
        # Add basket for testing purposes
        # add some products to basket
        prod = self.db.products.find_one({'name_slug': 'prod-0-0'})
        req = self.app.post_json('/api/basket/add', {
            'prod_id': str(prod['_id']),
            'amount': 4
        })
        for prod in self.db.products.find(skip=1, limit=5):
            req = self.app.post_json(
                '/api/basket/add', {
                    'basket_id': json.loads(req.body)['_id'],
                    'prod_id': str(prod['_id']),
                    'amount': randint(1, 10)
                })

        self.basket = json.loads(req.body)
Ejemplo n.º 12
0
def create_app(config_class=DevConfig):
    """
    Creates an application instance to run using settings from config.py
    :return: A Flask object
    """
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    bcrypt.init_app(app)
    configure_uploads(app, photos)
    patch_request_class(app)

    from populate_db import populate_db
    from app.models import User, Item, ShippingInfo

    with app.app_context():
        db.create_all()
        populate_db()

    from app.main import bp
    app.register_blueprint(bp)

    return app
Ejemplo n.º 13
0
# -*- coding: utf-8 -*
import pytest

from populate_db import populate_db
import tt_demo
from tt_demo.queries import Query

# populate the database with examples for tests
populate_db()

# start the app
mongodb_uri = "mongodb://*****:*****@pytest.fixture(scope='module')
def client():
    with app.app.test_client() as c:
        yield c
Ejemplo n.º 14
0
def reset_test_db():
    d = DB()
    d.create_schema()
    populate_db(d)
    return d
Ejemplo n.º 15
0
csrf = CSRFProtect()


def create_app(database):
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'bgnti84;jv_d-0ngr8gvhk'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    csrf.init_app(app)
    with app.app_context():
        database.init_app(app)
    CORS(app)

    return app


db = SQLAlchemy()
app = create_app(db)

import routes
import models

from populate_db import populate_db
populate_db(db, n_products=25)

if __name__ == '__main__':

    app.run(debug=True)
Ejemplo n.º 16
0
# -*- coding: utf-8 -*-
"""
Script to determine when a college football program from a Power-5 conference
(ACC, SEC, Big Ten, Big 12, Pac-12) plays a non-Power 5 team on the road.
This a semi-rare occurance,

Requirements: Python with the SQLAlchemy and Beautiful Soup modules

Project page: https://github.com/inkjet/FBS_Power5

Author: Scott Rodkey, [email protected]

"""

from create_database import create_db, db_location
from populate_db import populate_db
from calc_matchups import calc_matchups

# Create a blank database -- edit create_database.py to specify a specific DB location
create_db()

# Scrape all FBS schools and their conference from Wikipedia and place them in the database
populate_db(db_location)

# Look at the 2015 schedule and print a week-by-week report to see if a Power-5 school
# is playing a non-Power 5 school on the road
calc_matchups(db_location)