-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_wallet_credentials.py
62 lines (48 loc) · 2.29 KB
/
test_wallet_credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import logging
import pytest
from fastapi import HTTPException
from app.routes.wallet.credentials import router
from shared import RichAsyncClient
from shared.models.credential_exchange import CredentialExchange
WALLET_CREDENTIALS_PATH = router.prefix
logger = logging.getLogger(__name__)
@pytest.mark.anyio
async def test_get_credentials(alice_member_client: RichAsyncClient):
# Assert empty list is returned for empty wallet when fetching all credentials
response = await alice_member_client.get(WALLET_CREDENTIALS_PATH)
assert response.status_code == 200
@pytest.mark.anyio
async def test_get_and_delete_credential_record(
alice_member_client: RichAsyncClient,
issue_credential_to_alice: CredentialExchange, # pylint: disable=unused-argument
):
credentials_response = await alice_member_client.get(WALLET_CREDENTIALS_PATH)
assert credentials_response.status_code == 200
credentials_response = credentials_response.json()["results"]
credential_id = credentials_response[0]["referent"]
# While in the broader context of Aries and credentials, referent can refer to specific attributes,
# when dealing with the wallet's stored credentials, the referent becomes synonymous with a credential_id
# specific to the wallet. It's how the wallet references and retrieves that particular credential record.
fetch_response = await alice_member_client.get(
f"{WALLET_CREDENTIALS_PATH}/{credential_id}"
)
assert fetch_response.status_code == 200
fetch_response = fetch_response.json()
logger.info("fetch_response: %s", fetch_response)
# Assert we can delete this credential
delete_response = await alice_member_client.delete(
f"{WALLET_CREDENTIALS_PATH}/{credential_id}"
)
assert delete_response.status_code == 204
# Assert referent is no longer in credentials list
credentials_response = (
await alice_member_client.get(WALLET_CREDENTIALS_PATH)
).json()["results"]
for cred in credentials_response:
assert cred["referent"] != credential_id
# Assert fetching deleted credential yields 404
with pytest.raises(HTTPException) as exc:
credentials_response = await alice_member_client.get(
f"{WALLET_CREDENTIALS_PATH}/{credential_id}"
)
assert exc.value.status_code == 404