Exemplo n.º 1
0
def test_process_returns_correct_instance_type(operation_code, commit_statement, expected_type, mocker):

    oracle_message = OracleMessage()
    oracle_message.operation_code = operation_code
    oracle_message.commit_statement = commit_statement
    oracle_message.primary_key_fields = ""

    processor = processor_factory.build(const.ORACLE)
    statement = processor.process(oracle_message)

    assert type(statement).__name__ == expected_type
Exemplo n.º 2
0
def execute_statement_parsing_test(operation, data, mocker):
    print("Running test: '{}'".format(data.description))
    
    oracle_message = OracleMessage()
    oracle_message.operation_code = operation
    oracle_message.table_name = data.input_table_name
    oracle_message.commit_statement = data.input_commit_statement
    oracle_message.primary_key_fields = data.input_primary_key_fields

    processor = processor_factory.build(const.ORACLE)
    output = processor.process(oracle_message)
    return output
Exemplo n.º 3
0
def execute_batch_state_tests(applier, data, mocker, mock_target_db):
    print("Running test: '{}'".format(data.description))

    for record_type, op, statement in (zip(data.input_record_types,
                                           data.input_operation_codes,
                                           data.input_commit_statements)):

        oracle_message = OracleMessage()
        oracle_message.record_type = record_type
        oracle_message.operation_code = op
        oracle_message.table_name = data.input_table_name
        oracle_message.commit_statement = statement
        oracle_message.primary_key_fields = data.input_primary_key_fields

        config = {
            'value.return_value': oracle_message.serialise(),
            'offset.return_value': 1
        }
        mock_message = mocker.Mock(**config)
Exemplo n.º 4
0
def execute_tests(applier, data, mocker, mock_target_db, mock_audit_db):
    print("Running test: '{}'".format(data.description))

    for (record_type, op, statement, record_count, lsn,
         expect_sql_execute_called, expect_execute_called_times,
         expect_audit_db_execute_sql_called, expect_commit_called_times,
         expect_insert_row_count, expect_update_row_count,
         expect_delete_row_count, expect_source_row_count,
         expect_batch_committed) in (zip(
             data.input_record_types, data.input_operation_codes,
             data.input_commit_statements, data.input_record_counts,
             data.input_commit_lsns, data.expect_sql_execute_called,
             data.expect_execute_called_times,
             data.expect_audit_db_execute_sql_called,
             data.expect_commit_called_times, data.expect_insert_row_count,
             data.expect_update_row_count, data.expect_delete_row_count,
             data.expect_source_row_count, data.expect_batch_committed)):

        oracle_message = OracleMessage()
        oracle_message.record_type = record_type
        oracle_message.operation_code = op
        oracle_message.table_name = data.input_table_name
        oracle_message.commit_statement = statement
        oracle_message.primary_key_fields = data.input_primary_key_fields
        oracle_message.record_count = record_count
        oracle_message.commit_lsn = lsn

        config = {
            'value.return_value': oracle_message.serialise(),
            'offset.return_value': 1
        }
        mock_message = mocker.Mock(**config)

        commit_status = applier.apply(mock_message)

        print(
            "mock_target_db.execute.call_count {} == expect_execute_called_times {}?"
            .format(mock_target_db.execute.call_count,
                    expect_execute_called_times))
        assert mock_target_db.execute.call_count == expect_execute_called_times

        print(
            "mock_target_db.execute.call_count {} == expect_execute_called_times {}?"
            .format(mock_target_db.execute.call_count,
                    expect_execute_called_times))
        assert mock_target_db.execute.call_count == expect_execute_called_times

        print(
            "mock_target_db.commit.call_count {} == expect_commit_called_times {}?"
            .format(mock_target_db.commit.call_count,
                    expect_commit_called_times))
        assert mock_target_db.commit.call_count == expect_commit_called_times

        print("commit_status {} == expect_batch_committed {}?".format(
            commit_status, expect_batch_committed))
        assert commit_status == expect_batch_committed

        pcd = applier.get_pcd(data.input_table_name)
        assert pcd is not None
        print("insert={}, update={}, delete={}, source={}".format(
            pcd.insert_row_count, pcd.update_row_count, pcd.delete_row_count,
            pcd.source_row_count))

        print("pcd.insert_row_count {} == expect_insert_row_count {}?".format(
            pcd.insert_row_count, expect_insert_row_count))
        assert pcd.insert_row_count == expect_insert_row_count

        print("pcd.update_row_count {} == expect_update_row_count {}?".format(
            pcd.update_row_count, expect_update_row_count))
        assert pcd.update_row_count == expect_update_row_count

        print("pcd.delete_row_count {} == expect_delete_row_count {}?".format(
            pcd.delete_row_count, expect_delete_row_count))
        assert pcd.delete_row_count == expect_delete_row_count

        print("pcd.source_row_count {} == expect_source_row_count {}?".format(
            pcd.source_row_count, expect_source_row_count))
        assert pcd.source_row_count == expect_source_row_count

        if expect_sql_execute_called:
            mock_target_db.execute.assert_called_with(
                expect_sql_execute_called)

        if expect_audit_db_execute_sql_called:
            (sql, bind_values) = expect_audit_db_execute_sql_called
            if sql:
                print("sql = ({}, {})".format(sql, bind_values))
                mock_audit_db.execute.assert_called_with(sql, bind_values)