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

Test/int/connections #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions acapy_plugin_toolbox/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,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)
88 changes: 60 additions & 28 deletions int/tests/test_basicmessage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Basic Message Tests"""
import asyncio
import pytest

from aries_staticagent import StaticConnection
from aries_staticagent import StaticConnection, utils


@pytest.mark.asyncio
async def test_send(connection: StaticConnection, connection_id: str):
"""Test send message"""
with connection.next() as future_recip_message:
sent_message = await asyncio.wait_for(
connection.send_and_await_reply_async(
Expand All @@ -25,7 +25,7 @@ async def test_send(connection: StaticConnection, connection_id: str):
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/sent"
)
assert recip_message["message"]["content"] == "Your hovercraft is full of eels."
# Delete messages to clear the state between tests
# TODO add proper backchannel for clearing messages
await connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/delete",
Expand All @@ -34,40 +34,33 @@ async def test_send(connection: StaticConnection, connection_id: str):


@pytest.mark.asyncio
async def test_delete(connection: StaticConnection, connection_id: str):
for i in range(6):
with connection.next() as future_recip_message:
sent_message = await asyncio.wait_for(
connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/send",
"connection_id": connection_id,
"content": "Test Message #{}".format(i),
},
return_route="all",
),
timeout=60,
)
recip_message = await asyncio.wait_for(future_recip_message, 60)
delete_message = await connection.send_and_await_reply_async(
async def test_new(connection: StaticConnection):
"""Test new message notification"""
new_response = await connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/delete",
}
"@type": "https://didcomm.org/basicmessage/1.0/message",
"~l10n": {"locale": "en"},
"sent_time": utils.timestamp(),
"content": "Your hovercraft is full of eels.",
},
return_route="all",
)
get_messages = await connection.send_and_await_reply_async(
assert (
new_response["@type"]
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/new"
)
assert new_response["message"]["content"] == "Your hovercraft is full of eels."
# Delete messages to clear the state between tests
await connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/get",
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/delete",
}
)
assert (
delete_message["@type"]
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/deleted"
)
assert get_messages["count"] == 0


@pytest.mark.asyncio
async def test_get(connection: StaticConnection, connection_id: str):
"""Send multiple messages and verify that the proper count and content appears in messages list"""
with connection.next() as future_recip_message:
sent_message = await asyncio.wait_for(
connection.send_and_await_reply_async(
Expand Down Expand Up @@ -104,6 +97,10 @@ async def test_get(connection: StaticConnection, connection_id: str):
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/messages"
)
assert get_messages["count"] == 2
assert (
get_messages["messages"][1]["content"] == "Are you suggesting coconuts migrate?"
)
assert get_messages["messages"][0]["content"] == "'Tis but a flesh wound."
# Delete messages to clear the state between tests
await connection.send_and_await_reply_async(
{
Expand All @@ -114,6 +111,7 @@ async def test_get(connection: StaticConnection, connection_id: str):

@pytest.mark.asyncio
async def test_get_limit_offset(connection: StaticConnection, connection_id: str):
"""Send multiple messages and verify that get returns the correct content according to the limit and offset"""
for i in range(6):
with connection.next() as future_recip_message:
sent_message = await asyncio.wait_for(
Expand Down Expand Up @@ -149,3 +147,37 @@ async def test_get_limit_offset(connection: StaticConnection, connection_id: str
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/delete",
}
)


@pytest.mark.asyncio
async def test_delete(connection: StaticConnection, connection_id: str):
"""Send multiple messages, delete them, and verify that the messages count is zero"""
for i in range(6):
with connection.next() as future_recip_message:
sent_message = await asyncio.wait_for(
connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/send",
"connection_id": connection_id,
"content": "Test Message #{}".format(i),
},
return_route="all",
),
timeout=60,
)
recip_message = await asyncio.wait_for(future_recip_message, 60)
delete_message = await connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/delete",
}
)
get_messages = await connection.send_and_await_reply_async(
{
"@type": "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/get",
}
)
assert (
delete_message["@type"]
== "https://github.com/hyperledger/aries-toolbox/tree/master/docs/admin-basicmessage/0.1/deleted"
)
assert get_messages["count"] == 0
Loading