Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #85 from dbluhm/test/integration
Browse files Browse the repository at this point in the history
Integration tests part II
  • Loading branch information
dbluhm authored Aug 18, 2021
2 parents ed72658 + 7fd8baa commit 993c0d2
Show file tree
Hide file tree
Showing 125 changed files with 4,450 additions and 568 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-testing-${{ matrix.python-version }} #-${{ hashFiles('poetry.lock') }}
key: ${{ runner.os }}-testing-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install poetry # (use poetry?)
if: steps.cache-env.outputs.cache-hit != 'true'
run: |
Expand All @@ -59,7 +59,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ steps.setup-poetry-env.outputs.poetry-env }}
key: ${{ runner.os }}-poetry-${{ matrix.python-version }} #-${{ hashFiles('poetry.lock') }}
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
Expand All @@ -81,7 +81,7 @@ jobs:
- uses: actions/checkout@v2
- name: integration tests
run: |
docker-compose -f int/docker-compose.yml up -d && docker attach juggernaut
docker-compose -f int/docker-compose.yml run tests
- name: teardown
run: |
docker-compose -f int/docker-compose.yml down
11 changes: 2 additions & 9 deletions acapy_plugin_toolbox/basicmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ def record_value(self) -> dict:
"""Get record value."""
return {
prop: getattr(self, prop)
for prop in (
"content",
"locale",
"sent_time",
"state",
)
for prop in ("content", "locale", "sent_time", "state")
}

@property
Expand Down Expand Up @@ -214,9 +209,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
tag_filter = dict(
filter(
lambda item: item[1] is not None,
{
"connection_id": context.message.connection_id,
}.items(),
{"connection_id": context.message.connection_id}.items(),
)
)
msgs = sorted(
Expand Down
22 changes: 5 additions & 17 deletions acapy_plugin_toolbox/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ async def connections_event_handler(profile: Profile, event: Event):
responder = profile.inject(BaseResponder)
async with profile.session() as session:
await send_to_admins(
session,
Connected(**conn_record_to_message_repr(record)),
responder,
session, Connected(**conn_record_to_message_repr(record)), responder
)


Expand Down Expand Up @@ -138,14 +136,7 @@ def _state_map(state: str) -> str:
schema={
"my_did": fields.Str(required=False),
"state": fields.Str(
validate=validate.OneOf(
[
"pending",
"active",
"error",
]
),
required=False,
validate=validate.OneOf(["pending", "active", "error"]), required=False
),
"their_did": fields.Str(required=False),
},
Expand Down Expand Up @@ -234,18 +225,14 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
name="Delete",
handler="acapy_plugin_toolbox.connections.DeleteHandler",
msg_type=DELETE,
schema={
"connection_id": fields.Str(required=True),
},
schema={"connection_id": fields.Str(required=True)},
)

Deleted, DeletedSchema = generate_model_schema(
name="Deleted",
handler="acapy_plugin_toolbox.util.PassHandler",
msg_type=DELETED,
schema={
"connection_id": fields.Str(required=True),
},
schema={"connection_id": fields.Str(required=True)},
)


Expand Down Expand Up @@ -311,4 +298,5 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
mediation_id=context.message.mediation_id,
)
connection_resp = Connection(**conn_record_to_message_repr(connection))
connection_resp.assign_thread_from(context.message)
await responder.send_reply(connection_resp)
7 changes: 1 addition & 6 deletions acapy_plugin_toolbox/credential_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ def record_tags(self) -> dict:
"""Get tags for record."""
return {
prop: getattr(self, prop)
for prop in (
"cred_def_id",
"schema_id",
"state",
"author",
)
for prop in ("cred_def_id", "schema_id", "state", "author")
}

@classmethod
Expand Down
1 change: 1 addition & 0 deletions acapy_plugin_toolbox/holder/v0_1/messages/cred_get_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
cred_list = CredList(
results=[credential.serialize() for credential in credentials], page=page
)
cred_list.assign_thread_from(context.message) # self
await responder.send_reply(cred_list)
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

sent = CredRequestSent(record=cred_ex_record)
sent.assign_thread_from(self)

await responder.send(credential_request_message, connection_id=connection_id)
await responder.send_reply(sent)
4 changes: 1 addition & 3 deletions acapy_plugin_toolbox/holder/v0_1/messages/pres_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

await pres_ex_record.delete_record(session)

message = PresDeleted(
presentation_exchange_id=self.presentation_exchange_id,
)
message = PresDeleted(presentation_exchange_id=self.presentation_exchange_id)
message.assign_thread_from(self)
await responder.send_reply(message)
7 changes: 2 additions & 5 deletions acapy_plugin_toolbox/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def __init__(
connection_id: UUID,
proof_request: IndyProofRequest,
comment: str = None,
**kwargs
**kwargs,
):
"""Initialize message."""
super().__init__(**kwargs)
Expand Down Expand Up @@ -270,10 +270,7 @@ class CredList(AdminIssuerMessage):

class Fields:
results = fields.List(
fields.Dict(),
required=True,
description="List of credentials",
example=[],
fields.Dict(), required=True, description="List of credentials", example=[]
)


Expand Down
8 changes: 2 additions & 6 deletions acapy_plugin_toolbox/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
return

address = Address(
address=address_str,
method=SOV_METHOD,
balance=sovatoms_to_tokens(balance),
address=address_str, method=SOV_METHOD, balance=sovatoms_to_tokens(balance)
)
address.assign_thread_from(context.message)
await responder.send_reply(address)
Expand Down Expand Up @@ -341,9 +339,7 @@ async def fetch_transfer_auth(ledger: BaseLedger):
)
if ledger.cache:
await ledger.cache.set(
["admin-payments::xfer_auth"],
xfer_auth_fee,
ledger.cache_duration,
["admin-payments::xfer_auth"], xfer_auth_fee, ledger.cache_duration
)
return xfer_auth_fee

Expand Down
10 changes: 2 additions & 8 deletions acapy_plugin_toolbox/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

_record, request = await manager.prepare_request(connection.connection_id)
# Send mediation request
await responder.send(
request,
connection_id=connection.connection_id,
)
await responder.send(request, connection_id=connection.connection_id)

# Send notification of mediation request sent
sent = MediationRequestSent(connection_id=connection.connection_id)
Expand Down Expand Up @@ -195,10 +192,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
context.message.verkey, context.message.connection_id
)

await responder.send(
update,
connection_id=context.message.connection_id,
)
await responder.send(update, connection_id=context.message.connection_id)

sent = KeylistUpdateSent(
connection_id=context.message.connection_id,
Expand Down
6 changes: 2 additions & 4 deletions acapy_plugin_toolbox/static_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

# Make our info for the connection
my_info = await wallet.create_local_did(
method=DIDMethod.SOV,
key_type=KeyType.ED25519,
method=DIDMethod.SOV, key_type=KeyType.ED25519
)

# Create connection record
Expand Down Expand Up @@ -150,8 +149,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
msg_type=STATIC_CONNECTION_GET_LIST,
schema={
"initiator": fields.Str(
validate=validate.OneOf(["self", "external"]),
required=False,
validate=validate.OneOf(["self", "external"]), required=False
),
"invitation_key": fields.Str(required=False),
"my_did": fields.Str(required=False),
Expand Down
6 changes: 2 additions & 4 deletions acapy_plugin_toolbox/taa.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ async def setup(session: ProfileSession, protocol_registry: ProblemReport = None
msg_type=TAA,
schema={
"version": fields.Str(
required=True,
description="Version of Transaction Author Agreement",
required=True, description="Version of Transaction Author Agreement"
),
"text": fields.Str(
required=True, description="Transaction Author Agreement text"
Expand Down Expand Up @@ -185,8 +184,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"version": fields.Str(required=False, description="Version of accepted TAA."),
"time": fields.Str(required=False, description="Time of acceptance."),
"mechanism": fields.Str(
required=False,
description="The mechanism used to accept the TAA.",
required=False, description="The mechanism used to accept the TAA."
),
},
)
Expand Down
50 changes: 34 additions & 16 deletions acapy_plugin_toolbox/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,26 @@ async def handle(self, context: RequestContext, _responder):
async def admin_connections(session: ProfileSession):
"""Return admin connections."""
storage = session.inject(BaseStorage)
admin_ids = map(
lambda record: record.tags["connection_id"],
filter(
lambda record: json.loads(record.value) == "admin",
await storage.find_all_records(
ConnRecord.RECORD_TYPE_METADATA, {"key": "group"}
),
),
)
admins = [await ConnRecord.retrieve_by_id(session, id) for id in admin_ids]
admin_metadata_records = [
record
for record in await storage.find_all_records(
ConnRecord.RECORD_TYPE_METADATA, {"key": "group"}
)
or []
if json.loads(record.value) == "admin"
]
admins = []
for record in admin_metadata_records:
try:
admin = await ConnRecord.retrieve_by_id(
session, record.tags["connection_id"]
)
admins.append(admin)
except StorageNotFoundError:
# Clean up dangling metadata records of admins
LOGGER.debug("Deleteing dangling admin metadata record: %s", admins)
await storage.delete_record(record)

LOGGER.info("Discovered admins: %s", admins)
return admins

Expand All @@ -370,12 +380,20 @@ async def send_to_admins(
]

for target in admin_targets:
await responder.send(
message,
reply_to_verkey=target.recipient_keys[0],
reply_from_verkey=target.sender_key,
to_session_only=to_session_only,
)
if not to_session_only:
await responder.send(
message,
reply_to_verkey=target.recipient_keys[0],
reply_from_verkey=target.sender_key,
target=target,
)
else:
await responder.send(
message,
reply_to_verkey=target.recipient_keys[0],
reply_from_verkey=target.sender_key,
to_session_only=to_session_only,
)


class InvalidConnection(Exception):
Expand Down
1 change: 1 addition & 0 deletions int/Dockerfile.test.runner
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERS
RUN chmod +x /wait

COPY acapy-backchannel acapy-backchannel
COPY echo-agent echo-agent
COPY pyproject.toml .
COPY poetry.lock .
RUN poetry install --no-dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -52,7 +52,7 @@ def sync_detailed(
mediation_id: Union[Unset, str] = UNSET,
my_endpoint: Union[Unset, str] = UNSET,
my_label: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
their_public_did=their_public_did,
Expand All @@ -75,7 +75,7 @@ async def asyncio_detailed(
mediation_id: Union[Unset, str] = UNSET,
my_endpoint: Union[Unset, str] = UNSET,
my_label: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
their_public_did=their_public_did,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -62,7 +62,7 @@ def sync_detailed(
role: Union[Unset, GetIssueCredential20RecordsRole] = UNSET,
state: Union[Unset, GetIssueCredential20RecordsState] = UNSET,
thread_id: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
connection_id=connection_id,
Expand All @@ -85,7 +85,7 @@ async def asyncio_detailed(
role: Union[Unset, GetIssueCredential20RecordsRole] = UNSET,
state: Union[Unset, GetIssueCredential20RecordsState] = UNSET,
thread_id: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
connection_id=connection_id,
Expand Down
Loading

0 comments on commit 993c0d2

Please sign in to comment.