Merged PR 378: Add create file/folder and file access requests
## Summary Added requests in file system that allows: - file to be created - folder to be created - file to be "accessed" ## Test process https://dev.azure.com/ma-dev-uk/PrimAITE/_git/PrimAITE/pullrequest/378?_a=files&path=/tests/integration_tests/test_simulation/test_request_response.py ## Checklist - [X] PR is linked to a **work item** - [X] **acceptance criteria** of linked ticket are met - [X] performed **self-review** of the code - [X] written **tests** for any new functionality added with this PR - [ ] updated the **documentation** if this PR changes or adds functionality - [ ] written/updated **design docs** if this PR implements new functionality - [ ] updated the **change log** - [X] ran **pre-commit** checks for code style - [ ] attended to any **TO-DOs** left in the code Related work items: #2606
This commit is contained in:
@@ -329,6 +329,78 @@ def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
|
||||
assert file.deleted
|
||||
|
||||
|
||||
def test_node_file_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
|
||||
"""Test that a file is created."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1 = game.simulation.network.get_node_by_hostname("client_1") #
|
||||
|
||||
action = (
|
||||
"NODE_FILE_CREATE",
|
||||
{
|
||||
"node_id": 0,
|
||||
"folder_name": "test",
|
||||
"file_name": "file.txt",
|
||||
},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
assert client_1.file_system.get_file(folder_name="test", file_name="file.txt")
|
||||
|
||||
|
||||
def test_node_file_access(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
|
||||
"""Test that the file access increments."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1 = game.simulation.network.get_node_by_hostname("client_1") #
|
||||
|
||||
action = (
|
||||
"NODE_FILE_CREATE",
|
||||
{
|
||||
"node_id": 0,
|
||||
"folder_name": "test",
|
||||
"file_name": "file.txt",
|
||||
},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
assert client_1.file_system.get_file(folder_name="test", file_name="file.txt").num_access == 0
|
||||
|
||||
action = (
|
||||
"NODE_FILE_ACCESS",
|
||||
{
|
||||
"node_id": 0,
|
||||
"folder_name": "test",
|
||||
"file_name": "file.txt",
|
||||
},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
assert client_1.file_system.get_file(folder_name="test", file_name="file.txt").num_access == 1
|
||||
|
||||
|
||||
def test_node_folder_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
|
||||
"""Test that a folder is created."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1 = game.simulation.network.get_node_by_hostname("client_1") #
|
||||
|
||||
action = (
|
||||
"NODE_FOLDER_CREATE",
|
||||
{
|
||||
"node_id": 0,
|
||||
"folder_name": "test",
|
||||
},
|
||||
)
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
assert client_1.file_system.get_folder(folder_name="test")
|
||||
|
||||
|
||||
def test_network_router_port_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
|
||||
"""Test that the NetworkPortDisableAction can form a request and that it is accepted by the simulation."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
@@ -15,6 +15,31 @@ from primaite.simulator.network.transmission.transport_layer import Port
|
||||
from tests.conftest import TestApplication, TestService
|
||||
|
||||
|
||||
def test_successful_node_file_system_creation_request(example_network):
|
||||
"""Tests that the file system requests."""
|
||||
client_1 = example_network.get_node_by_hostname("client_1")
|
||||
assert client_1.file_system.get_file(folder_name="root", file_name="test.txt") is None
|
||||
|
||||
response = example_network.apply_request(["node", "client_1", "file_system", "create", "file", "", "test.txt"])
|
||||
|
||||
assert response
|
||||
assert client_1.file_system.get_file(folder_name="root", file_name="test.txt")
|
||||
|
||||
assert client_1.file_system.get_folder(folder_name="test_folder") is None
|
||||
|
||||
response = example_network.apply_request(["node", "client_1", "file_system", "create", "folder", "test_folder"])
|
||||
|
||||
assert response
|
||||
assert client_1.file_system.get_folder(folder_name="test_folder")
|
||||
|
||||
assert client_1.file_system.get_file(folder_name="root", file_name="test.txt").num_access == 0
|
||||
|
||||
response = example_network.apply_request(["node", "client_1", "file_system", "access", "root", "test.txt"])
|
||||
|
||||
assert response
|
||||
assert client_1.file_system.get_file(folder_name="root", file_name="test.txt").num_access == 1
|
||||
|
||||
|
||||
def test_successful_application_requests(example_network):
|
||||
net = example_network
|
||||
|
||||
|
||||
Reference in New Issue
Block a user