Skip to content

Commit

Permalink
Add test for update with IN condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ojii committed Oct 25, 2022
1 parent 3cbf4d8 commit 65ba76a
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/integration/test_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import asyncio
import contextlib
import secrets
import typing
from operator import itemgetter
from typing import List, Type
from typing import Any, List, Type

import pytest
from yarl import URL
Expand All @@ -10,6 +12,7 @@
from aiodynamo.client import Client
from aiodynamo.credentials import ChainCredentials
from aiodynamo.errors import (
ConditionalCheckFailed,
ItemNotFound,
NoCredentialsFound,
TableNotFound,
Expand Down Expand Up @@ -219,6 +222,39 @@ async def test_update_item(client: Client, table: TableName) -> None:
}


@pytest.mark.parametrize(
"check,cond,ok",
[
(False, F("check").equals(False), True),
(False, F("check").is_in([False]), True),
(0, F("check").is_in([0]), True),
(None, F("check").is_in([None]), True),
(False, F("check").equals(True), False),
(False, F("check").is_in([True]), False),
],
ids=repr,
)
async def test_update_item_condition(
client: Client, table: TableName, check: Any, cond: Condition, ok: bool
) -> None:
key = {"h": "hkv", "r": "rkv"}
item = {**key, "target": 1, "check": check}
await client.put_item(table, item)
ctx: typing.Any = (
contextlib.nullcontext() if ok else pytest.raises(ConditionalCheckFailed)
)
with ctx:
updated = await client.update_item(
table,
key,
F("target").add(1),
condition=cond,
return_values=ReturnValues.all_new,
)
assert updated
assert updated["target"] == 2


async def test_delete_item(client: Client, table: TableName) -> None:
item = {"h": "h", "r": "r"}
await client.put_item(table, item)
Expand Down

0 comments on commit 65ba76a

Please sign in to comment.