import pytest
from data_pipeline.sql.statement.where_statement import WhereStatement
from data_pipeline.processor.oracle_where_parser import OracleWhereParser

@pytest.mark.parametrize("commit_statement, primary_key_fields, where_beg_i, expected_conditions", [
    ("""where "AUTOGENERATED" = '0'""",["AUTOGENERATED"], 0, " WHERE AUTOGENERATED = '0'"),
    ("""update "CCUSER"."CC_ACTIVITY" set "FIELD0" = '3' where "AUTOGENERATED" = '0'""", ["AUTOGENERATED"], 49, " WHERE AUTOGENERATED = '0'"),
    ("""update "CCUSER"."CC_ACTIVITY" set "FIELD0" = '3 where ' where "AUTOGENERATED" = '0'""", ["AUTOGENERATED"], 56, " WHERE AUTOGENERATED = '0'"),
    ("""update "CCUSER"."CC_ACTIVITY" set "FIELD0" = '3 where ' where "AUTOGENERATED" = '0' and "FIELD0" = 'something where '""", ["AUTOGENERATED", "FIELD0"], 56, " WHERE AUTOGENERATED = '0' AND FIELD0 = 'something where '"),
    ("""update "CCUSER"."CC_ACTIVITY" set "FIELD0" = '3 '' where "' where "AUTOGENERATED" = '0' and "FIELD0" = 'something where '""", ["AUTOGENERATED"], 60, " WHERE AUTOGENERATED = '0'"),
    ])
def test_where_parse(commit_statement, primary_key_fields, where_beg_i, expected_conditions):
    where_statement = WhereStatement("CCUSER", None, primary_key_fields)
    parser = OracleWhereParser()
    parser.set_commit_statement(commit_statement)
    parser.set_read_cursor(where_beg_i)
    parser.set_statement(where_statement)
    parser.set_primary_keys(primary_key_fields)
    parser.parse()
    assert str(where_statement) == expected_conditions


