Exemplo n.º 1
0
def test_define_tables_start_with_nonempty_db(app, snapshot):
    """test define_tables()

    This function tests if tables will be redefined starting from db
    with tables with entries.

    """

    # confirm tables are defined initially and not empty
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        assert metadata.tables
        total_nentries = sum([
            len([r for r in sa.engine.execute(tbl.select())])
            for tbl in metadata.sorted_tables
        ])
        assert total_nentries > 0

    with app.app_context():
        define_tables()

    # confirm tables are defined and all empty
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        snapshot.assert_match(metadata.tables)
        total_nentries = sum([
            len([r for r in sa.engine.execute(tbl.select())])
            for tbl in metadata.sorted_tables
        ])
        assert total_nentries == 0
Exemplo n.º 2
0
def test_define_tables_start_with_empty_db(app_with_empty_db):
    """test define_tables()

    This function tests if tables will be defined starting from new db without
    any tables.

    """

    app = app_with_empty_db

    # confirm tables are not defined initially
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        assert not metadata.tables

    with app.app_context():
        define_tables()

    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        tbl_names = {
            'simulations', 'simulation_file_paths', 'maps', 'map_file_paths',
            'beams', 'beam_file_paths'
        }
        assert tbl_names == metadata.tables.keys()
Exemplo n.º 3
0
def app():
    config_path = Path(SAMPLE_DIR, "config.py")
    database_uri = "sqlite:///:memory:"
    app = create_app(config_path=config_path,
                     SQLALCHEMY_DATABASE_URI=database_uri)
    with app.app_context():
        define_tables()
    yield app
Exemplo n.º 4
0
def app():
    database_uri ="sqlite:///:memory:"
    csvdir = os.path.join(SAMPLE_DIR, 'csv')
    app = create_app(SQLALCHEMY_DATABASE_URI=database_uri)
    with app.app_context():
        define_tables()
        import_tables_from_csv_files(csvdir)
    yield app
Exemplo n.º 5
0
def test_export_db_to_csv_files(app, tmpdir_factory, snapshot):
    outdir = str(tmpdir_factory.mktemp('csv'))

    with app.app_context():
        export_db_to_csv_files(outdir)

    with app.app_context():
        define_tables()
        import_tables_from_csv_files(outdir)
        snapshot.assert_match(export_db_to_dict_of_dict_list())
Exemplo n.º 6
0
def create_db_with_csv_files():
    """create a test DB, load data from CSV files"""
    config_path = Path(SAMPLE_DIR, "config.py")
    csvdir = Path(SAMPLE_DIR, "csv")
    app = create_app(config_path=config_path)
    with app.app_context():
        define_tables()
        import_tables_from_csv_files(csvdir)
    yield
    database_path = Path(SAMPLE_DIR, "product.sqlite3")
    database_path.unlink()
Exemplo n.º 7
0
def app_empty():
    database_uri = "sqlite:///:memory:"
    y = create_app(
        SQLALCHEMY_DATABASE_URI=database_uri,
        GITHUB_AUTH_AUTHORIZE_URL="https://github.com/login/oauth/authorize",
        GITHUB_AUTH_TOKEN_URL="https://github.com/login/oauth/access_token",
        GITHUB_AUTH_CLIENT_ID="client_id_0123456789",
        GITHUB_AUTH_CLIENT_SECRET="client_secret_abcdefghijklmnupqrstuvwxyz",
        GITHUB_AUTH_REDIRECT_URI="http://localhost:8080/signin",
    )
    with y.app_context():
        define_tables()
    yield y
Exemplo n.º 8
0
def test_template(number, data):
    app = create_app(
        SQLALCHEMY_DATABASE_URI="sqlite:///:memory:",
        ACONDBS_GRAPHIQL=True,
        ACONDBS_GRAPHIQL_TEMPLATE_NO=number,
    )
    with app.app_context():
        define_tables()

    client = app.test_client()

    response = client.get("/graphql", headers={"Accept": "text/html"})
    assert 200 == response.status_code
    assert data in response.data.decode("utf-8")
Exemplo n.º 9
0
def test_add_owners_to_db_as_admins(kwargs, expected, tmpdir_factory):
    config_path = Path(SAMPLE_DIR, "config.py")

    # use a file because, with memory, a DB will be recreated in the
    # second create_app().
    tmpdir = str(tmpdir_factory.mktemp("models"))
    tmp_database_path = Path(tmpdir, "product.sqlite3")
    kwargs.update(
        dict(SQLALCHEMY_DATABASE_URI=f"sqlite:///{tmp_database_path}"))

    # define tables and add a admin
    app_ = create_app(config_path, **kwargs)
    with app_.app_context():
        define_tables()

        octocat = AccountAdmin(git_hub_login="******")
        sa.session.add(octocat)
        sa.session.commit()

    app = create_app(config_path, **kwargs)
    with app.app_context():
        assert expected == {e.git_hub_login for e in AccountAdmin.query.all()}
Exemplo n.º 10
0
def test_define_tables_start_with_empty_db(app_with_empty_db, snapshot):
    """test define_tables()

    This function tests if tables will be defined starting from new db without
    any tables.

    """

    app = app_with_empty_db

    # confirm tables are not defined initially
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        assert not metadata.tables

    with app.app_context():
        define_tables()

    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        snapshot.assert_match(metadata.tables)
Exemplo n.º 11
0
def test_define_tables_start_with_nonempty_db(app):
    """test define_tables()

    This function tests if tables will be redefined starting from db
    with tables with entries.

    """

    # confirm tables are defined initially and not empty
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        assert metadata.tables
        total_nentries = sum([
            len([r for r in sa.engine.execute(tbl.select())])
            for tbl in metadata.sorted_tables
        ])
        assert total_nentries > 0

    with app.app_context():
        define_tables()

    # confirm tables are defined and all empty
    with app.app_context():
        metadata = MetaData()
        metadata.reflect(bind=sa.engine)
        tbl_names = {
            'simulations', 'simulation_file_paths', 'maps', 'map_file_paths',
            'beams', 'beam_file_paths'
        }
        assert tbl_names == metadata.tables.keys()
        total_nentries = sum([
            len([r for r in sa.engine.execute(tbl.select())])
            for tbl in metadata.sorted_tables
        ])
        assert total_nentries == 0
Exemplo n.º 12
0
def app_empty():
    database_uri = "sqlite:///:memory:"
    y = create_app(SQLALCHEMY_DATABASE_URI=database_uri)
    with y.app_context():
        define_tables()
    yield y