How to use the etlhelper.execute function in etlhelper

To help you get started, we’ve selected a few etlhelper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BritishGeologicalSurvey / etlhelper / test / integration / etl / test_etl_extract.py View on Github external
def test_execute_with_params(pgtestdb_test_tables, pgtestdb_conn,
                             test_table_data):
    # Arrange
    sql = "DELETE FROM src WHERE id = %s;"
    params = [1]
    expected = test_table_data[1:]

    # Act
    execute(sql, pgtestdb_conn, parameters=params)

    # Assert
    result = get_rows('SELECT * FROM src;', pgtestdb_conn)
    assert result == expected
github BritishGeologicalSurvey / etlhelper / test / integration / db / test_sqlite.py View on Github external
def test_bad_select(testdb_conn):
    select_sql = "SELECT * FROM bad_table"
    with pytest.raises(ETLHelperQueryError):
        execute(select_sql, testdb_conn)
github BritishGeologicalSurvey / etlhelper / test / integration / db / test_sqlite.py View on Github external
def test_bad_constraint(test_tables, testdb_conn):
    # src already has a row with id=1
    insert_sql = "INSERT INTO src (id) VALUES (1)"
    with pytest.raises(ETLHelperQueryError):
        execute(insert_sql, testdb_conn)
github BritishGeologicalSurvey / etlhelper / test / integration / etl / test_etl_extract.py View on Github external
def test_execute_bad_query(pgtestdb_test_tables, pgtestdb_conn):
    sql = "DELETE * FROM this_does_not_exist"
    with pytest.raises(ETLHelperQueryError):
        execute(sql, pgtestdb_conn)
github BritishGeologicalSurvey / etlhelper / test / integration / etl / test_etl_extract.py View on Github external
def test_execute_happy_path(pgtestdb_test_tables, pgtestdb_conn):
    # Arrange
    sql = "DELETE FROM src;"

    # Act
    execute(sql, pgtestdb_conn)

    # Assert
    result = get_rows('SELECT * FROM src;', pgtestdb_conn)
    assert result == []
github BritishGeologicalSurvey / etlhelper / test / integration / etl / test_etl_logging.py View on Github external
def test_logging_execute(caplog, level, expected, pgtestdb_conn):
    # Arrange
    caplog.set_level(level, logger=logger.name)
    select_sql = "SELECT 1 AS result;"

    # Act
    execute(select_sql, pgtestdb_conn)
    # ID for connection object and hostname vary between tests
    # and test environments
    messages = [re.sub(r'object at .*;', 'object at ???;', m)
                for m in caplog.messages]
    messages = [re.sub(r'host=.*? ', 'host=??? ', m)
                for m in messages]

    # Assert
    for i, message in enumerate(messages):
        assert message == expected[i]
github BritishGeologicalSurvey / etlhelper / test / integration / db / test_sqlite.py View on Github external
def test_bad_insert(testdb_conn):
    insert_sql = "INSERT INTO bad_table (id) VALUES (1)"
    with pytest.raises(ETLHelperQueryError):
        execute(insert_sql, testdb_conn)