diff --git a/src/primaite/simulator/file_system/file_system.py b/src/primaite/simulator/file_system/file_system.py index 42aa0573..bcb0334e 100644 --- a/src/primaite/simulator/file_system/file_system.py +++ b/src/primaite/simulator/file_system/file_system.py @@ -693,7 +693,4 @@ class FileSystem(SimComponent): @property def fail_message(self) -> str: """Message that is reported when a request is rejected by this validator.""" - return ( - f"Cannot perform request on application '{self.application.name}' because it is not in the " - f"{self.state.name} state." - ) + return "Cannot perform request on file that does not exist." diff --git a/src/primaite/simulator/file_system/folder.py b/src/primaite/simulator/file_system/folder.py index af7cc660..d891641e 100644 --- a/src/primaite/simulator/file_system/folder.py +++ b/src/primaite/simulator/file_system/folder.py @@ -489,7 +489,4 @@ class Folder(FileSystemItemABC): @property def fail_message(self) -> str: """Message that is reported when a request is rejected by this validator.""" - return ( - f"Cannot perform request on application '{self.application.name}' because it is not in the " - f"{self.state.name} state." - ) + return "Cannot perform request on file that does not exist." diff --git a/tests/integration_tests/game_layer/actions/test_file_request_permission.py b/tests/integration_tests/game_layer/actions/test_file_request_permission.py index c422ad43..1c143aed 100644 --- a/tests/integration_tests/game_layer/actions/test_file_request_permission.py +++ b/tests/integration_tests/game_layer/actions/test_file_request_permission.py @@ -22,7 +22,7 @@ def game_and_agent_fixture(game_and_agent): def test_create_file(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the validator allows a folder to be created.""" + """Test that the validator allows a files to be created.""" game, agent = game_and_agent_fixture client_1 = game.simulation.network.get_node_by_hostname("client_1") @@ -43,7 +43,7 @@ def test_create_file(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): def test_file_delete_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the validator allows a folder to be created.""" + """Test that the validator allows a file to be deleted.""" game, agent = game_and_agent_fixture client_1 = game.simulation.network.get_node_by_hostname("client_1") @@ -61,7 +61,7 @@ def test_file_delete_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge def test_file_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): - """Test that the validator allows a folder to be created.""" + """Test that the validator allows a file to be scanned.""" game, agent = game_and_agent_fixture client_1 = game.simulation.network.get_node_by_hostname("client_1") @@ -80,3 +80,80 @@ def test_file_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent assert file.health_status == FileSystemItemHealthStatus.CORRUPT assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_repair_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the validator allows a folder to be created.""" + game, agent = game_and_agent_fixture + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file(folder_name="downloads", file_name="cat.png") + + file.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + action = ( + "NODE_FILE_REPAIR", + {"node_id": 0, "folder_id": 0, "file_id": 0}, + ) + agent.store_action(action) + game.step() + + assert file.health_status == FileSystemItemHealthStatus.GOOD + + +def test_file_restore_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the validator allows a file to be restored.""" + game, agent = game_and_agent_fixture + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file(folder_name="downloads", file_name="cat.png") + + file.corrupt() + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + action = ( + "NODE_FILE_RESTORE", + {"node_id": 0, "folder_id": 0, "file_id": 0}, + ) + agent.store_action(action) + game.step() + + assert file.health_status == FileSystemItemHealthStatus.GOOD + + +def test_file_corrupt_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the validator allows a file to be corrupted.""" + game, agent = game_and_agent_fixture + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file(folder_name="downloads", file_name="cat.png") + + assert file.health_status == FileSystemItemHealthStatus.GOOD + + action = ( + "NODE_FILE_CORRUPT", + {"node_id": 0, "folder_id": 0, "file_id": 0}, + ) + agent.store_action(action) + game.step() + + assert file.health_status == FileSystemItemHealthStatus.CORRUPT + + +def test_file_access_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]): + """Test that the validator allows a file to be accessed.""" + game, agent = game_and_agent_fixture + + client_1 = game.simulation.network.get_node_by_hostname("client_1") + file = client_1.file_system.get_file(folder_name="downloads", file_name="cat.png") + assert file.num_access == 0 + + action = ( + "NODE_FILE_ACCESS", + {"node_id": 0, "folder_name": file.folder_name, "file_name": file.name}, + ) + agent.store_action(action) + game.step() + + assert file.num_access == 1