Ejemplo n.º 1
0
def test_not_in():
    c = SQLConverter()

    assert c._not_in("id", ["1"]) == "id NOT IN ('1')"
    assert c._not_in("id", ["1", "2"]) == "id NOT IN ('1','2')"

    assert c._not_in("id", [1, 2]) == "id NOT IN (1,2)"
Ejemplo n.º 2
0
def test_eq():
    c = SQLConverter()

    assert c._eq("id", "1") == "id = '1'"
    assert c._eq("id", 1) == "id = 1"

    assert c._eq("id", ["1", 1]) == "(id = '1' OR id = 1)"
Ejemplo n.º 3
0
def test_not_eq():
    c = SQLConverter()

    assert c._not_eq("id", "1") == "id != '1'"
    assert c._not_eq("id", 1) == "id != 1"

    assert c._not_eq("id", ["1", 1]) == "(id != '1' AND id != 1)"
Ejemplo n.º 4
0
def test_gte():
    c = SQLConverter()

    assert c._gte("id", "1") == "id >= '1'"
    assert c._gte("id", 1) == "id >= 1"

    assert c._gte("id", ["1", 1]) == "(id >= '1' OR id >= 1)"
Ejemplo n.º 5
0
def test_gt():
    c = SQLConverter()

    assert c._gt("id", "1") == "id > '1'"
    assert c._gt("id", 1) == "id > 1"

    assert c._gt("id", ["1", 1]) == "(id > '1' OR id > 1)"
Ejemplo n.º 6
0
def test_lt():
    c = SQLConverter()

    assert c._lt("id", "1") == "id < '1'"
    assert c._lt("id", 1) == "id < 1"

    assert c._lt("id", ["1", 1]) == "(id < '1' OR id < 1)"
Ejemplo n.º 7
0
def test_ends_with():
    c = SQLConverter()

    assert c._ends_with("id", "test") == "id LIKE '%test'"
    assert c._ends_with(
        "id", ["test", "test1"]) == "(id LIKE '%test' OR id LIKE '%test1')"
    assert c._ends_with("id",
                        ["test", 123]) == "(id LIKE '%test' OR id LIKE '%123')"
Ejemplo n.º 8
0
def test_starts_with():
    c = SQLConverter()

    assert c._starts_with("id", "test") == "id LIKE 'test%'"
    assert c._starts_with(
        "id", ["test", "test1"]) == "(id LIKE 'test%' OR id LIKE 'test1%')"
    assert c._starts_with(
        "id", ["test", 123]) == "(id LIKE 'test%' OR id LIKE '123%')"
Ejemplo n.º 9
0
def test_or():
    c = SQLConverter()

    content = [
        {
            "op": "eq",
            "field": "id",
            "value": "1",
        },
        {
            "op": "eq",
            "field": "name",
            "value": "test",
        },
    ]
    assert c._or(content) == "(id = '1' OR name = 'test')"
Ejemplo n.º 10
0
def test_convert():
    c = SQLConverter()

    data = {
        "op":
        "AND",
        "content": [
            {
                "op": "eq",
                "field": "id",
                "value": "1",
            },
            {
                "op": "eq",
                "field": "name",
                "value": "test",
            },
        ],
    }
    assert c.convert(data) == "(id = '1' AND name = 'test')"

    data = {
        "op":
        "OR",
        "content": [
            {
                "op": "eq",
                "field": "id",
                "value": "1",
            },
            {
                "op": "eq",
                "field": "name",
                "value": "test",
            },
        ],
    }
    assert c.convert(data) == "(id = '1' OR name = 'test')"
Ejemplo n.º 11
0
def test_not_contains():
    c = SQLConverter()

    with pytest.raises(NotImplementedError):
        c._not_contains("1", "1")
Ejemplo n.º 12
0
def test_to_str_present():
    c = SQLConverter()

    assert c._to_str_present(1, True) == 1
    assert c._to_str_present("1", True) == "'1'"
    assert c._to_str_present("1", False) == "1"
Ejemplo n.º 13
0
def test_any():
    c = SQLConverter()

    assert c._any(1, 1) == "1 = 1"