Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Enhance validation for SubTaskData (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
cicharka authored Feb 26, 2024
1 parent 557b15f commit 20d74a6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
6 changes: 3 additions & 3 deletions catalystwan/endpoints/configuration_dashboard_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="empty-body"
from typing import List, Optional
from typing import Dict, List, Optional, Union

from pydantic.v1 import BaseModel, Field

Expand All @@ -13,7 +13,7 @@ class SubTaskData(BaseModel):
action: Optional[str]
activity: List[str]
current_activity: Optional[str] = Field(alias="currentActivity")
action_config: Optional[str] = Field(alias="actionConfig")
action_config: Optional[Union[str, Dict]] = Field(alias="actionConfig")
order: Optional[int]
uuid: Optional[str]
hostname: Optional[str] = Field(alias="host-name")
Expand Down Expand Up @@ -50,7 +50,7 @@ class Validation(BaseModel):
rid: Optional[int] = Field(alias="@rid")
status_id: str = Field(alias="statusId")
process_id: Optional[str] = Field(alias="processId")
action_config: Optional[str] = Field(alias="actionConfig")
action_config: Optional[Union[str, Dict]] = Field(alias="actionConfig")
current_activity: Optional[str] = Field(alias="currentActivity")
action: Optional[str] = Field(alias="action")
start_time: Optional[int] = Field(alias="startTime")
Expand Down
86 changes: 86 additions & 0 deletions catalystwan/tests/test_task_status_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,80 @@ def setUp(self, mock_session):
"isCancelEnabled": True,
"isParallelExecutionEnabled": True,
}
self.response_with_action_config_as_dict = {
"data": [
{
"local-system-ip": "local_ip",
"statusType": "reboot",
"activity": [],
"system-ip": "system_ip",
"site-id": "siteid",
"uuid": "dev-uuid",
"@rid": 1211,
"personality": "vedge",
"processId": "processid",
"actionConfig": {
"devices": {
"deviceIP": "",
"deviceId": "",
"version": "",
"order": "",
"isNutellaMigration": False,
}
},
"device-type": "vedge",
"action": "reboot",
"startTime": 1685440088317,
"reachability": "reachable",
"order": 0,
"vmanageIP": "vmanage_ip",
"host-name": "vm1",
"version": "vmanage-version",
"deviceID": "deviceid",
"statusId": "success",
"currentActivity": "Done - Reboot",
"deviceModel": "vedge-cloud",
"validity": "valid",
"requestStatus": "received",
"status": "Success",
}
],
"validation": {
"statusType": "reboot",
"activity": [],
"vmanageIP": "vmanage-ip",
"system-ip": "Validation",
"deviceID": "Validation",
"uuid": "Validation",
"@rid": 747,
"statusId": "validation_success",
"processId": "reboot-9fc30834-cc46-47c5-83c4-0b837cf84f1a",
"actionConfig": {
"devices": {"deviceIP": "", "deviceId": "", "version": "", "order": "", "isNutellaMigration": False}
},
"currentActivity": "Done - Validation",
"action": "reboot",
"startTime": 1685440057748,
"requestStatus": "received",
"status": "Validation success",
"order": 0,
},
"summary": {
"action": "reboot",
"name": "Reboot",
"detailsURL": "/dataservice/device/action/status",
"startTime": "1685440057829",
"endTime": "1685440179295",
"userSessionUserName": "admin",
"userSessionIP": "10.0.1.1",
"tenantName": "DefaultTenant",
"total": 1,
"status": "done",
"count": {"Success": 1},
},
"isCancelEnabled": True,
"isParallelExecutionEnabled": True,
}

@patch.object(Task, "_Task__check_validation_status")
@patch.object(ConfigurationDashboardStatus, "find_status")
Expand Down Expand Up @@ -256,6 +330,18 @@ def test_wait_for_completed_empty_data(self, mock_task_response, mock_validation
# Assert
self.assertEqual(answer, True)

@patch.object(Task, "_Task__check_validation_status")
@patch.object(ConfigurationDashboardStatus, "find_status")
def test_wait_for_completed_with_action_config_as_dict(self, mock_task_response, mock_validation):
# Arrange
mock_task_response.return_value = TaskData.parse_obj(self.response_with_action_config_as_dict)

# Act
answer = self.task.wait_for_completed(interval_seconds=1).result

# Assert
self.assertEqual(answer, True)

@patch.object(Task, "_Task__check_validation_status")
@patch.object(ConfigurationDashboardStatus, "find_status")
def test_wait_for_completed_no_data(self, mock_task_response, mock_validation):
Expand Down

0 comments on commit 20d74a6

Please sign in to comment.