This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GET Monitoring Security Policy Device List
- Loading branch information
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2024 Cisco Systems, Inc. and its affiliates | ||
|
||
# mypy: disable-error-code="empty-body" | ||
|
||
from catalystwan.endpoints import APIEndpoints, get | ||
from catalystwan.models.monitoring.security_policy import DeviceListResponse | ||
|
||
|
||
class SecurityPolicy(APIEndpoints): | ||
@get("/security/policy/devicelist") | ||
def get_device_list(self) -> DeviceListResponse: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Cisco Systems, Inc. and its affiliates | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class DeviceListResponse(BaseModel): | ||
amp_down: list = Field(..., alias="amp_down") | ||
amp_up: list = Field(..., alias="amp_up") | ||
ips_down: list = Field(..., alias="ips_down") | ||
ips_up: list = Field(..., alias="ips_up") | ||
urlf_down: list = Field(..., alias="urlf_down") | ||
urlf_up: list = Field(..., alias="urlf_up") | ||
zbfw_down: list = Field(..., serialization_alias="zbfw_down", validation_alias="zbfw_down") | ||
zbfw_up: list = Field(..., serialization_alias="zbfw_up", validation_alias="zbfw_up") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2022 Cisco Systems, Inc. and its affiliates | ||
|
||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from catalystwan.endpoints.monitoring.security_policy import MonitoringSecurityPolicy | ||
from catalystwan.models.monitoring.security_policy import DeviceListResponse | ||
|
||
|
||
class TestMonitoringSecurityPolicy(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.mock_device_list_data = { | ||
"amp_down": ["2.2.2.2"], | ||
"amp_up": ["3.3.3.3"], | ||
"ips_down": ["2.2.2.2"], | ||
"ips_up": ["1.1.1.1"], | ||
"urlf_down": ["3.3.3.3"], | ||
"urlf_up": ["1.1.1.1", "2.2.2.2"], | ||
"zbfw_down": [], | ||
"zbfw_up": ["1.1.1.1", "2.2.2.2", "3.3.3.3"] | ||
} | ||
|
||
@patch("catalystwan.session.ManagerSession") | ||
def test_get_security_policy_device_list(self, mock_session): | ||
# Arrange | ||
# Create a MagicMock for the response that has a dataobj method | ||
mock_response = MagicMock() | ||
# Set up the mock response's dataobj method to return a ServerInfoResponse | ||
mock_response.dataobj.return_value = DeviceListResponse(**self.mock_device_list_data) | ||
|
||
# Mock the request method of the ManagerSession to return the mock response | ||
mock_session_instance = mock_session.return_value | ||
mock_session_instance.request.return_value = mock_response | ||
|
||
mon_sec_pol_api = MonitoringSecurityPolicy(mock_session_instance) | ||
|
||
# Act | ||
response = mon_sec_pol_api.get_device_list() | ||
|
||
# Assert | ||
self.assertIsInstance(response, DeviceListResponse) | ||
self.assertEqual(response.amp_down, self.mock_device_list_data["amp_down"]) | ||
self.assertEqual(response.amp_down, ["2.2.2.2"]) | ||
self.assertEqual(response.amp_up, self.mock_device_list_data["amp_up"]) | ||
self.assertEqual(response.amp_up, ["3.3.3.3"]) | ||
self.assertEqual(response.ips_down, self.mock_device_list_data["ips_down"]) | ||
self.assertEqual(response.ips_down, ["2.2.2.2"]) | ||
self.assertEqual(response.ips_up, self.mock_device_list_data["ips_up"]) | ||
self.assertEqual(response.ips_up, ["1.1.1.1"]) | ||
self.assertEqual(response.urlf_down, self.mock_device_list_data["urlf_down"]) | ||
self.assertEqual(response.urlf_down, ["3.3.3.3"]) | ||
self.assertEqual(response.urlf_up, self.mock_device_list_data["urlf_up"]) | ||
self.assertEqual(response.urlf_up, ["1.1.1.1", "2.2.2.2"]) | ||
self.assertEqual(response.zbfw_down, self.mock_device_list_data["zbfw_down"]) | ||
self.assertEqual(response.zbfw_down, []) | ||
self.assertEqual(response.zbfw_up, self.mock_device_list_data["zbfw_up"]) | ||
self.assertEqual(response.zbfw_up, ["1.1.1.1", "2.2.2.2", "3.3.3.3"]) | ||
|
||
# Ensure the request method was called | ||
mock_session_instance.request.assert_called_once() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |