def test_or_operator() -> None: field1 = "f" value1 = "1" operator1 = "=" filter1 = FilterOperator(field1, operator1, value1) field2 = "f" value2 = "2" operator2 = "<" filter2 = FilterOperator(field2, operator2, value2) or_ = Or(filter1, filter2) assert or_.to_dict() == {"or_filter": [filter1.to_dict(), filter2.to_dict()]}
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_complex_filter() -> None: collection = Collection("a") filter1 = FilterOperator(field="f", value="1", operator="=") filter2 = FilterOperator(field="f", value="3", operator="=") or_filter = Or([filter1, filter2]) found = db.filter(collection=collection, filter=or_filter) assert found is not None assert len(found) > 0
def test_complex_filter() -> None: collection = Collection("a") filter1 = FilterOperator(field="f", value="1", operator="=") filter2 = FilterOperator(field="f", value="3", operator="=") or_filter = Or([filter1, filter2]) command = commands.Filters(collection=collection, filter=or_filter) engine.filter.return_value = [ {"f": 1, "meta_deleted": False, "meta_position": 1}, {"f": 3, "meta_deleted": False, "meta_position": 4}, {"f": 1, "meta_deleted": False, "meta_position": 6}, {"f": 1, "meta_deleted": False, "meta_position": 7}, ] found = db.filter(collection=collection, filter=or_filter) assert found is not None assert command.data == { "collection": str(collection), "filter": or_filter.to_dict(), } engine.filter.called_with(command)
def test_complex_filter(self) -> None: collection = Collection("a") filter1 = FilterOperator("f", "=", "1") filter2 = FilterOperator("f", "=", "3") or_filter = Or(filter1, filter2) command = commands.Filter(collection=collection, filter=or_filter) self.engine.retrieve.return_value = ( json.dumps({ "position": 1, "data": { "1": { "f": 1, "meta_deleted": False, "meta_position": 1 }, "4": { "f": 3, "meta_deleted": False, "meta_position": 4 }, "6": { "f": 1, "meta_deleted": False, "meta_position": 6 }, "7": { "f": 1, "meta_deleted": False, "meta_position": 7 }, }, }), 200, ) found = self.db.filter(collection=collection, filter=or_filter, lock_result=False) assert found is not None assert command.get_raw_data() == { "collection": str(collection), "filter": or_filter.to_dict(), } self.engine.retrieve.called_with("filter", command.data)
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))))}' )
def test_complex_filter(self) -> None: collection = Collection("a") filter1 = FilterOperator(field="f", value="1", operator="=") filter2 = FilterOperator(field="f", value="3", operator="=") or_filter = Or([filter1, filter2]) command = commands.Filter(collection=collection, filter=or_filter) self.engine.retrieve.return_value = ( json.dumps([ { "f": 1, "meta_deleted": False, "meta_position": 1 }, { "f": 3, "meta_deleted": False, "meta_position": 4 }, { "f": 1, "meta_deleted": False, "meta_position": 6 }, { "f": 1, "meta_deleted": False, "meta_position": 7 }, ]), 200, ) found = self.db.filter(collection=collection, filter=or_filter) assert found is not None assert command.get_raw_data() == { "collection": str(collection), "filter": or_filter.to_dict(), } self.engine.retrieve.called_with("filter", command.data)
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()]}
def test_or_operator() -> None: filter1 = FilterOperator("f", "=", 1) filter2 = FilterOperator("f", "<", 2) or_ = Or(filter1, filter2) assert or_.to_dict() == {"or_filter": [filter1.to_dict(), filter2.to_dict()]}