forked from fedbiomed/fedbiomed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt unit tests for split secagg_manager between common and node
- Loading branch information
Showing
3 changed files
with
69 additions
and
59 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 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 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,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() |