Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/messagesreceived #9

Merged
merged 4 commits into from
Dec 21, 2021
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
9 changes: 0 additions & 9 deletions acapy_plugin_pickup/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,6 @@ class MessagesReceived(AgentMessage):
message_type = f"{PROTOCOL}/messages-received"
message_id_list: Set[str]

@staticmethod
def determine_session(manager: InboundTransportManager, key: str):
"""Determine the session associated with the given key."""
for session in manager.sessions.values():
session = cast(InboundSession, session)
if key in session.reply_verkeys:
return session
return None

async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle MessageReceived message."""
if not self.transport or self.transport.return_route != "all":
Expand Down
1 change: 0 additions & 1 deletion int/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import hashlib
import os

# TODO: Remove debugging tools before final commit
import logging

from acapy_client.client import Client
Expand Down
118 changes: 118 additions & 0 deletions int/tests/test_messagesreceived.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from echo_agent.client import EchoClient
from echo_agent.client import ConnectionInfo
import pytest


@pytest.mark.asyncio
async def test_messages_received_no_id(echo: EchoClient, connection: ConnectionInfo):
"""Testing that an empty ID list does not alter the queue."""

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/status-request",
"~transport": {"return_route": "all"},
},
)
initial_status = await echo.get_message(connection)
inital_count = initial_status["message_count"]

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/messages-received",
"message_id_list": [],
"~transport": {"return_route": "all"},
},
)

final_status = await echo.get_message(connection)
assert final_status["@type"] == "https://didcomm.org/messagepickup/2.0/status"
final_count = final_status["message_count"]
assert inital_count == final_count


@pytest.mark.asyncio
async def test_messages_received_with_id(echo: EchoClient, connection: ConnectionInfo):
"""Testing that accurate ID's remove messages from the queue."""

for _ in range(2):
await echo.send_message(
connection,
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
"response_resquested": True,
},
)

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/status-request",
"~transport": {"return_route": "all"},
},
)
initial_status = await echo.get_message(connection)
inital_count = initial_status["message_count"]

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/delivery-request",
"~transport": {"return_route": "all"},
"limit": 2,
},
)

wrapped_msgs = await echo.get_message(connection)
assert wrapped_msgs["@type"] == "https://didcomm.org/messagepickup/2.0/delivery"
msg_ids = []

for _ in wrapped_msgs["~attach"]:
msg_ids.append(_["@id"])

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/messages-received",
"message_id_list": msg_ids,
"~transport": {"return_route": "all"},
},
)

final_status = await echo.get_message(connection)
assert final_status["@type"] == "https://didcomm.org/messagepickup/2.0/status"
final_count = final_status["message_count"]

assert final_count == inital_count - 2


@pytest.mark.asyncio
async def test_messages_received_junk_id(echo: EchoClient, connection: ConnectionInfo):
"""Testing that an incorrect ID list does not alter the queue."""

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/status-request",
"~transport": {"return_route": "all"},
},
)
initial_status = await echo.get_message(connection)
inital_count = initial_status["message_count"]

await echo.send_message(
connection,
{
"@type": "https://didcomm.org/messagepickup/2.0/messages-received",
"message_id_list": [
"A communications disruption can mean only one thing: invasion"
],
"~transport": {"return_route": "all"},
},
)

final_status = await echo.get_message(connection)
assert final_status["@type"] == "https://didcomm.org/messagepickup/2.0/status"
final_count = final_status["message_count"]
assert inital_count == final_count