Skip to content

Commit

Permalink
Merge pull request #277 from Limmen/foro
Browse files Browse the repository at this point in the history
add unit test for csle-common
  • Loading branch information
Limmen authored Aug 29, 2023
2 parents 0cd7724 + 617ad5a commit 099382e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
36 changes: 35 additions & 1 deletion simulation-system/libs/csle-common/tests/test_jobs_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@
from csle_common.dao.system_identification.system_identification_config import SystemIdentificationConfig
from csle_common.dao.system_identification.system_model_type import SystemModelType
from csle_common.dao.training.hparam import HParam
from csle_common.dao.jobs.training_job_config import TrainingJobConfig
from csle_common.dao.training.experiment_config import ExperimentConfig
from csle_common.dao.training.experiment_result import ExperimentResult
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


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:
Expand Down Expand Up @@ -142,3 +148,31 @@ def test_system_identification_job_config(self) -> None:
system_identification_job_config.to_dict())
assert (SystemIdentificationJobConfig.from_dict(system_identification_job_config.to_dict()) ==
system_identification_job_config)

def test_training_job_config(self) -> None:
"""
Tests creation and dict conversion of the TrainingJobConfig DAO
:return: None
"""

hparams = dict()
hparams["test"] = HParam(value=1, name="test", descr="test")
experiment_config = ExperimentConfig(output_dir="test/test", title="test1", random_seeds=[1],
agent_type=AgentType.PPO, hparams=hparams, log_every=10,
player_type=PlayerType.DEFENDER, player_idx=2)

training_job_config = TrainingJobConfig(simulation_env_name="test", progress_percentage=0.5,
pid=1, emulation_env_name="test", num_cached_traces=1,
log_file_path="test/test", descr="test", physical_host_ip="1.1.1.1",
experiment_config=experiment_config,
experiment_result=ExperimentResult(),
simulation_traces=[SimulationTrace(simulation_env="test1")])

assert isinstance(training_job_config.to_dict(), dict)
assert isinstance(TrainingJobConfig.from_dict(training_job_config.to_dict()),
TrainingJobConfig)
assert (TrainingJobConfig.from_dict(training_job_config.to_dict()).to_dict() ==
training_job_config.to_dict())
assert (TrainingJobConfig.from_dict(training_job_config.to_dict()) ==
training_job_config)
42 changes: 42 additions & 0 deletions simulation-system/libs/csle-common/tests/test_management_dao.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]", 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)

0 comments on commit 099382e

Please sign in to comment.