Ejemplo n.º 1
0
def database():
    """
    Fixture for creating an empty database. The scope is set to 'function'.
    """
    db.create_all()
    yield db
    db.drop_all()
Ejemplo n.º 2
0
def initdb():
    """ Create database """
    db.create_all()
    buildPosts()
    buildCourse()
    buildUsers()
    print('Successful')
Ejemplo n.º 3
0
def init_db():
    '''db.drop_all() && db.create_all()'''
    db.drop_all()
    print 'Drop table ok.'
    db.create_all()
    print 'Create table ok.'
    print 'Done!'
Ejemplo n.º 4
0
def init_db():
    '''db.drop_all() && db.create_all()'''
    db.drop_all()
    print 'Drop table ok.'
    db.create_all()
    print 'Create table ok.'
    print 'Done!'
Ejemplo n.º 5
0
 def setUp(self):
     # Make sure database exists
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
     with app.app_context():
         db.init_app(app)
         db.create_all()
     # Get a test client
     self.app = app.test_client()
     self.app_context = app.app_context()
Ejemplo n.º 6
0
 def setUpClass(cls):
     db.create_all()
     cls.examinee = User(username='******', role='examinee',
             fullname='Charles Dickens', exam_id='silly1', answer_page='{}')
     cls.examinee.hash_password('hard2guess')
     db.session.add(cls.examinee)
     db.session.commit()
     add_exam('silly1', 'Silly 1', (os.path.join('tests', 'testdata', 'exams', 'silly1.json')),
             (os.path.join('tests', 'testdata', 'exams', 'silly1_answers.json')))
Ejemplo n.º 7
0
def initdb():
    """ Create database """
    db.create_all()
    #usercourse()
    #userdefine()
    #buildtags()
    #buildnewpost()
    # posts = buildPosts()
    # buildCourse()
    print('Successful')
Ejemplo n.º 8
0
def db(app):
    """Clean database between test executions."""
    # Create and drop all tables for every test,
    # as transaction support with SQLAlchemy + SQLite is clumsy.
    # Didn't find a way yet to make it work.

    with app.app_context():
        _db.create_all()
        yield _db
        _db.drop_all()
Ejemplo n.º 9
0
def create_db(ctx, path):
    """Create and initialize database."""
    path = Path(path)

    if path.exists():
        exit("💥 Database already exists!")

    path.touch()
    config = DevelopmentConfig(DATABASE_PATH=path)
    app = create_app(config)

    with app.app_context():
        _db.create_all()
Ejemplo n.º 10
0
 def setUpClass(cls):
     db.create_all()
     cls.examinee = User(username='******',
                         role='examinee',
                         fullname='Charles Dickens',
                         exam_id='silly1',
                         answer_page='{}')
     cls.examinee.hash_password('hard2guess')
     db.session.add(cls.examinee)
     db.session.commit()
     add_exam('silly1', 'Silly 1',
              (os.path.join('tests', 'testdata', 'exams', 'silly1.json')),
              (os.path.join('tests', 'testdata', 'exams',
                            'silly1_answers.json')))
Ejemplo n.º 11
0
    def test_on_disk_database_is_not_overwritten(self, invoke, monkeypatch,
                                                 tmpdir):
        db = tmpdir.ensure('test.db')
        config = DevelopmentConfig(DATABASE_PATH=db)
        app = create_app(config)

        with app.app_context():
            _db.create_all()
        last_update = db.mtime()

        monkeypatch.setenv(DevelopmentConfig.ENV_DATABASE_PATH, str(db))
        check_server_is_running(invoke, 'demo')

        assert db.mtime() == last_update
Ejemplo n.º 12
0
    def setUp(self):
        app = create_app()
        basedir = os.path.abspath(os.path.dirname(__file__))
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
            basedir, 'test.db')
        self.app = app.test_client()
        app_ctx = app.app_context()
        app_ctx.push()
        db.create_all()
        s1 = User(name="Abdi", email="*****@*****.**", password=1234)
        s2 = User(name="Farshad", email="*****@*****.**", password=123)
        score1 = Score(name="Abdi", score=180)
        score2 = Score(name="Farshad", score=180)

        db.session.add(s1)
        db.session.add(s2)
        db.session.add(score1)
        db.session.add(score2)
        db.session.commit()
def main():
    if REMOVE_EXISTING:
        db.drop_all()
        db.create_all()
        print(f"Removing All Existing Database Entries")
        User.query.filter(User.user_type.isnot(UserTypes.ADMIN)).delete()
        Sponsor.query.delete()
        Sponsorship.query.delete()
        print(f"Generating Admin Accounts")
        password = bcrypt.generate_password_hash("password").decode("utf-8")
        chase = User(user_type=UserTypes.ADMIN,
                     first_name="Chase",
                     last_name="Autry",
                     email="*****@*****.**",
                     password=password)
        jake = User(user_type=UserTypes.ADMIN,
                    first_name="Jake",
                    last_name="Ammons",
                    email="*****@*****.**",
                    password=password)
        lee = User(user_type=UserTypes.ADMIN,
                   first_name="Hyeop",
                   last_name="Lee",
                   email="*****@*****.**",
                   password=password)
        db.session.add_all([chase, jake, lee])
    if GEN_SPONSORS:
        for i in range(0, NUM_SPONSORS):
            generate_sponsor(i)
    if GEN_DRIVERS:
        for i in range(0, NUM_DRIVERS):
            generate_user(i, UserTypes.DRIVER)
    if GEN_STORE_MANAGERS:
        for i in range(0, NUM_STORE_MANAGERS):
            generate_user(i, UserTypes.STORE_MANAGER)
    if GEN_SUPPORT_TICKETS:
        for i in range(0, NUM_SUPPORT_TICKETS):
            generate_support_ticket(i)
    db.session.commit()
Ejemplo n.º 14
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     self.app = app.test_client()
     db.create_all()
Ejemplo n.º 15
0
 def drop_collections():
     db.drop_all()
     db.create_all()
Ejemplo n.º 16
0
from website import db


db.create_all(bind=['sb_db'])
Ejemplo n.º 17
0
from website import app, db

if __name__ == '__main__':
    db.create_all()
    app.run(host='0.0.0.0', port=80)
Ejemplo n.º 18
0
def db_init():
    db.create_all()
Ejemplo n.º 19
0
 def setUp(self):
     self.app = app
     self.app.config.from_object('config.TestingConfig')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 20
0
def db_init():
    db.create_all()
Ejemplo n.º 21
0
    def setUp(self):

        db.create_all()
Ejemplo n.º 22
0
import os
from website import db
from website.models import User
from website.admin import add_admin
from website.exam_admin import add_exam

db.reflect()
db.drop_all()
db.create_all()

os.chdir(os.path.join('tests', 'testdata'))
add_exam('silly1', 'Silly 1', os.path.join('exams', 'silly1.json'),
        os.path.join('exams', 'silly1_answers.json'))
add_admin('admin', 'pass', 'Admin')

user1 = User(username='******', role='examinee', fullname='Thomas Hardy', exam_id='silly1', answer_page='{}')
user1.hash_password('pass')
db.session.add(user1)
user2 = User(username='******', role='examinee', fullname='Franz Kafka', exam_id='silly1', answer_page='{}')
user2.hash_password('pass')
db.session.add(user2)
db.session.commit()
Ejemplo n.º 23
0
 def setUp(self):
     db.create_all()
     pass
Ejemplo n.º 24
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()