Exemple #1
0
def test_build_filter_query_invalid_fields_params(
        query_helper: SqlQueryHelper):
    query_helper.build_filter_str = MagicMock(return_value=MagicMock())
    filter = MagicMock()
    param = "invalid"

    with pytest.raises(BadCodingError):
        query_helper.build_filter_query(MagicMock(), filter, param)
Exemple #2
0
def test_build_filter_query_invalid_cast_target(query_helper: SqlQueryHelper):
    query_helper.build_filter_str = bfs = MagicMock(return_value=MagicMock())
    filter = MagicMock()
    param = AggregateFilterQueryFieldsParameters("min", "field", "invalid")

    with pytest.raises(BadCodingError):
        query_helper.build_filter_query(MagicMock(), filter, param)

    assert bfs.call_args[0] == (filter, [])
Exemple #3
0
def test_build_filter_query_count(query_helper: SqlQueryHelper):
    query_helper.build_filter_str = bfs = MagicMock(return_value=MagicMock())
    filter = MagicMock()
    param = CountFilterQueryFieldsParameters()

    q, a, s = query_helper.build_filter_query(MagicMock(), filter, param)

    assert bfs.call_args[0] == (filter, [])
    assert s == []
Exemple #4
0
def test_build_filter_query_aggregate(query_helper: SqlQueryHelper):
    query_helper.build_filter_str = bfs = MagicMock(return_value=MagicMock())
    filter = MagicMock()
    field = MagicMock()
    param = AggregateFilterQueryFieldsParameters("min", field, "int")

    q, a, s = query_helper.build_filter_query(MagicMock(), filter, param)

    assert bfs.call_args[0] == (filter, [])
    assert a[0] == field
    assert s == []
Exemple #5
0
def test_build_filter_query_mapped_fields(query_helper: SqlQueryHelper):
    query_helper.build_filter_str = bfs = MagicMock(return_value=MagicMock())
    filter = MagicMock()
    field = MagicMock()
    param = MappedFieldsFilterQueryFieldsParameters([field])

    q, a, s = query_helper.build_filter_query(MagicMock(), filter, param)

    assert bfs.call_args[0] == (filter, [])
    assert a[0] == field
    assert s == [field]
Exemple #6
0
def test_build_models_from_result(read_database: ReadDatabase,
                                  query_helper: SqlQueryHelper):
    row = MagicMock()
    row["fqid"] = MagicMock()
    row.copy = lambda: row
    row.keys = MagicMock(return_value=[MagicMock()])
    mfpc = MagicMock()
    mfpc.__getitem__ = MagicMock(return_value=[MagicMock()])
    mfpc.__contains__ = MagicMock(return_value=True)

    query_helper.mapped_fields_map_has_empty_entry = MagicMock(
        return_value=False)

    result = read_database.build_models_from_result([row], mfpc)

    assert result == {row["fqid"]: row}
Exemple #7
0
def test_build_filter_str_not(query_helper: SqlQueryHelper):
    f = query_helper.build_filter_str
    query_helper.build_filter_str = MagicMock(return_value="")
    filter = Not(MagicMock())

    assert f(filter, []) == "NOT ()"
Exemple #8
0
def test_get_unique_mapped_fields(query_helper: SqlQueryHelper):
    assert query_helper.get_unique_mapped_fields({"c": ["field"]}) == ["field"]
Exemple #9
0
def test_build_filter_str_filter_operator(query_helper: SqlQueryHelper):
    f = query_helper.build_filter_str
    query_helper.build_filter_str = MagicMock(return_value="")
    filter = FilterOperator("f", "=", 0)

    assert f(filter, [], "a") == "a.data->>%s = %s::text"
Exemple #10
0
def test_build_filter_str_none_invalid(query_helper: SqlQueryHelper):
    filter = FilterOperator("field", ">", None)
    with pytest.raises(InvalidFormat):
        query_helper.build_filter_str(filter, [])
Exemple #11
0
def test_build_filter_str_none(query_helper: SqlQueryHelper):
    filter = FilterOperator("field", "!=", None)
    args = []
    assert query_helper.build_filter_str(filter,
                                         args) == "data->>%s IS NOT NULL"
    assert args == ["field"]
Exemple #12
0
def test_build_filter_str_invalid(query_helper: SqlQueryHelper):
    with pytest.raises(BadCodingError):
        query_helper.build_filter_str("invalid", [])
Exemple #13
0
def test_build_filter_str_and(query_helper: SqlQueryHelper):
    f = query_helper.build_filter_str
    query_helper.build_filter_str = MagicMock(return_value="")
    filter = And([MagicMock(), MagicMock()])

    assert f(filter, []) == "() AND ()"