forked from fedbiomed/fedbiomed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_secagg_manager_node.py
50 lines (37 loc) · 1.67 KB
/
test_secagg_manager_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from unittest.mock import patch
#############################################################
# Import NodeTestCase before importing FedBioMed Module
from testsupport.base_case import NodeTestCase
#############################################################
from fedbiomed.common.constants import _BaseEnum
from fedbiomed.common.exceptions import FedbiomedSecaggError
from fedbiomed.common.secagg_manager import SecaggServkeyManager, SecaggBiprimeManager
from fedbiomed.node.secagg_manager import SecaggManager
class TestSecaggManager(NodeTestCase):
def setUp(self) -> None:
pass
def tearDown(self) -> None:
pass
def test_secagg_manager_01_initialization(self):
# Test server key manager
secagg_setup = SecaggManager(0)()
self.assertIsInstance(secagg_setup, SecaggServkeyManager)
# Test biprime manager
secagg_setup = SecaggManager(1)()
self.assertIsInstance(secagg_setup, SecaggBiprimeManager)
# Raise element type erro
with self.assertRaises(FedbiomedSecaggError):
SecaggManager(2)()
# Raise missing component for element type error
with patch('fedbiomed.node.secagg_manager.SecaggElementTypes') as element_types_patch:
class FakeSecaggElementTypes(_BaseEnum):
DUMMY: int = 0
element_types_patch.return_value = FakeSecaggElementTypes(0)
element_types_patch.__iter__.return_value = [
FakeSecaggElementTypes(0)
]
with self.assertRaises(FedbiomedSecaggError):
SecaggManager(0)()
if __name__ == '__main__': # pragma: no cover
unittest.main()