Skip to content

Commit

Permalink
Exchanges client test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: pfeairheller <pfeairheller@gmail.com>
  • Loading branch information
pfeairheller committed Oct 22, 2023
1 parent b47a7e9 commit 0bb3b49
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/signify/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,9 @@ def send(self, name, topic, sender, route, payload, embeds, recipients):
"""

exn, sigs, atc = self.createExchangeMessage(sender, route, payload, embeds)
json = self.sendFromEvents(name, topic, exn=exn, sigs=sigs, atc=atc, recipients=recipients)

body = dict(
tpc=topic,
exn=exn.ked,
sigs=sigs,
atc=atc,
rec=recipients
)

res = self.client.post(f"/identifiers/{name}/exchanges", json=body)

return exn, sigs, res.json()
return exn, sigs, json

def createExchangeMessage(self, sender, route, payload, embeds, dig=None, dt=None):
""" Create exn message from parameters and return Serder with signatures and additional attachments.
Expand Down
Empty file added tests/peer/__init__.py
Empty file.
71 changes: 71 additions & 0 deletions tests/peer/test_exchanging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- encoding: utf-8 -*-
"""
SIGNIFY
signify.peer.test_exchanging module
Testing exchanging with unit tests
"""
from mockito import mock, unstub, verifyNoUnwantedInteractions, expect, ANY


def test_exchanges_send(mockHelpingNowIso8601):
from signify.app.clienting import SignifyClient
mock_client = mock(spec=SignifyClient, strict=True)

payload = dict(a='b')
embeds = dict()
recipients = ['Eqbc123']

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore

sender = {'prefix': 'a_prefix', 'name': 'aid1', 'state': {'s': '1', 'd': "ABCDEFG"}}
mock_keeper = mock({'algo': 'salty', 'params': lambda: {'keeper': 'params'}}, spec=keeping.SaltyKeeper, strict=True)
expect(mock_manager, times=1).get(sender).thenReturn(mock_keeper)
expect(mock_keeper, times=1).sign(ser=ANY()).thenReturn(['a signature'])

from requests import Response
mock_response = mock({'content': 'things I found'}, spec=Response, strict=True)
expect(mock_response, times=1).json().thenReturn({'content': 'things I found'})
expect(mock_client, times=1).post("/identifiers/aid1/exchanges",
json={'tpc': 'credentals',
'exn': {'v': 'KERI10JSON0000c2_', 't': 'exn',
'd':
'EAUlN3BbKZMrkGXEAw_nNppDC-ziimwxgPJfewodW_dh',
'i': 'a_prefix', 'p': '',
'dt': '2021-06-27T21:26:21.233257+00:00',
'r': '/ipex/admit', 'q': {}, 'a': {'a': 'b'},
'e': {}}, 'sigs': ['a signature'], 'atc': '',
'rec': ['Eqbc123']}).thenReturn(
mock_response)

from signify.peer.exchanging import Exchanges
exn, sigs, out = Exchanges(client=mock_client).send('aid1', 'credentals', sender=sender, route="/ipex/admit",
payload=payload,
embeds=embeds, recipients=recipients) # type: ignore

assert exn.said == "EAUlN3BbKZMrkGXEAw_nNppDC-ziimwxgPJfewodW_dh"
assert sigs == ['a signature']
assert out == {'content': 'things I found'}

verifyNoUnwantedInteractions()
unstub()


def test_exchanges_get(mockHelpingNowIso8601):
from signify.app.clienting import SignifyClient
mock_client = mock(spec=SignifyClient, strict=True)

from requests import Response
mock_response = mock({'content': 'things I found'}, spec=Response, strict=True)
expect(mock_response, times=1).json().thenReturn({'content': 'an exn'})
expect(mock_client, times=1).get("/identifiers/aid1/exchanges/EEE",).thenReturn(mock_response)

from signify.peer.exchanging import Exchanges
out = Exchanges(client=mock_client).get('aid1', 'EEE') # type: ignore

assert out == {'content': 'an exn'}

verifyNoUnwantedInteractions()
unstub()

0 comments on commit 0bb3b49

Please sign in to comment.