From 617ad5aa9ba9b36004326544ddc52e8eca357f23 Mon Sep 17 00:00:00 2001 From: foroogh shahab Date: Tue, 29 Aug 2023 10:48:15 +0200 Subject: [PATCH] add unit test for csle-common --- .../libs/csle-common/tests/test_jobs_dao.py | 38 +---------------- .../csle-common/tests/test_management_dao.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 simulation-system/libs/csle-common/tests/test_management_dao.py diff --git a/simulation-system/libs/csle-common/tests/test_jobs_dao.py b/simulation-system/libs/csle-common/tests/test_jobs_dao.py index 06f58c46e..7f9ad69ca 100644 --- a/simulation-system/libs/csle-common/tests/test_jobs_dao.py +++ b/simulation-system/libs/csle-common/tests/test_jobs_dao.py @@ -34,13 +34,11 @@ from csle_common.dao.simulation_config.simulation_trace import SimulationTrace from csle_common.dao.training.agent_type import AgentType from csle_common.dao.training.player_type import PlayerType -from csle_common.dao.management.management_user import ManagementUser -from csle_common.dao.management.session_token import SessionToken class TestJobsDaoSuite: """ - Test suite for jobs data access objects (DAOs) + Test suite for job data access objects (DAOs) """ def test_data_collection_job_config(self) -> None: @@ -178,37 +176,3 @@ def test_training_job_config(self) -> None: training_job_config.to_dict()) assert (TrainingJobConfig.from_dict(training_job_config.to_dict()) == training_job_config) - - def test_management_user(self) -> None: - """ - Tests creation and dict conversion of the ManagementUser DAO - - :return: None - """ - - management_user = ManagementUser(username="test1", password="test2", email="test@test.test", first_name="test3", - last_name="test4", organization="testi", admin=False, salt="test") - - assert isinstance(management_user.to_dict(), dict) - assert isinstance(ManagementUser.from_dict(management_user.to_dict()), - ManagementUser) - assert (ManagementUser.from_dict(management_user.to_dict()).to_dict() == - management_user.to_dict()) - assert (ManagementUser.from_dict(management_user.to_dict()) == - management_user) - - def test_session_token(self) -> None: - """ - Tests creation and dict conversion of the SessionToken DAO - - :return: None - """ - - session_token = SessionToken(token="test_token", timestamp=11.11, username="test") - assert isinstance(session_token.to_dict(), dict) - assert isinstance(SessionToken.from_dict(session_token.to_dict()), - SessionToken) - assert (SessionToken.from_dict(session_token.to_dict()).to_dict() == - session_token.to_dict()) - assert (SessionToken.from_dict(session_token.to_dict()) == - session_token) diff --git a/simulation-system/libs/csle-common/tests/test_management_dao.py b/simulation-system/libs/csle-common/tests/test_management_dao.py new file mode 100644 index 000000000..8036d5897 --- /dev/null +++ b/simulation-system/libs/csle-common/tests/test_management_dao.py @@ -0,0 +1,42 @@ +from csle_common.dao.management.management_user import ManagementUser +from csle_common.dao.management.session_token import SessionToken + + +class TestManagementDaoSuite: + """ + Test suite for management data access objects (DAOs) + """ + + def test_management_user(self) -> None: + """ + Tests creation and dict conversion of the ManagementUser DAO + + :return: None + """ + + management_user = ManagementUser(username="test1", password="test2", email="test@test.test", first_name="test3", + last_name="test4", organization="testi", admin=False, salt="test") + + assert isinstance(management_user.to_dict(), dict) + assert isinstance(ManagementUser.from_dict(management_user.to_dict()), + ManagementUser) + assert (ManagementUser.from_dict(management_user.to_dict()).to_dict() == + management_user.to_dict()) + assert (ManagementUser.from_dict(management_user.to_dict()) == + management_user) + + def test_session_token(self) -> None: + """ + Tests creation and dict conversion of the SessionToken DAO + + :return: None + """ + + session_token = SessionToken(token="test_token", timestamp=11.11, username="test") + assert isinstance(session_token.to_dict(), dict) + assert isinstance(SessionToken.from_dict(session_token.to_dict()), + SessionToken) + assert (SessionToken.from_dict(session_token.to_dict()).to_dict() == + session_token.to_dict()) + assert (SessionToken.from_dict(session_token.to_dict()) == + session_token)