diff --git a/src/gvm_sync_targets/models/targets_response.py b/src/gvm_sync_targets/models/targets_response.py index 906a22f..4a21992 100644 --- a/src/gvm_sync_targets/models/targets_response.py +++ b/src/gvm_sync_targets/models/targets_response.py @@ -49,14 +49,14 @@ class PortList(Model, tag="port_list"): trash: IntBoolean = element() -class Task(Resource, tag="task"): +class TaskReference(Model, tag="task"): uuid: str = attr("id") name: str = element() -class Tasks(Resource, tag="tasks"): - tasks: list[Task] = element(default_factory=list) +class Tasks(Model, tag="tasks"): + tasks: list[TaskReference] = element(default_factory=list) class Target(Resource, tag="target"): @@ -74,7 +74,7 @@ class Target(Resource, tag="target"): reverse_lookup_unify: IntBoolean = element() alive_tests: str = element() allow_simultaneous_ips: IntBoolean = element() - tasks: Tasks | None = None + tasks: Tasks | None = element(default=None) class GetTargetsResponse(Response, tag="get_targets_response"): diff --git a/tests/gvm_sync_targets/models/targets_response_test.py b/tests/gvm_sync_targets/models/targets_response_test.py index 3fe0d51..9ef8007 100644 --- a/tests/gvm_sync_targets/models/targets_response_test.py +++ b/tests/gvm_sync_targets/models/targets_response_test.py @@ -143,6 +143,151 @@ """ +data_with_tasks = """ + + + + admin + + All Hosts + + 2024-05-15T17:37:30Z + 2024-05-15T17:37:30Z + 1 + 1 + + + Everything + + + 1.2.3.4, 1::1 + + 44 + + All IANA assigned TCP and UDP + 0 + + + SSH auth + 22 + 0 + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + 0 + 0 + Scan Config Default + 1 + foo + + + + admin + + New All Hosts + + 2024-05-17T05:59:19Z + 2024-05-17T05:59:19Z + 1 + 0 + + + Everything + + + 1.2.3.4, 1::1 + + 41 + + All IANA assigned TCP and UDP + 0 + + + SSH auth + 22 + 0 + + + + 0 + + 0 + 0 + 0 + 0 + 0 + Scan Config Default1 + + + adminUnnamed + 2024-05-15T20:41:23Z + 2024-05-15T20:41:23Z + 11 + Everything + 1.2.3.4, 1::1 + 41 + All IANA assigned TCP0 + SSH auth220 + 00 + 00 + 00 + Scan Config Default1 + + + first=1 rows=10 sort=name + + + first + = + 1 + + + rows + = + 10 + + + sort + = + name + + + + + + name + ascending + + + + + 3 + 3 + 3 + + +""" + + def test_parse_model() -> None: model = GetTargetsResponse.from_xml(data) assert not model.model_extra + + +def test_parse_model_with_tasks() -> None: + model = GetTargetsResponse.from_xml(data_with_tasks) + assert not model.model_extra