Exemplo n.º 1
0
async def inner():
    async with ClientSession() as session:
        client = Client(AIOHTTP(session), Credentials.auto(), REGION_NAME)
        items = [
            item
            async for item in client.query(TABLE_NAME, Key(KEY_FIELD).eq(KEY_VALUE))
        ]
Exemplo n.º 2
0
async def inner():
    async with AsyncClient() as http_client:
        client = Client(HTTPX(http_client), Credentials.auto(), REGION_NAME)
        items = [
            item async for item in client.query(TABLE_NAME,
                                                Key(KEY_FIELD).eq(KEY_VALUE))
        ]
Exemplo n.º 3
0
async def test_query_descending(client: Client, table: TableName):
    item1 = {"h": "h", "r": "1", "d": "x"}
    item2 = {"h": "h", "r": "2", "d": "y"}
    items = [item1, item2]
    await client.put_item(table, item1)
    await client.put_item(table, item2)
    rv = [
        item
        async for item in client.query(table, HashKey("h", "h"), scan_forward=False)
    ]
    assert rv == list(reversed(items))
Exemplo n.º 4
0
async def test_query(client: Client, table: TableName):
    item1 = {"h": "h", "r": "1", "d": "x"}
    item2 = {"h": "h", "r": "2", "d": "y"}
    items = [item1, item2]
    await client.put_item(table, item1)
    await client.put_item(table, item2)
    index = 0
    async for item in client.query(table, HashKey("h", "h")):
        assert item == items[index]
        index += 1
    assert index == 2
Exemplo n.º 5
0
async def test_batch(client: Client, table: TableName):
    response = await client.batch_write(
        {
            table: BatchWriteRequest(
                items_to_put=[{"h": "h", "r": "1"}, {"h": "h", "r": "2"}]
            )
        }
    )
    assert not response
    assert len([item async for item in client.query(table, HashKey("h", "h"))]) == 2

    result = await client.batch_get(
        {table: BatchGetRequest(keys=[{"h": "h", "r": "1"}, {"h": "h", "r": "2"}])}
    )
    assert sorted(result.items[table], key=itemgetter("r")) == sorted(
        [{"h": "h", "r": "1"}, {"h": "h", "r": "2"}], key=itemgetter("r")
    )
    assert not result.unprocessed_keys

    response = await client.batch_write(
        {
            table: BatchWriteRequest(
                items_to_put=[{"h": "h", "r": "3"}],
                keys_to_delete=[{"h": "h", "r": "1"}],
            )
        }
    )
    assert not response
    assert len([item async for item in client.query(table, HashKey("h", "h"))]) == 2
    response = await client.batch_write(
        {
            table: BatchWriteRequest(
                keys_to_delete=[{"h": "h", "r": "2"}, {"h": "h", "r": "3"}],
            )
        }
    )
    assert not response
    assert len([item async for item in client.query(table, HashKey("h", "h"))]) == 0
Exemplo n.º 6
0
async def test_query_with_limit(client: Client,
                                high_throughput_table: TableName):
    big = "x" * 20_000

    await asyncio.gather(*(client.put_item(high_throughput_table, {
        "h": "h",
        "r": str(i),
        "big": big
    }) for i in range(100)))

    items = [
        item async for item in client.query(
            high_throughput_table, HashKey("h", "h"), limit=1)
    ]
    assert len(items) == 1
    assert items[0]["r"] == "0"