Ejemplo n.º 1
0
def test_dropped_db(client):
    """Check behavior when the db has no tables."""
    db.drop_all()
    assert b'Sorry' in client.get('/poetry/poem').data
    assert "404" in client.get('/poetry/poem/Flea').status
    # /add_samples route should not cause server error when db has no tables
    assert "404" in client.get('/poetry/add_samples').status
Ejemplo n.º 2
0
def init_db():
    """
    Drops and re-creates the SQL schema
    """
    db.drop_all()
    db.configure_mappers()
    db.create_all()
    db.session.commit()
Ejemplo n.º 3
0
def init_db():
    """
    Drops and re-creates the SQL schema
    """
    db.drop_all()
    db.configure_mappers()
    db.create_all()
    db.session.commit()
Ejemplo n.º 4
0
def _test_db(_test_app):
    test_app = _test_app
    tdb.init_app(test_app)
    try:
        initilize_test_db(tdb)
        yield tdb
    finally:
        tdb.session.commit()
        tdb.drop_all()
Ejemplo n.º 5
0
def database():
    db.session.remove()
    db.reflect()
    db.drop_all()
    db.create_all()

    yield db  # this is where the testing happens!

    db.drop_all()
Ejemplo n.º 6
0
def client():
    """ My custom test client.
    """
    app.config['TESTING'] = True
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
    # app.config['SQLALCHEMY_DATABASE_URI'] = \
    #     'mysql+mysqlconnector://test:Test12345678!@localhost/iot_test'

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

        # Add test user
        user = User(username='******', email='*****@*****.**')
        user.set_password('test')
        db.session.add(user)
        db.session.commit()

        # Add test device
        device = Device(name='test', display_name='test', user=user)
        db.session.add(device)
        db.session.commit()

        schema = {
            'test1': ['test1', 2, 1, 0],
            'test2': ['test2', 2, 1, 0],
            'control': ['control', 3, 1, 1],
        }
        device.set_schema(schema)

        # Add test data
        new_data = DeviceData(time=datetime.utcfromtimestamp(1500000000),
                              data={
                                  'test1': 10.0,
                                  'test2': 12.0,
                                  'control': False,
                              },
                              device=device)
        db.session.add(new_data)
        db.session.commit()

        # Get token
        access_token = create_access_token(identity=user.username)
        refresh_token = create_refresh_token(identity=user.username)

        my_client = MyTestClient(access_token,
                                 refresh_token,
                                 default_auth=TokenType.access)

    yield my_client

    with app.app_context():
        db.session.remove()
        db.drop_all()
Ejemplo n.º 7
0
def clear_db(db):
  confirm = input('Clear all tables? [yes/no]: ')
  if confirm == 'yes':
    # drop/create tables
    print('#'*60)
    print('Dropping all tables')
    print('#'*60)
    db.drop_all()
    print('#'*60)
    print('Creating all tables')
    print('#'*60)
    db.create_all()
    print('All tables cleared')
  elif confirm == 'no':
    exit(1)
  else:
    print('Please type yes or no')
    clear_db(db)
Ejemplo n.º 8
0
def clear_db(db):
    confirm = input('Clear all tables? [yes/no]: ')
    if confirm == 'yes':
    # drop/create tables
        print('#'*60)
        print('Dropping all tables')
        print('#'*60)
        db.drop_all()
        print('#'*60)
        print('Creating all tables')
        print('#'*60)
        db.create_all()
        print('All tables cleared')
    elif confirm == 'no':
        exit(1)
    else:
        print('Please type yes or no')
        clear_db(db)
Ejemplo n.º 9
0
def app():
    """Set up and tear down the test app."""
    from run import create_app, db

    app = create_app('testing')

    app.config['TESTING'] = True

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

    db.create_all()

    yield app

    db.session.remove()
    db.drop_all()
    app_context.pop()
Ejemplo n.º 10
0
def initial_db():
    ### Drop All tables
    db.reflect()
    db.drop_all()
    ### Clear sessions
    session.clear()
    session.pop('username', None)
    ### Create Tables
    db.create_all()
    ### Create Roles
    administrative_staff = models.Role(name='IdariPersonel')
    teacher = models.Role(name='Ogretmen')
    student = models.Role(name='Ogrenci')
    db.session.add(administrative_staff)
    db.session.add(teacher)
    db.session.add(student)
    db.session.commit()

    ### Create Role Funcs
    func_create_user = models.RoleFuncs(name='CreateUser', role_id=administrative_staff.id)
    func_see_all_user = models.RoleFuncs(name='SeeAllUser', role_id=administrative_staff.id)
    db.session.add(func_create_user)
    db.session.add(func_see_all_user)
    db.session.commit()

    func_danisman_ata = models.RoleFuncs(name='AssignCons', role_id=administrative_staff.id)
    db.session.add(func_danisman_ata)
    db.session.commit()

    ###################### Create Administrative Staff
    new_administrative_staff = create_new_user(
        uname="admin",
        password="******",
        fname= "Mustafa",
        mname= "Kemal",
        sname= "Ataturk",
        email= "*****@*****.**",
        role_id=administrative_staff.id
    )
    return '<a href="/">Ok!</a>'
Ejemplo n.º 11
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Ejemplo n.º 12
0
from run import db
from run import Role, User

db.drop_all()
db.create_all()

admin_role = Role(name='Admin')

user_john = User(username='******', role=admin_role)

db.session.add(admin_role)

db.session.commit()
Ejemplo n.º 13
0
def api_delete_all():
    db.drop_all()
    db.create_all()
    create_test_data()
    return {'status': 'Successfully deleted all database data'}, 200
Ejemplo n.º 14
0
 def setUp(self):
     db.drop_all()
     db.create_all()
     db.session.commit()
Ejemplo n.º 15
0
def dropall():
    db.drop_all()
    print("all tables dropped! remember to delete directory: migrations")