#2740: tests + implement file request validators
This commit is contained in:
@@ -693,7 +693,4 @@ class FileSystem(SimComponent):
|
|||||||
@property
|
@property
|
||||||
def fail_message(self) -> str:
|
def fail_message(self) -> str:
|
||||||
"""Message that is reported when a request is rejected by this validator."""
|
"""Message that is reported when a request is rejected by this validator."""
|
||||||
return (
|
return "Cannot perform request on file that does not exist."
|
||||||
f"Cannot perform request on application '{self.application.name}' because it is not in the "
|
|
||||||
f"{self.state.name} state."
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -489,7 +489,4 @@ class Folder(FileSystemItemABC):
|
|||||||
@property
|
@property
|
||||||
def fail_message(self) -> str:
|
def fail_message(self) -> str:
|
||||||
"""Message that is reported when a request is rejected by this validator."""
|
"""Message that is reported when a request is rejected by this validator."""
|
||||||
return (
|
return "Cannot perform request on file that does not exist."
|
||||||
f"Cannot perform request on application '{self.application.name}' because it is not in the "
|
|
||||||
f"{self.state.name} state."
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def game_and_agent_fixture(game_and_agent):
|
|||||||
|
|
||||||
|
|
||||||
def test_create_file(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
|
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
|
game, agent = game_and_agent_fixture
|
||||||
|
|
||||||
client_1 = game.simulation.network.get_node_by_hostname("client_1")
|
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]):
|
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
|
game, agent = game_and_agent_fixture
|
||||||
|
|
||||||
client_1 = game.simulation.network.get_node_by_hostname("client_1")
|
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]):
|
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
|
game, agent = game_and_agent_fixture
|
||||||
|
|
||||||
client_1 = game.simulation.network.get_node_by_hostname("client_1")
|
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.health_status == FileSystemItemHealthStatus.CORRUPT
|
||||||
assert file.visible_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
|
||||||
|
|||||||
Reference in New Issue
Block a user