Skip to content

Commit

Permalink
✅ Test limit and offset params on get credentials (#1169)
Browse files Browse the repository at this point in the history
* issue 10 creds to alice

* update fixture import

* test limit/offset params

* 🎨

* 🎨

* 🎨

* fix test

* update name

* import testMode

* skip if regression

* update checks

* update fixture with param

* 🎨

* fix fixture

* rework test

* 🎨

* rework fixture

* add one more case

* 🎨
  • Loading branch information
cl0ete authored Nov 13, 2024
1 parent 5700df1 commit ab2aa0d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
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
44 changes: 44 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,45 @@ 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
) # issue alice 3 creds
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},
{"limit": 2, "offset": 2},
]

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

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
74 changes: 74 additions & 0 deletions app/tests/fixtures/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,77 @@ 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 = []
num_creds = request.param if hasattr(request, "param") else 3
for i in range(num_creds):
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"]

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

await alice_member_client.post(
f"{CREDENTIALS_BASE_PATH}/{alice_cred_ex_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) == num_creds

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

0 comments on commit ab2aa0d

Please sign in to comment.