Ejemplo n.º 1
0
def db(local_config):
    db = PostgresDb.from_config(local_config, application_name='test-run', validate_db=False)
    # Drop and recreate tables so our tests have a clean db.
    drop_db(db._connection)
    remove_dynamic_indexes()
    ensure_db(db._engine)
    return db
Ejemplo n.º 2
0
def db(local_config, request):
    timezone = request.param

    db = PostgresDb.from_config(local_config,
                                application_name='test-run',
                                validate_connection=False)

    # Drop and recreate tables so our tests have a clean db.
    with db.connect() as connection:
        _core.drop_db(connection._connection)
    remove_dynamic_indexes()

    # Disable informational messages since we're doing this on every test run.
    with _increase_logging(_core._LOG) as _:
        _core.ensure_db(db._engine)

    c = db._engine.connect()
    c.execute('alter database %s set timezone = %r' %
              (local_config.db_database, str(timezone)))
    c.close()

    # We don't need informational create/drop messages for every config change.
    _dynamic._LOG.setLevel(logging.WARN)

    yield db
    db.close()
Ejemplo n.º 3
0
def db(local_config):
    db = PostgresDb.from_config(local_config,
                                application_name='test-run',
                                validate_db=False)
    # Drop and recreate tables so our tests have a clean db.
    drop_db(db._connection)
    remove_dynamic_indexes()
    ensure_db(db._engine)
    return db
Ejemplo n.º 4
0
def test_db_init(global_integration_cli_args, db, local_config):
    drop_db(db._connection)

    assert not has_schema(db._engine, db._connection)

    # Run on an empty database.
    opts = list(global_integration_cli_args)
    opts.extend(['-v', 'system', 'init'])
    cli_method = datacube.scripts.cli_app.cli
    result = _run_cli(cli_method, opts)
    assert result.exit_code == 0
    assert 'Created.' in result.output

    assert has_schema(db._engine, db._connection)
Ejemplo n.º 5
0
def test_db_init(global_integration_cli_args, db, local_config):
    with db.connect() as connection:
        drop_db(connection._connection)

        assert not has_schema(db._engine, connection._connection)

    # Run on an empty database.
    cli_method = datacube.scripts.cli_app.cli
    result = _run_cli(global_integration_cli_args, cli_method,
                      ['-v', 'system', 'init'])
    assert result.exit_code == 0
    assert 'Created.' in result.output

    with db.connect() as connection:
        assert has_schema(db._engine, connection._connection)
Ejemplo n.º 6
0
def db(local_config: LocalConfig):
    db = PostgresDb.from_config(local_config, application_name='dea-test-run', validate_connection=False)

    # Drop and recreate tables so our tests have a clean db.
    with db.connect() as connection:
        _core.drop_db(connection._connection)
    remove_dynamic_indexes()

    # Disable informational messages since we're doing this on every test run.
    with _increase_logging(_core._LOG) as _:
        _core.ensure_db(db._engine)

    # We don't need informational create/drop messages for every config change.
    _dynamic._LOG.setLevel(logging.WARN)

    yield db
    db.close()
Ejemplo n.º 7
0
def test_db_init(global_integration_cli_args, db, local_config):
    drop_db(db._connection)

    assert not has_schema(db._engine, db._connection)

    # Run on an empty database.
    opts = list(global_integration_cli_args)
    opts.extend(
        [
            '-v', 'system', 'init'
        ]
    )
    cli_method = datacube.scripts.cli_app.cli
    result = _run_cli(cli_method, opts)
    assert result.exit_code == 0
    assert 'Done.' in result.output

    assert has_schema(db._engine, db._connection)