This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e333bf
commit 9a78163
Showing
9 changed files
with
139 additions
and
3 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
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,28 @@ | ||
from typing import Optional | ||
|
||
from catalystwan.integration_tests.base import TestCaseBase | ||
from catalystwan.models.settings import ThreadGridApi | ||
|
||
|
||
class TestThreadGridApi(TestCaseBase): | ||
created_thread: Optional[ThreadGridApi] = None | ||
|
||
def test_thread_grid_api(self): | ||
# Arrange | ||
thread = ThreadGridApi() | ||
thread.set_region_api_key("eur", "1234567890") | ||
thread.set_region_api_key("nam", "0987654321") | ||
# Act | ||
response = self.session.endpoints.configuration_settings.create_threat_grid_api_key(thread) | ||
self.created_thread = response.single_or_default() | ||
# Assert | ||
assert self.created_thread is not None | ||
assert self.created_thread.entries[0].region == "nam" | ||
assert self.created_thread.entries[0].apikey == "0987654321" | ||
assert self.created_thread.entries[1].region == "eur" | ||
assert self.created_thread.entries[1].apikey == "1234567890" | ||
|
||
def tearDown(self) -> None: | ||
if self.created_thread: | ||
self.session.endpoints.configuration_settings.create_threat_grid_api_key(ThreadGridApi()) | ||
return super().tearDown() |
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,33 @@ | ||
# Copyright 2024 Cisco Systems, Inc. and its affiliates | ||
from typing import Any, Dict, List, Literal, Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, SerializationInfo, SerializerFunctionWrapHandler, model_serializer | ||
|
||
Region = Literal["nam", "eur"] | ||
|
||
|
||
class ThreadGridApiEntires(BaseModel): | ||
model_config = ConfigDict(extra="forbid") | ||
region: Region | ||
apikey: Optional[str] = Field(default="") | ||
|
||
|
||
class ThreadGridApi(BaseModel): | ||
model_config = ConfigDict(extra="forbid") | ||
entries: List[ThreadGridApiEntires] = Field( | ||
default_factory=lambda: [ | ||
ThreadGridApiEntires(region="nam"), | ||
ThreadGridApiEntires(region="eur"), | ||
] | ||
) | ||
|
||
def set_region_api_key(self, region: Region, apikey: str) -> None: | ||
for entry in self.entries: | ||
if entry.region == region: | ||
entry.apikey = apikey | ||
return | ||
raise ValueError(f"Region {region} not found in ThreadGridApi") | ||
|
||
@model_serializer(mode="wrap") | ||
def envelope_data(self, handler: SerializerFunctionWrapHandler, info: SerializationInfo) -> Dict[str, Any]: | ||
return {"data": [handler(self)]} |
31 changes: 31 additions & 0 deletions
31
catalystwan/tests/config_migration/policy_converters/test_thread_grid_api.py
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,31 @@ | ||
# Copyright 2024 Cisco Systems, Inc. and its affiliates | ||
import unittest | ||
|
||
from catalystwan.models.configuration.config_migration import PolicyConvertContext | ||
from catalystwan.models.policy.list.threat_grid_api_key import ThreatGridApiKeyEntry, ThreatGridApiKeyList | ||
from catalystwan.utils.config_migration.converters.policy.policy_lists import convert | ||
|
||
|
||
class TestThreadGridApiConverter(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.context = PolicyConvertContext() | ||
|
||
def test_thread_grid_api_conversion(self): | ||
# Arrange | ||
policy = ThreatGridApiKeyList( | ||
name="ThreatGridApiKeyList", | ||
description="ThreatGridApiKeyList", | ||
entries=[ | ||
ThreatGridApiKeyEntry(region="eur", api_key="123"), | ||
ThreatGridApiKeyEntry(region="nam", api_key="456"), | ||
], | ||
) | ||
# Act -- This action adds object to the context | ||
convert(policy, context=self.context) | ||
thread = self.context.thread_grid_api | ||
# Assert | ||
assert len(thread.entries) == 2 | ||
assert thread.entries[0].region == "nam" | ||
assert thread.entries[0].apikey == "456" | ||
assert thread.entries[1].region == "eur" | ||
assert thread.entries[1].apikey == "123" |
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
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