Skip to content

Commit

Permalink
🎨 Standardise CONNECTIONS_BASE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Dec 5, 2024
1 parent aad281b commit 69763b4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/tests/e2e/issuer/ld_proof/test_ld_proof_did_key_bbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from fastapi import HTTPException

from app.models.issuer import SendCredential
from app.routes.connections import router as con_router
from app.routes.connections import router as conn_router
from app.routes.issuer import router as issuer_router
from app.routes.oob import router as oob_router
from app.tests.util.connections import FaberAliceConnect
Expand All @@ -21,7 +21,7 @@

CREDENTIALS_BASE_PATH = issuer_router.prefix
OOB_BASE_PATH = oob_router.prefix
CONNECTIONS_BASE_PATH = con_router.prefix
CONNECTIONS_BASE_PATH = conn_router.prefix


credential_ = SendCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi import HTTPException

from app.models.issuer import SendCredential
from app.routes.connections import router as con_router
from app.routes.connections import router as conn_router
from app.routes.issuer import router as issuer_router
from app.routes.oob import router as oob_router
from app.tests.util.connections import FaberAliceConnect
Expand All @@ -16,7 +16,7 @@

CREDENTIALS_BASE_PATH = issuer_router.prefix
OOB_BASE_PATH = oob_router.prefix
CONNECTIONS_BASE_PATH = con_router.prefix
CONNECTIONS_BASE_PATH = conn_router.prefix

credential_ = SendCredential(
type="ld_proof",
Expand Down
10 changes: 5 additions & 5 deletions app/tests/e2e/issuer/test_connections_use_public_did.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from app.tests.util.webhooks import check_webhook_state
from shared import RichAsyncClient

BASE_PATH = router.prefix
CONNECTIONS_BASE_PATH = router.prefix


@pytest.mark.anyio
Expand All @@ -17,7 +17,7 @@ async def test_accept_use_public_did(
invite_json = CreateInvitation(use_public_did=True).model_dump()

response = await faber_client.post(
f"{BASE_PATH}/create-invitation", json=invite_json
f"{CONNECTIONS_BASE_PATH}/create-invitation", json=invite_json
)
assert response.status_code == 200

Expand All @@ -33,7 +33,7 @@ async def test_accept_use_public_did(
).model_dump()

accept_response = await meld_co_client.post(
f"{BASE_PATH}/accept-invitation",
f"{CONNECTIONS_BASE_PATH}/accept-invitation",
json=accept_invite_json,
)
connection_record = accept_response.json()
Expand Down Expand Up @@ -61,7 +61,7 @@ async def test_accept_use_public_did_between_issuer_and_holder(
invite_json = CreateInvitation(use_public_did=True).model_dump()

response = await faber_client.post(
f"{BASE_PATH}/create-invitation", json=invite_json
f"{CONNECTIONS_BASE_PATH}/create-invitation", json=invite_json
)
assert response.status_code == 200

Expand All @@ -77,7 +77,7 @@ async def test_accept_use_public_did_between_issuer_and_holder(
).model_dump()

accept_response = await alice_member_client.post(
f"{BASE_PATH}/accept-invitation",
f"{CONNECTIONS_BASE_PATH}/accept-invitation",
json=accept_invite_json,
)
connection_record = accept_response.json()
Expand Down
72 changes: 44 additions & 28 deletions app/tests/e2e/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from app.tests.util.webhooks import check_webhook_state
from shared import RichAsyncClient

BASE_PATH = router.prefix
CONNECTIONS_BASE_PATH = router.prefix


@pytest.mark.anyio
Expand Down Expand Up @@ -39,7 +39,7 @@ async def test_create_invitation_no_public_did(
with pytest.raises(HTTPException) as exc_info:
# regular holders cannot `use_public_did` as they do not have a public did
await bob_member_client.post(
f"{BASE_PATH}/create-invitation", json=invite_json
f"{CONNECTIONS_BASE_PATH}/create-invitation", json=invite_json
)
assert exc_info.value.status_code == 400
assert (
Expand All @@ -48,7 +48,7 @@ async def test_create_invitation_no_public_did(
)
else:
response = await bob_member_client.post(
f"{BASE_PATH}/create-invitation", json=invite_json
f"{CONNECTIONS_BASE_PATH}/create-invitation", json=invite_json
)
assert response.status_code == 200

Expand All @@ -67,7 +67,9 @@ async def test_accept_invitation(
alice_member_client: RichAsyncClient,
):
alias = "test_alias"
invitation_response = await bob_member_client.post(f"{BASE_PATH}/create-invitation")
invitation_response = await bob_member_client.post(
f"{CONNECTIONS_BASE_PATH}/create-invitation"
)
invitation = invitation_response.json()

accept_invite_json = AcceptInvitation(
Expand All @@ -76,7 +78,7 @@ async def test_accept_invitation(
).model_dump()

accept_response = await alice_member_client.post(
f"{BASE_PATH}/accept-invitation",
f"{CONNECTIONS_BASE_PATH}/accept-invitation",
json=accept_invite_json,
)
connection_record = accept_response.json()
Expand Down Expand Up @@ -113,65 +115,71 @@ async def test_get_connections(

try:
alice_connection = (
await alice_member_client.get(f"{BASE_PATH}/{alice_connection_id}")
await alice_member_client.get(
f"{CONNECTIONS_BASE_PATH}/{alice_connection_id}"
)
).json()
bob_connection = (
await bob_member_client.get(f"{BASE_PATH}/{bob_connection_id}")
await bob_member_client.get(f"{CONNECTIONS_BASE_PATH}/{bob_connection_id}")
).json()

alice_invitation_msg_id_value = alice_connection["invitation_msg_id"]
alice_did = alice_connection["my_did"]

alice_connection_alias = (
await alice_member_client.get(f"{BASE_PATH}?alias={connection_alias}")
await alice_member_client.get(
f"{CONNECTIONS_BASE_PATH}?alias={connection_alias}"
)
).json()[0]["alias"]
assert alice_connection_alias == connection_alias

alice_state = (
await alice_member_client.get(f"{BASE_PATH}?state=completed")
await alice_member_client.get(f"{CONNECTIONS_BASE_PATH}?state=completed")
).json()[0]["state"]
assert alice_state == "completed"

alice_key = (
await alice_member_client.get(
f"{BASE_PATH}?invitation_key={bob_connection['invitation_key']}"
f"{CONNECTIONS_BASE_PATH}?invitation_key={bob_connection['invitation_key']}"
)
).json()[0]["invitation_key"]
assert alice_key == alice_connection["invitation_key"]

alice_invitation_msg_id = (
await alice_member_client.get(
f"{BASE_PATH}?invitation_msg_id={alice_invitation_msg_id_value}"
f"{CONNECTIONS_BASE_PATH}?invitation_msg_id={alice_invitation_msg_id_value}"
)
).json()[0]["invitation_msg_id"]
assert alice_invitation_msg_id == alice_invitation_msg_id_value

alice_my_did = (
await alice_member_client.get(f"{BASE_PATH}?my_did={alice_did}")
await alice_member_client.get(f"{CONNECTIONS_BASE_PATH}?my_did={alice_did}")
).json()[0]["my_did"]
assert alice_my_did == alice_did

alice_their_did = (
await alice_member_client.get(
f"{BASE_PATH}?their_did={bob_connection['my_did']}"
f"{CONNECTIONS_BASE_PATH}?their_did={bob_connection['my_did']}"
)
).json()[0]["their_did"]
assert alice_their_did == alice_connection["their_did"]

with pytest.raises(HTTPException) as exc:
await alice_member_client.get(
f"{BASE_PATH}?their_public_did={bob_connection['their_public_did']}"
f"{CONNECTIONS_BASE_PATH}?their_public_did={bob_connection['their_public_did']}"
)
assert exc.value.status_code == 422

alice_their_role = (
await alice_member_client.get(f"{BASE_PATH}?their_role=inviter")
await alice_member_client.get(f"{CONNECTIONS_BASE_PATH}?their_role=inviter")
).json()[0]["their_role"]
assert alice_their_role == "inviter"

finally:
# clean up temp connection
await alice_member_client.delete(f"{BASE_PATH}/{alice_connection_id}")
await alice_member_client.delete(
f"{CONNECTIONS_BASE_PATH}/{alice_connection_id}"
)


@pytest.mark.anyio
Expand All @@ -188,7 +196,7 @@ async def test_get_connection_by_id(
bob_connection_id = bob_and_alice_connection.bob_connection_id
try:
connection_response = await bob_member_client.get(
f"{BASE_PATH}/{bob_connection_id}"
f"{CONNECTIONS_BASE_PATH}/{bob_connection_id}"
)
connection_record = connection_response.json()

Expand All @@ -198,7 +206,7 @@ async def test_get_connection_by_id(
)
assert_that(connection_record).has_alias(connection_alias)
finally:
await bob_member_client.delete(f"{BASE_PATH}/{bob_connection_id}")
await bob_member_client.delete(f"{CONNECTIONS_BASE_PATH}/{bob_connection_id}")


@pytest.mark.anyio
Expand All @@ -215,16 +223,22 @@ async def test_delete_connection(
bob_connection_id = bob_and_alice_connection.bob_connection_id
alice_connection_id = bob_and_alice_connection.alice_connection_id

response = await bob_member_client.delete(f"{BASE_PATH}/{bob_connection_id}")
response = await bob_member_client.delete(
f"{CONNECTIONS_BASE_PATH}/{bob_connection_id}"
)
assert response.status_code == 204

with pytest.raises(HTTPException) as exc:
response = await bob_member_client.get(f"{BASE_PATH}/{bob_connection_id}")
response = await bob_member_client.get(
f"{CONNECTIONS_BASE_PATH}/{bob_connection_id}"
)
assert exc.value.status_code == 404

# Check that the connection is deleted for alice as well
with pytest.raises(HTTPException) as exc:
response = await alice_member_client.get(f"{BASE_PATH}/{alice_connection_id}")
response = await alice_member_client.get(
f"{CONNECTIONS_BASE_PATH}/{alice_connection_id}"
)
assert exc.value.status_code == 404


Expand All @@ -249,7 +263,7 @@ async def test_get_connections_paginated(
retry = True
while retry and num_tries < 5: # Handle case where record doesn't exist yet
response = await alice_member_client.get(
BASE_PATH,
CONNECTIONS_BASE_PATH,
params={
"alias": test_alias,
"limit": limit,
Expand All @@ -269,7 +283,7 @@ async def test_get_connections_paginated(

# Test ascending order
response = await alice_member_client.get(
BASE_PATH,
CONNECTIONS_BASE_PATH,
params={
"alias": test_alias,
"limit": num_connections_to_test,
Expand All @@ -286,7 +300,7 @@ async def test_get_connections_paginated(

# Test descending order
response = await alice_member_client.get(
BASE_PATH,
CONNECTIONS_BASE_PATH,
params={
"alias": test_alias,
"limit": num_connections_to_test,
Expand All @@ -308,7 +322,7 @@ async def test_get_connections_paginated(

# Test offset greater than number of records
response = await alice_member_client.get(
BASE_PATH,
CONNECTIONS_BASE_PATH,
params={
"alias": test_alias,
"limit": 1,
Expand All @@ -322,7 +336,7 @@ async def test_get_connections_paginated(
prev_connections = []
for offset in range(num_connections_to_test):
response = await alice_member_client.get(
BASE_PATH,
CONNECTIONS_BASE_PATH,
params={
"alias": test_alias,
"limit": 1,
Expand All @@ -347,10 +361,12 @@ async def test_get_connections_paginated(

for params in invalid_params:
with pytest.raises(HTTPException) as exc:
await alice_member_client.get(BASE_PATH, params=params)
await alice_member_client.get(CONNECTIONS_BASE_PATH, params=params)
assert exc.value.status_code == 422

finally:
# Clean up connections
for conn in bob_alice_connections:
await alice_member_client.delete(f"{BASE_PATH}/{conn.alice_connection_id}")
await alice_member_client.delete(
f"{CONNECTIONS_BASE_PATH}/{conn.alice_connection_id}"
)
2 changes: 0 additions & 2 deletions app/tests/e2e/verifier/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from aries_cloudcontroller import IndyPresSpec, IndyRequestedCredsRequestedAttr
from fastapi import HTTPException

from app.routes.connections import router as conn_router
from app.routes.definitions import router as def_router
from app.routes.issuer import router as issuer_router
from app.routes.oob import router as oob_router
Expand All @@ -23,7 +22,6 @@
from shared.models.credential_exchange import CredentialExchange
from shared.models.presentation_exchange import PresentationExchange

CONNECTIONS_BASE_PATH = conn_router.prefix
DEFINITIONS_BASE_PATH = def_router.prefix
ISSUER_BASE_PATH = issuer_router.prefix
OOB_BASE_PATH = oob_router.prefix
Expand Down

0 comments on commit 69763b4

Please sign in to comment.