-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Akiff Manji <akiff.manji@quartech.com>
- Loading branch information
Showing
3 changed files
with
201 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import pytest | ||
import time | ||
|
||
from . import Agent, BOB, ALICE | ||
from unittest.mock import patch | ||
|
||
rpc_request = {"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1} | ||
rpc_response = {"jsonrpc": "2.0", "result": 3, "id": 1} | ||
rpc_error = { | ||
"jsonrpc": "2.0", | ||
"error": {"code": -32601, "message": "Method not found"}, | ||
"id": 1, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def bob(): | ||
"""bob agent fixture.""" | ||
yield Agent(BOB) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def alice(): | ||
"""resolver agent fixture.""" | ||
yield Agent(ALICE) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def established_connection(bob, alice): | ||
"""Established connection filter.""" | ||
invite = bob.create_invitation(auto_accept="true")["invitation"] | ||
resp = alice.receive_invite(invite, auto_accept="true") | ||
yield resp["connection_id"] | ||
|
||
|
||
def test_drpc_request(bob, alice, established_connection): | ||
# make sure connection is active... | ||
time.sleep(1) | ||
|
||
alice_drpc_request = alice.send_drpc_request( | ||
connection_id=established_connection, | ||
request=rpc_request, | ||
) | ||
assert True | ||
|
||
# make sure messages are exchanged... | ||
time.sleep(1) | ||
|
||
bob_drpc_request_records = bob.get_drpc_records(thread_id=alice_drpc_request["@id"]) | ||
bob_drpc_request_record = bob_drpc_request_records["results"][0] | ||
tags = bob_drpc_request_record["tags"] | ||
assert len(bob_drpc_request_records["results"]) == 1 | ||
assert bob_drpc_request_record["state"] == "request-received" | ||
assert tags["thread_id"] == alice_drpc_request["@id"] | ||
assert "request" in bob_drpc_request_record | ||
assert bob_drpc_request_record["request"] == rpc_request | ||
|
||
|
||
def test_drpc_response(bob, alice, established_connection): | ||
# make sure connection is active... | ||
time.sleep(1) | ||
|
||
alice_drpc_request = alice.send_drpc_request( | ||
connection_id=established_connection, | ||
request=rpc_request, | ||
) | ||
assert True | ||
|
||
# make sure messages are exchanged... | ||
time.sleep(1) | ||
|
||
bob_connections = bob.get_connections(state="active") | ||
bob_connection = bob_connections["results"][0] | ||
bob_connection_id = bob_connection["connection_id"] | ||
bob_drpc_response = bob.send_drpc_response( | ||
connection_id=bob_connection_id, | ||
thread_id=alice_drpc_request["@id"], | ||
response=rpc_response, | ||
) | ||
assert True | ||
|
||
# make sure messages are exchanged... | ||
time.sleep(1) | ||
|
||
alice_drpc_response_records = alice.get_drpc_records( | ||
connection_id=established_connection, thread_id=alice_drpc_request["@id"] | ||
) | ||
alice_drpc_response_record = alice_drpc_response_records["results"][0] | ||
alice_tags = alice_drpc_response_record["tags"] | ||
alice_thread_id = alice_tags["thread_id"] | ||
|
||
bob_drpc_request_records = bob.get_drpc_records( | ||
connection_id=bob_connection_id, thread_id=alice_drpc_request["@id"] | ||
) | ||
bob_drpc_request_record = bob_drpc_request_records["results"][0] | ||
bob_tags = bob_drpc_request_record["tags"] | ||
bob_thread_id = bob_tags["thread_id"] | ||
|
||
assert len(alice_drpc_response_records["results"]) == 1 | ||
assert alice_thread_id == bob_drpc_response["~thread"]["thid"] | ||
assert alice_drpc_response_record["state"] == "completed" | ||
assert "request" in alice_drpc_response_record | ||
assert "response" in alice_drpc_response_record | ||
assert alice_drpc_response_record["request"] == rpc_request | ||
assert alice_drpc_response_record["response"] == rpc_response | ||
|
||
assert len(bob_drpc_request_records["results"]) == 1 | ||
assert bob_thread_id == alice_drpc_request["@id"] | ||
assert bob_drpc_request_record["state"] == "completed" | ||
assert "request" in bob_drpc_request_record | ||
assert "response" in bob_drpc_request_record | ||
assert bob_drpc_request_record["request"] == rpc_request | ||
assert bob_drpc_request_record["response"] == rpc_response | ||
|
||
|
||
def test_drpc_response_error(bob, alice, established_connection): | ||
# make sure connection is active... | ||
time.sleep(1) | ||
|
||
alice_drpc_request = alice.send_drpc_request( | ||
connection_id=established_connection, | ||
request=rpc_request, | ||
) | ||
assert True | ||
|
||
# make sure messages are exchanged... | ||
time.sleep(1) | ||
|
||
bob_connections = bob.get_connections(state="active") | ||
bob_connection = bob_connections["results"][0] | ||
bob_connection_id = bob_connection["connection_id"] | ||
bob_drpc_response = bob.send_drpc_response( | ||
connection_id=bob_connection_id, | ||
thread_id=alice_drpc_request["@id"], | ||
response=rpc_error, | ||
) | ||
assert True | ||
|
||
# make sure messages are exchanged... | ||
time.sleep(1) | ||
|
||
alice_drpc_response_records = alice.get_drpc_records( | ||
connection_id=established_connection, thread_id=alice_drpc_request["@id"] | ||
) | ||
alice_drpc_response_record = alice_drpc_response_records["results"][0] | ||
alice_tags = alice_drpc_response_record["tags"] | ||
alice_thread_id = alice_tags["thread_id"] | ||
|
||
bob_drpc_request_records = bob.get_drpc_records( | ||
connection_id=bob_connection_id, thread_id=alice_drpc_request["@id"] | ||
) | ||
bob_drpc_request_record = bob_drpc_request_records["results"][0] | ||
bob_tags = bob_drpc_request_record["tags"] | ||
bob_thread_id = bob_tags["thread_id"] | ||
|
||
assert len(alice_drpc_response_records["results"]) == 1 | ||
assert alice_thread_id == bob_drpc_response["~thread"]["thid"] | ||
assert alice_drpc_response_record["state"] == "completed" | ||
assert "request" in alice_drpc_response_record | ||
assert "response" in alice_drpc_response_record | ||
assert alice_drpc_response_record["request"] == rpc_request | ||
assert alice_drpc_response_record["response"] == rpc_error | ||
|
||
assert len(bob_drpc_request_records["results"]) == 1 | ||
assert bob_thread_id == alice_drpc_request["@id"] | ||
assert bob_drpc_request_record["state"] == "completed" | ||
assert "request" in bob_drpc_request_record | ||
assert "response" in bob_drpc_request_record | ||
assert bob_drpc_request_record["request"] == rpc_request | ||
assert bob_drpc_request_record["response"] == rpc_error |