def test_poll_cdcs_valid_start_end_scn(mocker, setup):
    (extractor, mockdb, mockargv, mock_producer, start_scn, end_scn) = setup
    unittest_utils.mock_get_schemas_and_tables(mocker, [], [])
    extractor.poll_cdcs(start_scn, end_scn)
    mockdb.assert_has_calls([
        mocker.call.execute(const.ALTER_NLS_DATE_FORMAT_COMMAND),
        mocker.call.execute(const.ALTER_NLS_TIMESTAMP_FORMAT_COMMAND),
        mocker.call.execute_stored_proc(
            EXPECT_START_LOGMNR_CMD.format(
                start_scn, end_scn,
                build_logminer_options(BASE_LOGMNR_OPTIONS + ONLINE_DICT))),
        mocker.call.execute_query(mocker.ANY, 1000),
        mocker.call.execute_stored_proc(STOP_LOGMINER_COMMAND)
    ])
def test_no_redolog_dict(mocker, setup_no_redolog_dict):
    (extractor, mockdb, mockargv, mock_producer, start_scn,
     end_scn) = setup_no_redolog_dict

    unittest_utils.mock_get_schemas_and_tables(mocker, [], [])
    extractor.poll_cdcs(start_scn, end_scn)
    mockdb.assert_has_calls([
        mocker.call.execute(const.ALTER_NLS_DATE_FORMAT_COMMAND),
        mocker.call.execute(const.ALTER_NLS_TIMESTAMP_FORMAT_COMMAND),
        mocker.call.execute_query(GET_DICTIONARY_QUERY.format(scn=start_scn),
                                  1000),
        # If no redolog is found, then should go into online dict mode
        mocker.call.execute_stored_proc(
            EXPECT_START_LOGMNR_CMD.format(
                start_scn, end_scn,
                build_logminer_options(BASE_LOGMNR_OPTIONS + ONLINE_DICT))),
        mocker.call.execute_query(mocker.ANY, 1000),
        mocker.call.execute_stored_proc(STOP_LOGMINER_COMMAND)
    ])
def test_redolog_dict(mocker, setup_redolog_dict):
    (extractor, mockdb, mockargv, mock_producer, start_scn,
     end_scn) = setup_redolog_dict

    unittest_utils.mock_get_schemas_and_tables(mocker, [], [])
    extractor.poll_cdcs(start_scn, end_scn)
    mockdb.assert_has_calls([
        mocker.call.execute(const.ALTER_NLS_DATE_FORMAT_COMMAND),
        mocker.call.execute(const.ALTER_NLS_TIMESTAMP_FORMAT_COMMAND),
        mocker.call.execute_query(GET_DICTIONARY_QUERY.format(scn=start_scn),
                                  1000),
        mocker.call.execute_stored_proc(
            "DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => 'my_redolog_name', OPTIONS => DBMS_LOGMNR.NEW)"
        ),
        mocker.call.execute_stored_proc(
            EXPECT_START_LOGMNR_CMD.format(
                start_scn, end_scn,
                build_logminer_options(BASE_LOGMNR_OPTIONS + REDOLOG_DICT))),
        mocker.call.execute_query(mocker.ANY, 1000),
        mocker.call.execute_stored_proc(STOP_LOGMINER_COMMAND)
    ])
def test_poll_cdcs_start_gt_end_scn(mocker, setup):
    (extractor, mockdb, mockargv, mock_producer, start_scn, end_scn) = setup
    unittest_utils.mock_get_schemas_and_tables(mocker, [], [])
    with pytest.raises(InvalidArgumentsError):
        extractor.poll_cdcs(2, 1)