Skip to content

Commit

Permalink
Test coverage for grouping.py
Browse files Browse the repository at this point in the history
Signed-off-by: pfeairheller <[email protected]>
  • Loading branch information
pfeairheller committed Nov 10, 2023
1 parent cf985d4 commit cac9a1f
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/signify/app/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def join(self, name, rot, sigs, gid, smids, rmids):
rmids:
Returns:
dict: ked of sent message
dict: Operation
"""

Expand Down
125 changes: 125 additions & 0 deletions tests/app/test_grouping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# -*- encoding: utf-8 -*-
"""
SIGNIFY
signify.app.test_grouping module
Testing grouping with unit tests
"""

import pytest
from mockito import mock, verify, verifyNoUnwantedInteractions, unstub, expect


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

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

from signify.app.grouping import Groups
groups = Groups(client=mock_client) # type: ignore

from requests import Response
mock_response = mock({'headers': {'content-range': 'aids 0-10/2'}}, spec=Response, strict=True)
expect(mock_client, times=1).get('/multisig/request/EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4').thenReturn(mock_response)
expect(mock_response, times=1).json().thenReturn(
[{'d': "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"}]
)

res = groups.get_request(said="EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4")
assert len(res) == 1
assert res[0]['d'] == "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"

verifyNoUnwantedInteractions()
unstub()


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

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

from signify.app.grouping import Groups
groups = Groups(client=mock_client) # type: ignore

from requests import Response

mock_exn = {}
mock_sigs = ['sig']
mock_atc = b'-attachment'

body = {
'exn': mock_exn,
'sigs': mock_sigs,
'atc': mock_atc.decode("utf-8")
}

mock_response = mock({'headers': {'content-range': 'aids 0-10/2'}}, spec=Response, strict=True)
expect(mock_client, times=1).post(
'/identifiers/test/multisig/request',
json=body).thenReturn(mock_response)

expect(mock_response, times=1).json().thenReturn(
{'t': 'exn', 'd': "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"}
)

res = groups.send_request(name="test", exn=mock_exn, sigs=mock_sigs, atc=mock_atc)
assert res['t'] == 'exn'
assert res['d'] == "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"

verifyNoUnwantedInteractions()
unstub()


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

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

from signify.app.grouping import Groups
groups = Groups(client=mock_client) # type: ignore

from requests import Response
from keri.core.coring import Serder
mock_rot = mock({'ked': {}}, spec=Serder, strict=True)
mock_sigs = ['sig']
mock_smids = ['1', '2', '3']
mock_rmids = ['a', 'b', 'c']

body = {
'tpc': 'multisig',
'rot': {},
'sigs': mock_sigs,
'gid': "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4",
'smids': mock_smids,
'rmids': mock_rmids
}

mock_response = mock({'headers': {'content-range': 'aids 0-10/2'}}, spec=Response, strict=True)
expect(mock_client, times=1).post(
'/identifiers/test/multisig/join',
json=body).thenReturn(mock_response)

expect(mock_response, times=1).json().thenReturn(
{'t': 'op', 'd': "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"}
)

res = groups.join(name="test", rot=mock_rot, sigs=mock_sigs, gid="EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4",
smids=mock_smids, rmids=mock_rmids)
assert res['t'] == 'op'
assert res['d'] == "EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4"

verifyNoUnwantedInteractions()
unstub()




0 comments on commit cac9a1f

Please sign in to comment.