Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing assert in json tests #3261

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions tests/test_asyncio/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def test_jsonsetexistentialmodifiersshouldsucceed(decoded_r: redis.Redis):
assert await decoded_r.json().set("obj", Path("foo"), "baz", xx=True)
assert await decoded_r.json().set("obj", Path("qaz"), "baz", nx=True)

# Test that flags are mutually exlusive
# Test that flags are mutually exclusive
with pytest.raises(Exception):
await decoded_r.json().set("obj", Path("foo"), "baz", nx=True, xx=True)

Expand Down Expand Up @@ -483,7 +483,7 @@ async def test_json_mget_dollar(decoded_r: redis.Redis):
)

# Test mget with single path
await decoded_r.json().mget("doc1", "$..a") == [1, 3, None]
assert await decoded_r.json().mget(["doc1"], "$..a") == [[1, 3, None]]
# Test mget with multi path
res = await decoded_r.json().mget(["doc1", "doc2"], "$..a")
assert res == [[1, 3, None], [4, 6, [None]]]
Expand Down Expand Up @@ -539,15 +539,15 @@ async def test_numby_commands_dollar(decoded_r: redis.Redis):
await decoded_r.json().set(
"doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}
)
await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5
assert await decoded_r.json().numincrby("doc1", ".b[0].a", 3) == 5

# Test legacy NUMMULTBY
await decoded_r.json().set(
"doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]}
)

with pytest.deprecated_call():
await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6
assert await decoded_r.json().nummultby("doc1", ".b[0].a", 3) == 6


@pytest.mark.redismod
Expand All @@ -556,13 +556,13 @@ async def test_strappend_dollar(decoded_r: redis.Redis):
"doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}
)
# Test multi
await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
assert await decoded_r.json().strappend("doc1", "bar", "$..a") == [6, 8, None]

res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])

# Test single
await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11]
assert await decoded_r.json().strappend("doc1", "baz", "$.nested1.a") == [11]

res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])
Expand All @@ -572,7 +572,7 @@ async def test_strappend_dollar(decoded_r: redis.Redis):
await decoded_r.json().strappend("non_existing_doc", "$..a", "err")

# Test multi
await decoded_r.json().strappend("doc1", "bar", ".*.a") == 8
assert await decoded_r.json().strappend("doc1", "bar", ".*.a") == 14
res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}]
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])

Expand All @@ -594,8 +594,8 @@ async def test_strlen_dollar(decoded_r: redis.Redis):
assert res1 == res2

# Test single
await decoded_r.json().strlen("doc1", "$.nested1.a") == [8]
await decoded_r.json().strlen("doc1", "$.nested2.a") == [None]
assert await decoded_r.json().strlen("doc1", "$.nested1.a") == [8]
assert await decoded_r.json().strlen("doc1", "$.nested2.a") == [None]

# Test missing key
with pytest.raises(exceptions.ResponseError):
Expand All @@ -614,7 +614,8 @@ async def test_arrappend_dollar(decoded_r: redis.Redis):
},
)
# Test multi
await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
res = [3, 5, None]
assert await decoded_r.json().arrappend("doc1", "$..a", "bar", "racuda") == res
res = [
{
"a": ["foo", "bar", "racuda"],
Expand Down Expand Up @@ -794,7 +795,7 @@ async def test_arrpop_dollar(decoded_r: redis.Redis):
},
)
# Test multi (all paths are updated, but return result of last path)
await decoded_r.json().arrpop("doc1", "..a", "1") is None
assert await decoded_r.json().arrpop("doc1", "..a", "1") == "null"
res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}]
assert_resp_response(decoded_r, await decoded_r.json().get("doc1", "$"), res, [res])

Expand Down
43 changes: 22 additions & 21 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_jsonsetexistentialmodifiersshouldsucceed(client):
assert client.json().set("obj", Path("foo"), "baz", xx=True)
assert client.json().set("obj", Path("qaz"), "baz", nx=True)

# Test that flags are mutually exlusive
# Test that flags are mutually exclusive
with pytest.raises(Exception):
client.json().set("obj", Path("foo"), "baz", nx=True, xx=True)

Expand Down Expand Up @@ -453,6 +453,7 @@ def test_json_forget_with_dollar(client):
client.json().forget("not_a_document", "..a")


@pytest.mark.onlynoncluster
@pytest.mark.redismod
def test_json_mget_dollar(client):
# Test mget with multi paths
Expand All @@ -473,14 +474,14 @@ def test_json_mget_dollar(client):
assert_resp_response(client, client.json().get("doc2", "$..a"), res, [res])

# Test mget with single path
client.json().mget("doc1", "$..a") == [1, 3, None]
assert client.json().mget(["doc1"], "$..a") == [[1, 3, None]]
# Test mget with multi path
client.json().mget(["doc1", "doc2"], "$..a") == [[1, 3, None], [4, 6, [None]]]
res = [[1, 3, None], [4, 6, [None]]]
assert client.json().mget(["doc1", "doc2"], "$..a") == res

# Test missing key
client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None]
res = client.json().mget(["missing_doc1", "missing_doc2"], "$..a")
assert res == [None, None]
assert client.json().mget(["doc1", "missing_doc"], "$..a") == [[1, 3, None], None]
assert client.json().mget(["missing_doc1", "missing_doc2"], "$..a") == [None, None]


@pytest.mark.redismod
Expand Down Expand Up @@ -518,13 +519,13 @@ def test_numby_commands_dollar(client):

# Test legacy NUMINCRBY
client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]})
client.json().numincrby("doc1", ".b[0].a", 3) == 5
assert client.json().numincrby("doc1", ".b[0].a", 3) == 5

# Test legacy NUMMULTBY
client.json().set("doc1", "$", {"a": "b", "b": [{"a": 2}, {"a": 5.0}, {"a": "c"}]})

with pytest.deprecated_call():
client.json().nummultby("doc1", ".b[0].a", 3) == 6
assert client.json().nummultby("doc1", ".b[0].a", 3) == 6


@pytest.mark.redismod
Expand All @@ -533,25 +534,25 @@ def test_strappend_dollar(client):
"doc1", "$", {"a": "foo", "nested1": {"a": "hello"}, "nested2": {"a": 31}}
)
# Test multi
client.json().strappend("doc1", "bar", "$..a") == [6, 8, None]
assert client.json().strappend("doc1", "bar", "$..a") == [6, 8, None]

# res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
res = [{"a": "foobar", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])

# Test single
client.json().strappend("doc1", "baz", "$.nested1.a") == [11]
assert client.json().strappend("doc1", "baz", "$.nested1.a") == [11]

# res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
res = [{"a": "foobar", "nested1": {"a": "hellobarbaz"}, "nested2": {"a": 31}}]
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])

# Test missing key
with pytest.raises(exceptions.ResponseError):
client.json().strappend("non_existing_doc", "$..a", "err")

# Test multi
client.json().strappend("doc1", "bar", ".*.a") == 8
# res = [{"a": "foo", "nested1": {"a": "hellobar"}, "nested2": {"a": 31}}]
# assert_resp_response(client, client.json().get("doc1", "$"), res, [res])
assert client.json().strappend("doc1", "bar", ".*.a") == 14
res = [{"a": "foobar", "nested1": {"a": "hellobarbazbar"}, "nested2": {"a": 31}}]
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])

# Test missing path
with pytest.raises(exceptions.ResponseError):
Expand All @@ -571,8 +572,8 @@ def test_strlen_dollar(client):
assert res1 == res2

# Test single
client.json().strlen("doc1", "$.nested1.a") == [8]
client.json().strlen("doc1", "$.nested2.a") == [None]
assert client.json().strlen("doc1", "$.nested1.a") == [8]
assert client.json().strlen("doc1", "$.nested2.a") == [None]

# Test missing key
with pytest.raises(exceptions.ResponseError):
Expand All @@ -591,7 +592,7 @@ def test_arrappend_dollar(client):
},
)
# Test multi
client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
assert client.json().arrappend("doc1", "$..a", "bar", "racuda") == [3, 5, None]
res = [
{
"a": ["foo", "bar", "racuda"],
Expand Down Expand Up @@ -775,7 +776,7 @@ def test_arrpop_dollar(client):
},
)
# Test multi (all paths are updated, but return result of last path)
client.json().arrpop("doc1", "..a", "1") is None
assert client.json().arrpop("doc1", "..a", "1") == "null"
res = [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}]
assert_resp_response(client, client.json().get("doc1", "$"), res, [res])

Expand Down
Loading