Exemple #1
0
def test_import_data():
    """
    unit test for import_data
    """

    file_path = os.path.join(CONST_ADVANTICSYS_DIR, CONST_ADVANTICSYS_TEST_1)

    # Bring df
    success, log, test_ingress_df = advanticsys_import(file_path)
    assert success, log
    assert isinstance(test_ingress_df, pd.DataFrame)

    # Test import function
    success, log = import_data(
        test_ingress_df,
        CONST_ADVANTICSYS,
        SQL_USER,
        SQL_PASSWORD,
        SQL_HOST,
        SQL_PORT,
        SQL_TEST_DBNAME,
    )

    assert success is True, log
    assert log == "New: 0 (uploaded); Duplicates: 75 (ignored)"
Exemple #2
0
def test_advanticsys_import():

    # One column is misppeled, the checks should pick this up and return None
    file_path = os.path.join(
        CONST_TEST_DIR_DATA, CONST_ADVANTICSYS_FOLDER, CONST_ADVANTICSYS_TEST_2
    )
    success, _, data_df = advanticsys_import(file_path)
    assert success is False
    assert data_df is None

    file_path = os.path.join(
        CONST_TEST_DIR_DATA, CONST_ADVANTICSYS_FOLDER, CONST_ADVANTICSYS_TEST_1
    )
    success, _, data_df = advanticsys_import(file_path)

    # counting the number of entries
    assert len(data_df.index) == 75
Exemple #3
0
def test_insert_advanticsys_data():
    """
    Bulk inserts test advanticsys data

    Arguments:
        engine: SQL engine object
    """

    file_path = os.path.join(CONST_ADVANTICSYS_DIR, CONST_ADVANTICSYS_TEST_1)
    success, log, test_ingress_df = advanticsys_import(file_path)
    assert success, log
    assert isinstance(test_ingress_df, pd.DataFrame)

    # Try to connect to an engine that exists
    status, log, engine = connect_db(SQL_CONNECTION_STRING, SQL_TEST_DBNAME)
    assert status, log

    # trying to import the same data twice
    session = session_open(engine)
    success, log = insert_advanticsys_data(session, test_ingress_df)
    session_close(session)

    # This should pass and reeport 75 duplicatee values
    assert success is True, log
    assert log == "New: 0 (uploaded); Duplicates: 75 (ignored)"

    file_path = os.path.join(CONST_ADVANTICSYS_DIR, CONST_ADVANTICSYS_TEST_10)
    success, log, test_ingress_df = advanticsys_import(file_path)

    assert success, log
    assert isinstance(test_ingress_df, pd.DataFrame)

    session = session_open(engine)
    success, log = insert_advanticsys_data(session, test_ingress_df)
    session_close(session)

    assert success is False, log
def insert_adv_data(engine):
    """
    Bulk inserts test advanticsys data

    Arguments:
        engine: SQL engine object
    """

    file_path = os.path.join(CONST_ADVANTICSYS_DIR, CONST_ADVANTICSYS_TEST_1)
    success, log, test_ingress_df = advanticsys_import(file_path)

    assert success, log
    assert isinstance(test_ingress_df, pd.DataFrame)

    # Creates/Opens a new connection to the db and binds the engine
    session = session_open(engine)

    # tests loading sensor data to db
    success, log = insert_advanticsys_data(session, test_ingress_df)
    session_close(session)
    assert success, log