From 587c6292180a66e709983e38ccfa56fa00318b77 Mon Sep 17 00:00:00 2001 From: Benjamin Ramser Date: Sat, 22 Jun 2024 13:28:24 +0200 Subject: [PATCH] feat: add WHEREIN to NEARBY --- pyle38/commands/nearby.py | 2 ++ tests/test_command_nearby.py | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/pyle38/commands/nearby.py b/pyle38/commands/nearby.py index 327b450..55611ce 100644 --- a/pyle38/commands/nearby.py +++ b/pyle38/commands/nearby.py @@ -56,6 +56,7 @@ def __init__(self, client: Client, key: str, hook=None) -> None: self._options = {} self._hook = hook self._where = [] + self._wherein = [] def key(self, key: str) -> Nearby: """Set key to search in @@ -372,6 +373,7 @@ def compile(self) -> Compiled: self._key, *(self.__compile_options()), *(self.compile_where()), + *(self.compile_wherein()), *(self.__compile_fence()), *(self._output if self._output else []), *(self._query.get()), diff --git a/tests/test_command_nearby.py b/tests/test_command_nearby.py index af379a5..dc3b1c1 100644 --- a/tests/test_command_nearby.py +++ b/tests/test_command_nearby.py @@ -43,6 +43,14 @@ "bar", 1, 1, + "WHEREIN", + "foo", + 1, + 1, + "WHEREIN", + "bar", + 1, + 1, "FENCE", "DETECT", "enter,exit", @@ -70,6 +78,8 @@ async def test_command_nearby_compile(tile38, format, precision, expected): .limit(10) .where("foo", 1, 1) .where("bar", 1, 1) + .wherein("foo", 1, [1]) + .wherein("bar", 1, [1]) .fence() .detect(["enter", "exit"]) .commands(["del", "set"]) @@ -127,6 +137,42 @@ async def test_command_nearby_where_point(tile38): assert len(response.objects) == 2 +@pytest.mark.asyncio +async def test_command_nearby_wherein_point(tile38): + await ( + tile38.set(key, id) + .fields({"maxspeed": 120, "maxweight": 1000}) + .object(feature) + .exec() + ) + await ( + tile38.set(key, "truck1") + .fields({"maxspeed": 100, "maxweight": 1000}) + .object(feature) + .exec() + ) + + response = ( + await tile38.nearby(key) + .wherein("maxspeed", 1, [120]) + .point(52.250212, 13.370871) + .asObjects() + ) + assert response.ok + assert len(response.objects) == 1 + assert response.objects[0].dict() == dict(expected, **{"fields": [120, 1000]}) + + response = ( + await tile38.nearby(key) + .wherein("maxspeed", 2, [100, 120]) + .wherein("maxweight", 1, [1000]) + .point(52.250212, 13.370871) + .asObjects() + ) + assert response.ok + assert len(response.objects) == 2 + + @pytest.mark.asyncio async def test_command_nearby_point_with_radius(tile38): response = await tile38.set(key, id).object(feature).exec()