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

✅ Test limit and offset params on get credentials #1169

Merged
merged 19 commits into from
Nov 13, 2024
1 change: 1 addition & 0 deletions app/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
get_or_issue_regression_cred_revoked,
get_or_issue_regression_cred_valid,
issue_alice_creds,
issue_alice_many_creds,
issue_credential_to_alice,
meld_co_issue_credential_to_alice,
revoke_alice_creds,
Expand Down
41 changes: 41 additions & 0 deletions app/tests/e2e/test_wallet_credentials.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
from typing import List

import pytest
from fastapi import HTTPException

from app.routes.wallet.credentials import router
from app.tests.util.regression_testing import TestMode
from shared import RichAsyncClient
from shared.models.credential_exchange import CredentialExchange

Expand Down Expand Up @@ -60,3 +62,42 @@ async def test_get_and_delete_credential_record(
f"{WALLET_CREDENTIALS_PATH}/{credential_id}"
)
assert exc.value.status_code == 404


@pytest.mark.anyio
@pytest.mark.skipif(
TestMode.regression_run in TestMode.fixture_params,
reason="Skipping due to regression run",
)
@pytest.mark.parametrize("issue_alice_many_creds", [3], indirect=True)
cl0ete marked this conversation as resolved.
Show resolved Hide resolved
async def test_get_credential_record_with_limit(
alice_member_client: RichAsyncClient,
issue_alice_many_creds: List[CredentialExchange], # pylint: disable=unused-argument
):
valid_params = [
{"limit": 1},
{"limit": 2},
{"limit": 3},
{"limit": 4},
{"limit": 1, "offset": 4},
cl0ete marked this conversation as resolved.
Show resolved Hide resolved
]

expected_length = [1, 2, 3, 3, 0]

for params, length in zip(valid_params, expected_length):
response = (
await alice_member_client.get(WALLET_CREDENTIALS_PATH, params=params)
).json()
assert len(response["results"]) == length

invalid_params = [
{"limit": -1}, # must be positive
{"offset": -1}, # must be positive
{"limit": 0}, # must be greater than 0
{"limit": 10001}, # must be less than or equal to max in ACA-Py: 10'000
]

for params in invalid_params:
with pytest.raises(HTTPException) as exc:
await alice_member_client.get(WALLET_CREDENTIALS_PATH, params=params)
assert exc.value.status_code == 422
77 changes: 77 additions & 0 deletions app/tests/fixtures/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,80 @@ async def get_or_issue_regression_cred_valid(
referent=valid_credential["referent"],
cred_def_revocable=valid_credential["cred_def_id"],
)


@pytest.fixture(scope="function")
async def issue_alice_many_creds(
request,
faber_client: RichAsyncClient,
alice_member_client: RichAsyncClient,
credential_definition_id: str,
faber_and_alice_connection: FaberAliceConnect,
) -> List[CredentialExchange]:

faber_conn_id = faber_and_alice_connection.faber_connection_id

faber_cred_ex_ids = []
for i in range(request.param):
cl0ete marked this conversation as resolved.
Show resolved Hide resolved
credential = {
"connection_id": faber_conn_id,
"save_exchange_record": True,
"indy_credential_detail": {
"credential_definition_id": credential_definition_id,
"attributes": {"speed": str(i), "name": "Alice", "age": "44"},
},
}
response = (
await faber_client.post(
CREDENTIALS_BASE_PATH,
json=credential,
)
).json()

faber_cred_ex_id = response["credential_exchange_id"]
faber_cred_ex_ids += [faber_cred_ex_id]

thread_id = response["thread_id"]

await check_webhook_state(
client=alice_member_client,
topic="credentials",
state="offer-received",
filter_map={
"thread_id": thread_id,
},
)

cred_exchange = (
await alice_member_client.get(
f"{CREDENTIALS_BASE_PATH}?thread_id={thread_id}"
)
).json()[0]
cl0ete marked this conversation as resolved.
Show resolved Hide resolved
await alice_member_client.post(
f"{CREDENTIALS_BASE_PATH}/{cred_exchange['credential_exchange_id']}/request",
json={},
)

await check_webhook_state(
client=alice_member_client,
topic="credentials",
state="done",
filter_map={
"thread_id": thread_id,
},
)

cred_ex_response = (
await faber_client.get(
CREDENTIALS_BASE_PATH + "?connection_id=" + faber_conn_id
)
).json()
cred_ex_response = [
record
for record in cred_ex_response
if record["credential_exchange_id"] in faber_cred_ex_ids
]

assert len(cred_ex_response) == request.param

return [CredentialExchange(**cred) for cred in cred_ex_response]
Loading