Merge remote-tracking branch 'origin/dev' into feature/2476-training-schedules-mockup

This commit is contained in:
Marek Wolan
2024-04-26 16:23:41 +01:00
21 changed files with 502 additions and 156 deletions

View File

@@ -70,7 +70,7 @@ def test_dm_bot_perform_data_manipulation_success(dm_bot):
dm_bot._perform_data_manipulation(p_of_success=1.0)
assert dm_bot.attack_stage in (DataManipulationAttackStage.SUCCEEDED, DataManipulationAttackStage.FAILED)
assert len(dm_bot._host_db_client.connections)
assert len(dm_bot._host_db_client.client_connections)
def test_dm_bot_fails_without_db_client(dm_client):

View File

@@ -56,7 +56,11 @@ def test_connect_to_database_fails_on_reattempt(database_client_on_computer):
database_client, computer = database_client_on_computer
database_client.connected = False
assert database_client._connect(server_ip_address=IPv4Address("192.168.0.1"), is_reattempt=True) is False
database_connection = database_client._connect(
server_ip_address=IPv4Address("192.168.0.1"), connection_request_id="", is_reattempt=True
)
assert database_connection is None
def test_disconnect_when_client_is_closed(database_client_on_computer):
@@ -79,21 +83,20 @@ def test_disconnect(database_client_on_computer):
"""Database client should remove the connection."""
database_client, computer = database_client_on_computer
assert not database_client.connected
assert database_client.connected is False
database_client.connect()
assert database_client.connected
assert database_client.connected is True
database_client.disconnect()
assert not database_client.connected
assert database_client.connected is False
def test_query_when_client_is_closed(database_client_on_computer):
"""Database client should return False when it is not running."""
database_client, computer = database_client_on_computer
database_client.close()
assert database_client.operating_state is ApplicationOperatingState.CLOSED

View File

@@ -1,5 +1,7 @@
from uuid import uuid4
import pytest
from primaite.simulator.system.services.service import ServiceOperatingState
from primaite.simulator.system.software import SoftwareHealthState
@@ -179,7 +181,8 @@ def test_overwhelm_service(service):
assert service.health_state_actual is SoftwareHealthState.OVERWHELMED
def test_create_and_remove_connections(service):
@pytest.mark.xfail(reason="Fails as it's now too simple. Needs to be be refactored so that uses a service on a node.")
def test_create_and_terminate_connections(service):
service.start()
uuid = str(uuid4())
@@ -187,6 +190,6 @@ def test_create_and_remove_connections(service):
assert len(service.connections) == 1
assert service.health_state_actual is SoftwareHealthState.GOOD
assert service.remove_connection(connection_id=uuid) # should be true
assert service.terminate_connection(connection_id=uuid) # should be true
assert len(service.connections) == 0
assert service.health_state_actual is SoftwareHealthState.GOOD