Exemplo n.º 1
0
def test_not_operator() -> None:
    field = "f"
    value = "1"
    operator = "="
    filter = FilterOperator(field, operator, value)
    not_ = Not(filter)
    assert not_.to_dict() == {"not_filter": filter.to_dict()}
Exemplo n.º 2
0
def test_complex_operator() -> None:
    field1 = "f"
    value1 = "1"
    operator1 = "="
    filter1 = FilterOperator(field1, operator1, value1)
    field2 = "f"
    value2 = "2"
    operator2 = "<"
    filter2 = FilterOperator(field2, operator2, value2)
    not_ = Not(filter2)
    or_ = Or(filter1, not_)
    assert or_.to_dict() == {"or_filter": [filter1.to_dict(), not_.to_dict()]}
def test_sql_to_filter_code_complex() -> None:
    ds = ExtendedDatastoreAdapter(MagicMock(), MagicMock())
    operator = FilterOperator("test", "=", 1)
    _filter = Or(operator, And(operator, Not(operator)))
    with patch("openslides_backend.services.datastore.extended_adapter.eval"
               ) as mock:
        ds._filter_changed_models(MagicMock(), _filter, [])
    assert (
        mock.call_args[0][0] ==
        '{model[\'id\']: {field: model[field] for field in mapped_fields if field in model} for fqid, model in self.changed_models.items() if fqid.collection == collection and ((model.get("test") == 1) or ((model.get("test") == 1) and (not (model.get("test") == 1))))}'
    )
Exemplo n.º 4
0
def test_complex_operator() -> None:
    filter1 = FilterOperator("f", "=", 1)
    filter2 = FilterOperator("f", "<", 2)
    not_ = Not(filter2)
    or_ = Or(filter1, not_)
    assert or_.to_dict() == {"or_filter": [filter1.to_dict(), not_.to_dict()]}
Exemplo n.º 5
0
def test_not_operator() -> None:
    filter = FilterOperator("f", "=", 1)
    not_ = Not(filter)
    assert not_.to_dict() == {"not_filter": filter.to_dict()}