def test_simple_filter(self) -> None: collection = Collection("a") field = "f" value = "1" operator = "=" filter = FilterOperator(field, operator, value) command = commands.Filter(collection=collection, filter=filter) self.engine.retrieve.return_value = ( json.dumps( { "1": {"f": 1, "meta_deleted": False, "meta_position": 1}, "5": {"f": 1, "meta_deleted": False, "meta_position": 5}, "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=filter) assert found is not None assert command.get_raw_data() == { "collection": str(collection), "filter": {"field": field, "operator": operator, "value": value}, } self.engine.retrieve.called_with("filter", command.data)
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_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)