Skip to content

Commit

Permalink
feat: add WHEREIN to NEARBY
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Jun 22, 2024
1 parent 41e81dd commit 587c629
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyle38/commands/nearby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()),
Expand Down
46 changes: 46 additions & 0 deletions tests/test_command_nearby.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
"bar",
1,
1,
"WHEREIN",
"foo",
1,
1,
"WHEREIN",
"bar",
1,
1,
"FENCE",
"DETECT",
"enter,exit",
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 587c629

Please sign in to comment.