コード例 #1
0
    def test_scores_with_generate(self, generate=False):
        if generate:
            db.drop_all()
            db.create_all()
            generate.seed()
            self.login('*****@*****.**')
        else:
            backup = Backup.query.filter_by(submitter_id=self.user1.id, submit=True).first()
            score = Score(backup_id=backup.id, kind="Composition", score=2.0,
                          message="Good work", assignment_id=self.assignment.id,
                          user_id=backup.submitter_id, grader=self.staff1)
            db.session.add(score)
            db.session.commit()
            self.login(self.staff1.email)

        endpoint = '/admin/course/1/assignments/1/scores'
        response = self.client.get(endpoint)
        self.assert_200(response)
        csv_rows = list(csv.reader(StringIO(str(response.data, 'utf-8'))))

        scores = Score.query.filter_by(assignment_id=1).all()

        backup_creators = []
        for s in scores:
            backup_creators.extend(s.backup.owners())

        self.assertEquals(len(backup_creators), len(csv_rows) - 1)
コード例 #2
0
ファイル: conftest.py プロジェクト: infobyte/faraday
def database(app, request):
    """Session-wide test database."""

    def teardown():
        try:
            db.engine.execute('DROP TABLE vulnerability CASCADE')
        except Exception:
            pass
        try:
            db.engine.execute('DROP TABLE vulnerability_template CASCADE')
        except Exception:
            pass
        db.drop_all()

    # Disable check_vulnerability_host_service_source_code constraint because
    # it doesn't work in sqlite
    vuln_constraints = db.metadata.tables['vulnerability'].constraints
    vuln_constraints.remove(next(
        constraint for constraint in vuln_constraints
        if constraint.name == 'check_vulnerability_host_service_source_code'))

    db.app = app
    db.create_all()

    request.addfinalizer(teardown)
    return db
コード例 #3
0
ファイル: initdb.py プロジェクト: infobyte/faraday
 def _create_tables(self, conn_string):
     print('Creating tables')
     from server.models import db
     current_app.config['SQLALCHEMY_DATABASE_URI'] = conn_string
     try:
         db.create_all()
     except OperationalError as ex:
         if 'could not connect to server' in ex.message:
             print('ERROR: {red}PostgreSQL service{white} is not running. Please verify that it is running in port 5432 before executing setup script.'.format(red=Fore.RED, white=Fore.WHITE))
             sys.exit(1)
         elif 'password authentication failed' in ex.message:
             print('ERROR: ')
             sys.exit(1)
         else:
             raise
     except ProgrammingError as ex:
         print(ex)
         print('Please check postgres user permissions.')
         sys.exit(1)
     except ImportError as ex:
         if 'psycopg2' in ex:
             print(
                 'ERROR: Missing python depency {red}psycopg2{white}. Please install it with {blue}pip install psycopg2'.format(red=Fore.RED, white=Fore.WHITE, blue=Fore.BLUE))
             sys.exit(1)
         else:
             raise
     else:
         from alembic.config import Config
         from alembic import command
         alembic_cfg = Config(os.path.join(os.getcwd(), 'alembic.ini'))
         command.stamp(alembic_cfg, "head")
コード例 #4
0
 def _create_tables(self, conn_string):
     print('Creating tables')
     from server.models import db
     current_app.config['SQLALCHEMY_DATABASE_URI'] = conn_string
     try:
         db.create_all()
     except OperationalError as ex:
         if 'could not connect to server' in ex.message:
             print(
                 'ERROR: {red}PostgreSQL service{white} is not running. Please verify that it is running in port 5432 before executing setup script.'
                 .format(red=Fore.RED, white=Fore.WHITE))
             sys.exit(1)
         elif 'password authentication failed' in ex.message:
             print('ERROR: ')
             sys.exit(1)
         else:
             raise
     except ProgrammingError as ex:
         print(ex)
         print('Please check postgres user permissions.')
         sys.exit(1)
     except ImportError as ex:
         if 'psycopg2' in ex:
             print(
                 'ERROR: Missing python depency {red}psycopg2{white}. Please install it with {blue}pip install psycopg2'
                 .format(red=Fore.RED, white=Fore.WHITE, blue=Fore.BLUE))
             sys.exit(1)
         else:
             raise
     else:
         from alembic.config import Config
         from alembic import command
         alembic_cfg = Config(os.path.join(os.getcwd(), 'alembic.ini'))
         command.stamp(alembic_cfg, "head")
コード例 #5
0
def createdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """

    db.create_all()
    directory = os.path.join('.', 'initdata', 'timeseries')
    for root, dirs, files in os.walk(directory):
        for file in files:
            symbol = file.split('.')[0]
            with open(os.path.join(root, file), 'r') as f:
                reader = csv.reader(f)
                next(reader, None)
                for row in reader:
                    mock = MockTimeSeries(symbol, *row)
                    db.session.add(mock)
                    db.session.flush()
                db.session.commit()

    with open(os.path.join('.', 'initdata', 'portfolio',
                           'mock_portfolio.csv')) as f:
        reader = csv.reader(f)
        for row in reader:
            amount = random.randint(100, 500)
            symbol, company, industry = row
            portfolio = Portfolio(
                symbol, company, industry, 100 * amount,
                MockTimeSeries.query.filter_by(
                    symbol=row[0].lower()).order_by('time').all()[0].close)
            print(portfolio.symbol)
            db.session.add(portfolio)
            db.session.commit()
コード例 #6
0
def recreate_db():
    """
    Recreates a local database. Do not use in prod
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
コード例 #7
0
ファイル: conftest.py プロジェクト: superf0sh/faraday
def database(app, request):
    """Session-wide test database."""
    def teardown():
        if db.engine.dialect.name == 'sqlite':
            # since sqlite was created in a temp file we skip the drops.
            return
        try:
            db.engine.execute('DROP TABLE vulnerability CASCADE')
        except Exception:
            pass
        try:
            db.engine.execute('DROP TABLE vulnerability_template CASCADE')
        except Exception:
            pass
        db.drop_all()

    # Disable check_vulnerability_host_service_source_code constraint because
    # it doesn't work in sqlite
    vuln_constraints = db.metadata.tables['vulnerability'].constraints
    try:
        vuln_constraints.remove(
            next(constraint for constraint in vuln_constraints
                 if constraint.name ==
                 'check_vulnerability_host_service_source_code'))
    except StopIteration:
        pass
    db.init_app(app)
    db.create_all()

    request.addfinalizer(teardown)
    return db
コード例 #8
0
def create_db():
    """
    Creates the db tables.
    """
    db.create_all()
    populate_roles()
    create_admin_user()
コード例 #9
0
    def test_scores_with_generate(self, generate=False):
        if generate:
            db.drop_all()
            db.create_all()
            generate.seed()
            self.login('*****@*****.**')
        else:
            backup = Backup.query.filter_by(submitter_id=self.user1.id,
                                            submit=True).first()
            score = Score(backup_id=backup.id,
                          kind="Composition",
                          score=2.0,
                          message="Good work",
                          assignment_id=self.assignment.id,
                          user_id=backup.submitter_id,
                          grader=self.staff1)
            db.session.add(score)
            db.session.commit()
            self.login(self.staff1.email)

        endpoint = '/admin/course/1/assignments/1/scores.csv'
        response = self.client.get(endpoint)
        self.assert_200(response)
        csv_rows = list(csv.reader(StringIO(str(response.data, 'utf-8'))))

        scores = Score.query.filter_by(assignment_id=1).all()

        backup_creators = []
        for s in scores:
            backup_creators.extend(s.backup.owners())

        self.assertEquals(len(backup_creators), len(csv_rows) - 1)
コード例 #10
0
def database(app, request):
    """Session-wide test database."""
    def teardown():
        try:
            db.engine.execute('DROP TABLE vulnerability CASCADE')
        except Exception:
            pass
        try:
            db.engine.execute('DROP TABLE vulnerability_template CASCADE')
        except Exception:
            pass
        db.drop_all()

    # Disable check_vulnerability_host_service_source_code constraint because
    # it doesn't work in sqlite
    vuln_constraints = db.metadata.tables['vulnerability'].constraints
    vuln_constraints.remove(
        next(constraint for constraint in vuln_constraints if constraint.name
             == 'check_vulnerability_host_service_source_code'))

    db.app = app
    db.create_all()

    request.addfinalizer(teardown)
    return db
コード例 #11
0
def create_app() -> Flask:
    """Creates and returns the Flask WSGI application
    and initializes helping components"""
    # Initialize json support for wtforms
    wtforms_json.init()

    # Define the WSGI Application object
    app = Flask(__name__,
                template_folder="../../",
                static_folder="../../static")

    # Configurations
    app.config.from_object('server.config')

    # Initialize database with application
    db.init_app(app)
    with app.test_request_context():
        db.create_all()

    # Initialize login manager with application
    login_manager.init_app(app)

    # Setup the routes
    define_routes(app)

    return app
コード例 #12
0
ファイル: __init__.py プロジェクト: wanasit/webapp-template
def _init_database(app):
    db_path = os.path.join(app.instance_path, "server.sqlite")
    app.config.from_mapping(SECRET_KEY='SECRET_KEY',
                            SQLALCHEMY_DATABASE_URI='sqlite:///' + db_path,
                            SQLALCHEMY_TRACK_MODIFICATIONS=False)

    with app.app_context():
        db.init_app(app)
        db.create_all()
コード例 #13
0
ファイル: conftest.py プロジェクト: Chronowork1/hms-weave
def client():
    app.config['TESTING'] = True

    test_client = app.test_client()

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

        yield test_client
コード例 #14
0
ファイル: conftest.py プロジェクト: jjchen20/hms-weave
def client():
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
    app.config['TESTING'] = True

    test_client = app.test_client()

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

        yield test_client
コード例 #15
0
ファイル: tests.py プロジェクト: samnalkande/bookflip
    def setUp(self):

        self.app = server.create_app(TestConfig)

        self.app_context = self.app.app_context()
        self.app_context.push()

        db.create_all()

        self.test_user = User('test', '*****@*****.**', 'password')
        db.session.add(self.test_user)
        db.session.commit()

        self.client = self.app.test_client()
コード例 #16
0
def _db(database, app):
    """
    Provide the transactional fixtures with access to the database via a Flask-SQLAlchemy
    database connection.
    """
    app.config["SQLALCHEMY_DATABASE_URI"] = TEST_DATABASE_URL

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

        yield db

        db.session.remove()
        db.drop_all()
コード例 #17
0
def initApiServer(conf):
    # load config
    app.config.from_object(conf)

    # init flask sqlalchemy
    db.app = app
    db.init_app(app)
    db.create_all()

    # init API endpoints
    manager = APIManager(app, flask_sqlalchemy_db=db)
    createApi(manager)

    return app
コード例 #18
0
ファイル: conftest.py プロジェクト: pbedn/flask-app-factory
def client(request):
    app = create_app('server.settings.TestingConfig')
    client = app.test_client()

    db.app = app
    db.create_all()

    if getattr(request.module, "create_user", True):
        admin = User('admin', 'pass')
        db.session.add(admin)
        db.session.commit()

    yield client

    db.session.remove()
    db.drop_all()
コード例 #19
0
def database(app, request):
    """Session-wide test database."""

    # Disable check_vulnerability_host_service_source_code constraint because
    # it doesn't work in sqlite
    vuln_constraints = db.metadata.tables['vulnerability'].constraints
    try:
        vuln_constraints.remove(
            next(constraint for constraint in vuln_constraints
                 if constraint.name ==
                 'check_vulnerability_host_service_source_code'))
    except StopIteration:
        pass
    db.init_app(app)
    db.create_all()

    return db
コード例 #20
0
def testapp(request):
    app = create_app('server.settings.TestConfig', env='dev')
    client = app.test_client()

    db.app = app
    db.create_all()

    if getattr(request.module, "create_user", True):
        admin = User('admin', 'supersafepassword')
        db.session.add(admin)
        db.session.commit()

    def teardown():
        db.session.remove()
        db.drop_all()

    request.addfinalizer(teardown)

    return client
コード例 #21
0
def testapp(request):
    app = create_app('server.settings.TestConfig')
    client = app.test_client()

    db.app = app
    db.create_all()

    if getattr(request.module, "create_user", True):
        admin = User('admin', 'supersafepassword')
        db.session.add(admin)
        db.session.commit()

    def teardown():
        db.session.remove()
        db.drop_all()

    request.addfinalizer(teardown)

    return client
コード例 #22
0
def create_app(instance_path=None, static_folder='../frontend/build'):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__,
                instance_path=instance_path,
                static_url_path='/',
                static_folder=static_folder,
                instance_relative_config=True)

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    db_path = os.path.join(app.instance_path, "server.sqlite")
    app.config.from_mapping(SECRET_KEY='SECRET_KEY',
                            SQLALCHEMY_DATABASE_URI='sqlite:///' + db_path,
                            SQLALCHEMY_TRACK_MODIFICATIONS=False)

    db.init_app(app)
    # apply the blueprints to the app
    from server import auth, api
    app.register_blueprint(auth.bp)
    app.register_blueprint(api.bp)

    @app.errorhandler(ValueError)
    def http_error_handler(error):
        return jsonify(code=400, message=str(error)), 400

    @app.errorhandler(HTTPException)
    def http_error_handler(error):
        return jsonify(code=error.code, message=error.description), error.code

    @app.route('/')
    def home():
        return redirect('/index.html', code=302)

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

    return app
コード例 #23
0
ファイル: manage.py プロジェクト: MACSIFS/IFS
def init_db():
    """ Initialize database: drop and create all columns """
    db.drop_all()
    db.create_all()
コード例 #24
0
from argparse import ArgumentParser

from flask import Flask

from server.app import AppConfig
from server.models import db
"""
Creates the database if it does not already exist and creates all the tables inside if it
Can be run with the --delete command line flag to empty the existing database
"""
if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument(
        '--delete',
        help="DELETES ALL DATA in the database and starts over",
        action='store_true')

    drop_all = parser.parse_args().delete

    app = Flask(__name__)
    app.config.from_object(AppConfig())
    db.init_app(app)
    with app.app_context():
        if drop_all:
            db.drop_all()

        db.create_all()
コード例 #25
0
ファイル: __init__.py プロジェクト: Cal-CS-61A-Staff/ok
 def setUp(self):
     db.drop_all()
     db.create_all()
コード例 #26
0
ファイル: __init__.py プロジェクト: takluyver/ok
 def setUp(self):
     db.create_all()
コード例 #27
0
ファイル: manage.py プロジェクト: OrangeCY/yspider
def createdb():
    """ create datebase"""
    db.create_all()
コード例 #28
0
def init_db():
    """ Initialize database: drop and create all columns """
    db.drop_all()
    db.create_all()
コード例 #29
0
from core.output import FileOutput
from youtube.videos import Videos
from server.models import Actor, db
from server.models import Videos as VideosDB, Relationship_Actor_Videos
from server.queries import DBYouTube
from server.main import app
import time
import progressbar
import os
import json

# scrap_basic_actors_info()
youtube_user = insert_actors_info()
video = Videos()
app.app_context().push()
db.create_all()  # create the tables and database

with open('config/actors.json') as data_file:
    actors = json.load(data_file)
    actors_dict = actors['channels']
    no_video_actors = []

    with open('config/parameters.json') as data_file:
        parameters = json.load(data_file)['parameters']

    for actor in progressbar.progressbar(actors_dict):
        channel_id = actor['id']
        channel_username = actor['username']
        channel_actor = actor['actor']
        if channel_id != 'null' and channel_id:
            directory = 'data/' + YoutubeAPI.start_time
コード例 #30
0
def createdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """
    db.create_all()
    setup_default()
コード例 #31
0
ファイル: app.py プロジェクト: Mari-W/course-server
 def create_tables():
     db.create_all()
コード例 #32
0
ファイル: __init__.py プロジェクト: sjl421/ok
 def setUp(self):
     db.drop_all()
     db.create_all()
コード例 #33
0
 def setUp(self):
     db.create_all()
コード例 #34
0
ファイル: manage.py プロジェクト: Cal-CS-61A-Staff/ok
def createdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """
    db.create_all()
    setup_default()