Exemplo n.º 1
0
def recreate_db():
    """
    Recreates a local database. Do not use in prod
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
def client():
    app.config['TESTING'] = True

    test_client = app.test_client()

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

        yield test_client
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def resetdb():
    """ Drop & create a database with all of the tables defined in
        your SQLAlchemy models.
        DO NOT USE IN PRODUCTION.
    """
    if app.config['ENV'] != "prod":
        print("Dropping database...")
        db.drop_all()
        print("Seeding database...")
        createdb()
        seed()
Exemplo n.º 9
0
def resetdb():
    """ Drop & create a database with all of the tables defined in
        your SQLAlchemy models.
        DO NOT USE IN PRODUCTION.
    """
    if app.config['ENV'] != "prod":
        print("Dropping database...")
        db.drop_all()
        print("Seeding database...")
        createdb()
        seed()
Exemplo n.º 10
0
 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()
Exemplo n.º 11
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()
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
def reset_db_all():
    # It might be  required to do a cascade delete to correctly the
    # vulnerability table
    for table in ('vulnerability', 'vulnerability_template', 'comment',
                  'faraday_user'):
        try:
            db.engine.execute('DROP TABLE {} CASCADE'.format(table))
        except:
            pass
    db.drop_all()

    # db.create_all()
    # Ugly hack to create tables and also setting alembic revision
    import server.config
    conn_string = server.config.database.connection_string
    from server.commands.initdb import InitDB
    InitDB()._create_tables(conn_string)
Exemplo n.º 14
0
def init_db():
    """ Initialize database: drop and create all columns """
    db.drop_all()
    db.create_all()
Exemplo n.º 15
0
def drop_db():
    """
    Drops the db tables.
    """
    db.drop_all()
Exemplo n.º 16
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()
Exemplo n.º 17
0
 def teardown():
     db.session.remove()
     db.drop_all()
Exemplo n.º 18
0
def dropdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """
    if app.config['ENV'] != "prod":
        db.drop_all()
Exemplo n.º 19
0
def dropdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """
    if app.config['ENV'] != "prod":
        db.drop_all()
Exemplo n.º 20
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Exemplo n.º 21
0
 def setUp(self):
     db.drop_all()
     db.create_all()
Exemplo n.º 22
0
 def teardown():
     db.session.remove()
     db.drop_all()
Exemplo n.º 23
0
 def setUp(self):
     db.drop_all()
     db.create_all()
Exemplo n.º 24
0
 def tearDown(self):
     db.drop_all()
     db.session.remove()
     self.app_context.pop()
Exemplo n.º 25
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Exemplo n.º 26
0
def init_db():
    """ Initialize database: drop and create all columns """
    db.drop_all()
    db.create_all()