Skip to content

Commit

Permalink
Add missing commands (#22)
Browse files Browse the repository at this point in the history
* add smismember implementation and test

* add georadius_ro test

* rm geo return type alias

* georadiusbymember and georadiusbymember_ro tests

* add geosearch tests

* add geosearchstore tests

* add placeholder for acl functions

* add script refactoring and tests

* remove pubsub from commands

* bump version

* run black formatter
  • Loading branch information
burak-upstash authored Jul 3, 2023
1 parent ebd3ca4 commit a3aed79
Show file tree
Hide file tree
Showing 136 changed files with 2,199 additions and 1,461 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "upstash_redis"
version = "0.13.3"
version = "0.14.0"
description = "Serverless Redis Sdk from Upstash"
authors = ["Upstash <[email protected]>", "Zgîmbău Tudor <[email protected]>"]
readme = "README.md"
Expand Down
3 changes: 1 addition & 2 deletions tests/async_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from upstash_redis.asyncio import Redis
redis = Redis.from_env(allow_telemetry=False)


redis = Redis.from_env(allow_telemetry=False)
6 changes: 5 additions & 1 deletion tests/commands/asyncio/generic/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ async def test_without_formatting() -> None:

redis.format_return = True


@mark.asyncio
async def test_with_formatting() -> None:
redis.format_return = True

async with redis:
assert await redis.copy(source="string", destination="copy_destination_2") == False
await redis.copy(source="string", destination="copy_destination_2")
assert (
await redis.copy(source="string", destination="copy_destination_2") == False
)
1 change: 1 addition & 0 deletions tests/commands/asyncio/generic/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async def test_with_scan_type() -> None:
async with redis:
assert (await redis.scan(cursor=0, scan_type="hash"))[1] == ["hash"]


@mark.asyncio
async def test_without_formatting() -> None:
redis.format_return = False
Expand Down
121 changes: 121 additions & 0 deletions tests/commands/asyncio/geo/test_georadius_ro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from pytest import mark, raises
from tests.async_client import redis


@mark.asyncio
async def test() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index", longitude=15, latitude=37, radius=200, unit="KM"
) == ["Palermo", "Catania"]


@mark.asyncio
async def test_with_distance() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
withdist=True,
) == [
{"member": "Palermo", "distance": 190.4424},
{"member": "Catania", "distance": 56.4413},
]


@mark.asyncio
async def test_with_hash() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
withhash=True,
) == [
{"member": "Palermo", "hash": 3479099956230698},
{"member": "Catania", "hash": 3479447370796909},
]


@mark.asyncio
async def test_with_coordinates() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
withcoord=True,
) == [
{
"member": "Palermo",
"longitude": 13.361389338970184,
"latitude": 38.115556395496299,
},
{
"member": "Catania",
"longitude": 15.087267458438873,
"latitude": 37.50266842333162,
},
]


@mark.asyncio
async def test_with_count() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index", longitude=15, latitude=37, radius=200, unit="KM", count=1
) == ["Catania"]


@mark.asyncio
async def test_with_any() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
count=1,
count_any=True,
) == ["Palermo"]


@mark.asyncio
async def test_with_sort() -> None:
async with redis:
assert await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
sort="ASC",
) == ["Catania", "Palermo"]


@mark.asyncio
async def test_with_invalid_parameters() -> None:
async with redis:
with raises(Exception) as exception:
await redis.georadius_ro(
"test_geo_index",
longitude=15,
latitude=37,
radius=200,
unit="KM",
count=None,
count_any=True,
)

assert (
str(exception.value)
== '"count_any" can only be used together with "count".'
)
147 changes: 147 additions & 0 deletions tests/commands/asyncio/geo/test_georadiusbymember.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
from pytest import mark, raises
from tests.async_client import redis


@mark.asyncio
async def test() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index", "Catania", 200, "KM"
) == ["Palermo", "Catania"]


@mark.asyncio
async def test_with_distance() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
withdist=True,
) == [
{"member": "Palermo", "distance": 166.2742},
{"member": "Catania", "distance": 0.0},
]


@mark.asyncio
async def test_with_hash() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
withhash=True,
) == [
{"member": "Palermo", "hash": 3479099956230698},
{"member": "Catania", "hash": 3479447370796909},
]


@mark.asyncio
async def test_with_coordinates() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
withcoord=True,
) == [
{
"member": "Palermo",
"longitude": 13.3613893389701841,
"latitude": 38.115556395496299,
},
{
"member": "Catania",
"longitude": 15.087267458438873,
"latitude": 37.50266842333162,
},
]


@mark.asyncio
async def test_with_count() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index", "Catania", 200, unit="KM", count=1
) == ["Catania"]


@mark.asyncio
async def test_with_any() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
count=1,
count_any=True,
) == ["Palermo"]


@mark.asyncio
async def test_with_sort() -> None:
async with redis:
assert await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
sort="ASC",
) == ["Catania", "Palermo"]


@mark.asyncio
async def test_with_store() -> None:
async with redis:
assert (
await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
store="test_geo_store",
)
== 2
)
assert await redis.zcard("test_geo_store") == 2


@mark.asyncio
async def test_with_store_dist() -> None:
async with redis:
assert (
await redis.georadiusbymember(
"test_geo_index",
"Catania",
100,
unit="KM",
storedist="test_geo_store_dist",
)
== 1
)
assert await redis.zcard("test_geo_store_dist") == 1


@mark.asyncio
async def test_with_invalid_parameters() -> None:
async with redis:
with raises(Exception) as exception:
await redis.georadiusbymember(
"test_geo_index",
"Catania",
200,
unit="KM",
count=None,
count_any=True,
)

assert (
str(exception.value)
== '"count_any" can only be used together with "count".'
)
Loading

0 comments on commit a3aed79

Please sign in to comment.