def test_copy_table_rows_on_error(test_tables, testdb_conn, test_table_data): # Arrange duplicate_id_row_sql = """ INSERT INTO dest (id) VALUES ( 1 )""".strip() execute(duplicate_id_row_sql, testdb_conn) # Act errors = [] copy_table_rows('src', testdb_conn, testdb_conn, target='dest', on_error=errors.extend) # Assert sql = "SELECT * FROM dest" result = get_rows(sql, testdb_conn) # Check that first row was caught as error row, exception = errors[0] assert row.id == 1 assert "unique" in str(exception).lower() # Check that other rows were inserted correctly assert result[1:] == test_table_data[1:]
def test_copy_table_rows_happy_path(test_tables, testdb_conn, test_table_data): # Arrange and act copy_table_rows('src', testdb_conn, testdb_conn, target='dest') # Assert sql = "SELECT * FROM dest" result = get_rows(sql, testdb_conn) assert result == test_table_data
def test_copy_table_rows_happy_path_fast_true(test_tables, testdb_conn, testdb_conn2, test_table_data): # Note: ODBC driver requires separate connections for source and destination, # even if they are the same database. # Arrange and act copy_table_rows('src', testdb_conn, testdb_conn2, target='dest') # Assert sql = "SELECT * FROM dest" result = get_rows(sql, testdb_conn) assert result == test_table_data
def test_copy_table_rows_happy_path(test_tables, testdb_conn, test_table_data): # Arrange and act copy_table_rows('src', testdb_conn, testdb_conn, target='dest') # Assert sql = "SELECT * FROM dest" result = get_rows(sql, testdb_conn) # Fix result date and datetime strings to native classes fixed_dates = [] for row in result: fixed_dates.append((*row[:4], row.DAY.date(), row.DATE_TIME)) assert fixed_dates == test_table_data
def test_copy_table_rows_on_error(test_tables, testdb_conn, test_table_data): # Arrange duplicate_id_row_sql = """ INSERT INTO dest (id, day, date_time) VALUES ( 1, TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss') )""".strip() execute(duplicate_id_row_sql, testdb_conn) # Act errors = [] copy_table_rows('src', testdb_conn, testdb_conn, target='dest', on_error=errors.extend) # Assert sql = "SELECT * FROM dest" result = get_rows(sql, testdb_conn) # Fix result date and datetime strings to native classes fixed_dates = [] for row in result: fixed_dates.append((*row[:4], row.DAY.date(), row.DATE_TIME)) # Check that first row was caught as error, noting that Oracle # changes the case of column names row, exception = errors[0] assert row.ID == 1 assert "unique" in str(exception).lower() # Check that other rows were inserted correctly assert fixed_dates[1:] == test_table_data[1:]