From 0d0887e91a69bd7e81ef2cbbb2775433b8b52adb Mon Sep 17 00:00:00 2001 From: Phellippe Lima Date: Thu, 23 May 2024 11:52:59 +0100 Subject: [PATCH] CP-2063 - test examples --- credentials/credentials/models/credential.py | 11 +- credentials/test/test_credentials_api.py | 63 +- credentials/test/test_utils.py | 16 + dashboards/dashboards/models/api_dashboard.py | 21 +- dashboards/dashboards/models/api_widget.py | 8 +- dashboards/test/test_dashboards_api.py | 1345 +++++++++++++++++ dashboards/test/test_utils.py | 16 + 7 files changed, 1407 insertions(+), 73 deletions(-) create mode 100644 credentials/test/test_utils.py create mode 100644 dashboards/test/test_dashboards_api.py create mode 100644 dashboards/test/test_utils.py diff --git a/credentials/credentials/models/credential.py b/credentials/credentials/models/credential.py index c6750cbe..3bbbecb7 100644 --- a/credentials/credentials/models/credential.py +++ b/credentials/credentials/models/credential.py @@ -5,7 +5,7 @@ Manage credentials for transaction tests using the Credentials API. The following permissions are required to access Credentials API endpoints: * `Settings Tests Read` for read operations. * `Settings Tests Update` for write operations. * `View sensitive data in web transaction scripts` to view the encrypted value property of credentials. * `Settings Tests Create Transaction (Tx) Tests` to create credentials. For more information about credentials, see [Working With Secure Credentials](https://docs.thousandeyes.com/product-documentation/browser-synthetics/transaction-tests/getting-started/working-with-secure-credentials). - The version of the OpenAPI document: 7.0.0 + The version of the OpenAPI document: 7.0.4 Generated by OpenAPI Generator (https://openapi-generator.tech) Do not edit the class manually. @@ -19,7 +19,7 @@ import json from pydantic import BaseModel, ConfigDict, Field, StrictStr from typing import Any, ClassVar, Dict, List, Optional -from credentials.models.self_links_links import SelfLinksLinks +from credentials.models.self_links import SelfLinks from typing import Optional, Set from typing_extensions import Self @@ -29,7 +29,7 @@ class Credential(BaseModel): """ # noqa: E501 id: Optional[StrictStr] = Field(default=None, description="Unique ID of the credential.") name: Optional[StrictStr] = Field(default=None, description="The name of the credential.") - links: Optional[SelfLinksLinks] = Field(default=None, alias="_links") + links: Optional[SelfLinks] = Field(default=None, alias="_links") value: Optional[StrictStr] = Field(default=None, description="The value of the credential that will be encrypted.") __properties: ClassVar[List[str]] = ["id", "name", "_links", "value"] @@ -37,6 +37,7 @@ class Credential(BaseModel): populate_by_name=True, validate_assignment=True, protected_namespaces=(), + extra="allow", ) @@ -47,7 +48,7 @@ class Credential(BaseModel): def to_json(self) -> str: """Returns the JSON representation of the model using alias""" # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_unset=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: @@ -89,7 +90,7 @@ class Credential(BaseModel): _obj = cls.model_validate({ "id": obj.get("id"), "name": obj.get("name"), - "_links": SelfLinksLinks.from_dict(obj["_links"]) if obj.get("_links") is not None else None, + "_links": SelfLinks.from_dict(obj["_links"]) if obj.get("_links") is not None else None, "value": obj.get("value") }) return _obj diff --git a/credentials/test/test_credentials_api.py b/credentials/test/test_credentials_api.py index f2046c0f..4a241d06 100644 --- a/credentials/test/test_credentials_api.py +++ b/credentials/test/test_credentials_api.py @@ -16,8 +16,8 @@ import json import unittest import credentials.models +from .test_utils import assert_constructed_model_matches_example_json from credentials.api.credentials_api import CredentialsApi -from pydantic import BaseModel class TestCredentialsApi(unittest.TestCase): @@ -38,20 +38,13 @@ class TestCredentialsApi(unittest.TestCase): }""" request_loaded_json = json.loads(request_body_json) - request_from_constructor = credentials.models.CredentialRequest(**request_loaded_json) - self.recursive_assert_no_extra_fields(request_from_constructor) - request_from_json = credentials.models.CredentialRequest.from_json(request_body_json) - self.assertIsNotNone(request_from_json) - self.assertCountEqual(request_from_constructor.model_fields_set, - request_from_json.model_fields_set, - "Request model from constructor fields do not match model from json fields") + assert_constructed_model_matches_example_json(request_from_json, request_loaded_json) response_body_json = """ { "_links" : { "self" : { - "extra" : "unexpected", "hreflang" : "hreflang", "templated" : true, "profile" : "profile", @@ -67,14 +60,8 @@ class TestCredentialsApi(unittest.TestCase): }""" response_loaded_json = json.loads(response_body_json) - response_from_constructor = credentials.models.CredentialWithoutValue(**response_loaded_json) - self.recursive_assert_no_extra_fields(response_from_constructor) - response_from_json = credentials.models.CredentialWithoutValue.from_json(response_body_json) - self.assertIsNotNone(response_from_json) - self.assertCountEqual(response_from_constructor.model_fields_set, - response_from_json.model_fields_set, - "Response model from constructor fields do not match model from json fields") + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) def test_delete_transaction_tests_credential_models_validation(self) -> None: """Test case for delete_transaction_tests_credential request a nd response models""" @@ -103,14 +90,8 @@ class TestCredentialsApi(unittest.TestCase): }""" response_loaded_json = json.loads(response_body_json) - response_from_constructor = credentials.models.Credential(**response_loaded_json) - self.recursive_assert_no_extra_fields(response_from_constructor) - response_from_json = credentials.models.Credential.from_json(response_body_json) - self.assertIsNotNone(response_from_json) - self.assertCountEqual(response_from_constructor.model_fields_set, - response_from_json.model_fields_set, - "Response model from constructor fields do not match model from json fields") + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) def test_get_transaction_tests_credentials_list_models_validation(self) -> None: """Test case for get_transaction_tests_credentials_list request a nd response models""" @@ -165,14 +146,8 @@ class TestCredentialsApi(unittest.TestCase): }""" response_loaded_json = json.loads(response_body_json) - response_from_constructor = credentials.models.Credentials(**response_loaded_json) - self.recursive_assert_no_extra_fields(response_from_constructor) - response_from_json = credentials.models.Credentials.from_json(response_body_json) - self.assertIsNotNone(response_from_json) - self.assertCountEqual(response_from_constructor.model_fields_set, - response_from_json.model_fields_set, - "Response model from constructor fields do not match model from json fields") + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) def test_update_transaction_tests_credential_models_validation(self) -> None: """Test case for update_transaction_tests_credential request a nd response models""" @@ -183,14 +158,8 @@ class TestCredentialsApi(unittest.TestCase): }""" request_loaded_json = json.loads(request_body_json) - request_from_constructor = credentials.models.CredentialRequest(**request_loaded_json) - self.recursive_assert_no_extra_fields(request_from_constructor) - request_from_json = credentials.models.CredentialRequest.from_json(request_body_json) - self.assertIsNotNone(request_from_json) - self.assertCountEqual(request_from_constructor.model_fields_set, - request_from_json.model_fields_set, - "Request model from constructor fields do not match model from json fields") + assert_constructed_model_matches_example_json(request_from_json, request_loaded_json) response_body_json = """ { @@ -211,26 +180,8 @@ class TestCredentialsApi(unittest.TestCase): }""" response_loaded_json = json.loads(response_body_json) - response_from_constructor = credentials.models.CredentialWithoutValue(**response_loaded_json) - self.recursive_assert_no_extra_fields(response_from_constructor) - response_from_json = credentials.models.CredentialWithoutValue.from_json(response_body_json) - self.assertIsNotNone(response_from_json) - self.assertCountEqual(response_from_constructor.model_fields_set, - response_from_json.model_fields_set, - "Response model from constructor fields do not match model from json fields") - - def recursive_assert_no_extra_fields(self, model: BaseModel): - self.assertIsNotNone(model) - self.assertGreater(model.model_fields_set.__len__(), 0) - self.assertEquals(model.model_extra.__len__(), 0, - 'model {0}.{1} has unmapped extra fields {2}' - .format(model.__class__.__module__, model.__class__.__name__, - model.model_extra)) - for f in model.model_fields_set: - field = model.__dict__.get(f) - if isinstance(field, BaseModel): - self.recursive_assert_no_extra_fields(field) + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) if __name__ == '__main__': diff --git a/credentials/test/test_utils.py b/credentials/test/test_utils.py new file mode 100644 index 00000000..930528d9 --- /dev/null +++ b/credentials/test/test_utils.py @@ -0,0 +1,16 @@ +# coding: utf-8 + +import json +import unittest + +from pydantic import BaseModel + + +def assert_constructed_model_matches_example_json(model: BaseModel, loaded_json: dict): + test_case = unittest.TestCase() + test_case.maxDiff = None + test_case.assertIsNotNone(model) + constructed_json = json.loads(model.to_json()) + sorted_loaded_json = json.dumps(loaded_json, sort_keys=True) + sorted_constructed_json = json.dumps(constructed_json, sort_keys=True) + test_case.assertEqual(sorted_loaded_json, sorted_constructed_json) diff --git a/dashboards/dashboards/models/api_dashboard.py b/dashboards/dashboards/models/api_dashboard.py index 642ecf02..2018decc 100644 --- a/dashboards/dashboards/models/api_dashboard.py +++ b/dashboards/dashboards/models/api_dashboard.py @@ -5,7 +5,7 @@ Manage ThousandEyes Dashboards. - The version of the OpenAPI document: 7.0.0 + The version of the OpenAPI document: 7.0.4 Generated by OpenAPI Generator (https://openapi-generator.tech) Do not edit the class manually. @@ -21,7 +21,7 @@ from datetime import datetime from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List, Optional from dashboards.models.api_widget import ApiWidget -from dashboards.models.dashboard_links_links import DashboardLinksLinks +from dashboards.models.dashboard_links import DashboardLinks from dashboards.models.default_timespan import DefaultTimespan from typing import Optional, Set from typing_extensions import Self @@ -38,7 +38,6 @@ class ApiDashboard(BaseModel): global_override: Optional[StrictBool] = Field(default=None, description="When set to `true`, the defaultTimespan is used and overrides the widget's timespan. If set to `false`, the the widget's timespan is used.", alias="globalOverride") migrated_report: Optional[StrictBool] = Field(default=None, description="True if this dashboard was previously a report.", alias="migratedReport") api_link: Optional[List[Dict[str, Any]]] = Field(default=None, description="A links array containing the self and the snapshots links.", alias="apiLink") - links: Optional[DashboardLinksLinks] = Field(default=None, alias="_links") dashboard_id: Optional[StrictStr] = Field(default=None, description="Identifier of a dashboard.", alias="dashboardId") title: Optional[StrictStr] = Field(default=None, description="Title of a dashboard.") is_built_in: Optional[StrictBool] = Field(default=None, description="Indicates if a dashboard is built-in. True for built-in dashboards, false for user-created dashboards.", alias="isBuiltIn") @@ -54,12 +53,14 @@ class ApiDashboard(BaseModel): default_timespan: Optional[DefaultTimespan] = Field(default=None, alias="defaultTimespan") is_global_override: Optional[StrictBool] = Field(default=None, description="When set to `true`, the defaultTimespan is used and overrides the widget's timespan. If set to `false`, the the widget's timespan is used.", alias="isGlobalOverride") is_migrated_report: Optional[StrictBool] = Field(default=None, description="True if this dashboard was previously a report.", alias="isMigratedReport") - __properties: ClassVar[List[str]] = ["globalFilterId", "accountId", "createdBy", "modifiedBy", "modifiedDate", "globalOverride", "migratedReport", "apiLink", "_links", "dashboardId", "title", "isBuiltIn", "aid", "dashboardCreatedBy", "dashboardModifiedBy", "dashboardModifiedDate", "isPrivate", "isDefaultForUser", "isDefaultForAccount", "widgets", "description", "defaultTimespan", "isGlobalOverride", "isMigratedReport"] + links: Optional[DashboardLinks] = Field(default=None, alias="_links") + __properties: ClassVar[List[str]] = ["globalFilterId", "accountId", "createdBy", "modifiedBy", "modifiedDate", "globalOverride", "migratedReport", "apiLink", "dashboardId", "title", "isBuiltIn", "aid", "dashboardCreatedBy", "dashboardModifiedBy", "dashboardModifiedDate", "isPrivate", "isDefaultForUser", "isDefaultForAccount", "widgets", "description", "defaultTimespan", "isGlobalOverride", "isMigratedReport", "_links"] model_config = ConfigDict( populate_by_name=True, validate_assignment=True, protected_namespaces=(), + extra="allow", ) @@ -70,7 +71,7 @@ class ApiDashboard(BaseModel): def to_json(self) -> str: """Returns the JSON representation of the model using alias""" # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_unset=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Optional[Self]: @@ -123,9 +124,6 @@ class ApiDashboard(BaseModel): exclude=excluded_fields, exclude_none=True, ) - # override the default output from pydantic by calling `to_dict()` of links - if self.links: - _dict['_links'] = self.links.to_dict() # override the default output from pydantic by calling `to_dict()` of each item in widgets (list) _items = [] if self.widgets: @@ -136,6 +134,9 @@ class ApiDashboard(BaseModel): # override the default output from pydantic by calling `to_dict()` of default_timespan if self.default_timespan: _dict['defaultTimespan'] = self.default_timespan.to_dict() + # override the default output from pydantic by calling `to_dict()` of links + if self.links: + _dict['_links'] = self.links.to_dict() return _dict @classmethod @@ -156,7 +157,6 @@ class ApiDashboard(BaseModel): "globalOverride": obj.get("globalOverride"), "migratedReport": obj.get("migratedReport"), "apiLink": obj.get("apiLink"), - "_links": DashboardLinksLinks.from_dict(obj["_links"]) if obj.get("_links") is not None else None, "dashboardId": obj.get("dashboardId"), "title": obj.get("title"), "isBuiltIn": obj.get("isBuiltIn"), @@ -171,7 +171,8 @@ class ApiDashboard(BaseModel): "description": obj.get("description"), "defaultTimespan": DefaultTimespan.from_dict(obj["defaultTimespan"]) if obj.get("defaultTimespan") is not None else None, "isGlobalOverride": obj.get("isGlobalOverride"), - "isMigratedReport": obj.get("isMigratedReport") + "isMigratedReport": obj.get("isMigratedReport"), + "_links": DashboardLinks.from_dict(obj["_links"]) if obj.get("_links") is not None else None }) return _obj diff --git a/dashboards/dashboards/models/api_widget.py b/dashboards/dashboards/models/api_widget.py index 707946e1..33e28852 100644 --- a/dashboards/dashboards/models/api_widget.py +++ b/dashboards/dashboards/models/api_widget.py @@ -5,7 +5,7 @@ Manage ThousandEyes Dashboards. - The version of the OpenAPI document: 7.0.0 + The version of the OpenAPI document: 7.0.4 Generated by OpenAPI Generator (https://openapi-generator.tech) Do not edit the class manually. @@ -31,7 +31,7 @@ from dashboards.models.api_stacked_barchart_widget import ApiStackedBarchartWidg from dashboards.models.api_table_widget import ApiTableWidget from dashboards.models.api_test_table_widget import ApiTestTableWidget from dashboards.models.api_timeseries_widget import ApiTimeseriesWidget -from pydantic import StrictStr, Field +from pydantic import StrictStr, Field, model_serializer from typing import Union, List, Set, Optional, Dict from typing_extensions import Literal, Self @@ -280,6 +280,10 @@ class ApiWidget(BaseModel): else: return instance + @model_serializer(when_used="json") + def serialize_model(self): + return json.loads(self.to_json()) + def to_json(self) -> str: """Returns the JSON representation of the actual instance""" if self.actual_instance is None: diff --git a/dashboards/test/test_dashboards_api.py b/dashboards/test/test_dashboards_api.py new file mode 100644 index 00000000..9ef011d5 --- /dev/null +++ b/dashboards/test/test_dashboards_api.py @@ -0,0 +1,1345 @@ +# coding: utf-8 + +""" + Dashboards API + + Manage ThousandEyes Dashboards. + + The version of the OpenAPI document: 7.0.4 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import json +import unittest +import dashboards.models + +from .test_utils import assert_constructed_model_matches_example_json +from dashboards.api.dashboards_api import DashboardsApi + + +class TestDashboardsApi(unittest.TestCase): + """DashboardsApi unit test stubs""" + + def setUp(self) -> None: + self.api = DashboardsApi() + + def tearDown(self) -> None: + pass + + def test_create_dashboard_models_validation(self) -> None: + """Test case for create_dashboard request a nd response models""" + request_body_json = """ + { + "isMigratedReport" : false, + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : "1", + "modifiedDate" : "2023-05-16T10:14:28Z", + "modifiedBy" : "1", + "isGlobalOverride" : true, + "aid" : "1234" + }""" + + request_loaded_json = json.loads(request_body_json) + request_from_json = dashboards.models.Dashboard.from_json(request_body_json) + assert_constructed_model_matches_example_json(request_from_json, request_loaded_json) + + response_body_json = """ + { + "isMigratedReport" : false, + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : "1", + "modifiedDate" : "2023-05-16T10:14:28Z", + "modifiedBy" : "1", + "isGlobalOverride" : true, + "aid" : "1234" + }""" + + response_loaded_json = json.loads(response_body_json) + response_from_json = dashboards.models.Dashboard.from_json(response_body_json) + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) + + def test_delete_dashboard_models_validation(self) -> None: + """Test case for delete_dashboard request a nd response models""" + + + def test_get_dashboard_by_id_models_validation(self) -> None: + """Test case for get_dashboard_by_id request a nd response models""" + + response_body_json = """ + { + "isMigratedReport" : false, + "dashboardCreatedBy" : "1", + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "dashboardModifiedBy" : "1", + "migratedReport" : false, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "accountId" : 1234, + "apiLink" : [ { + "key" : "" + }, { + "key" : "" + } ], + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : 1, + "globalOverride" : true, + "modifiedDate" : "2023-05-16 10:14:28", + "modifiedBy" : 1, + "isGlobalOverride" : true, + "aid" : "1234", + "dashboardModifiedDate" : "2023-05-16T10:14:28Z" + }""" + + response_loaded_json = json.loads(response_body_json) + response_from_json = dashboards.models.ApiDashboard.from_json(response_body_json) + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) + + def test_get_dashboard_data_models_validation(self) -> None: + """Test case for get_dashboard_data request a nd response models""" + + response_body_json = """ + { + "groupLabels" : [ { + "groupProperty" : "AGENT", + "groupLabels" : [ { + "groupId" : "2565", + "groupLabel" : "San Francisco, CA" + }, { + "groupId" : "2565", + "groupLabel" : "San Francisco, CA" + } ] + }, { + "groupProperty" : "AGENT", + "groupLabels" : [ { + "groupId" : "2565", + "groupLabel" : "San Francisco, CA" + }, { + "groupId" : "2565", + "groupLabel" : "San Francisco, CA" + } ] + } ], + "data" : { + "alerts" : [ { + "alertType" : "network-end-to-end-server", + "durationInSeconds" : 25, + "alertSource" : "Http Test", + "active" : true, + "testId" : "56512", + "startTime" : "2023-06-02T08:54:00Z", + "alertId" : "2004945", + "ruleId" : "281724", + "alertRule" : "Http Test Rule" + }, { + "alertType" : "network-end-to-end-server", + "durationInSeconds" : 25, + "alertSource" : "Http Test", + "active" : true, + "testId" : "56512", + "startTime" : "2023-06-02T08:54:00Z", + "alertId" : "2004945", + "ruleId" : "281724", + "alertRule" : "Http Test Rule" + } ], + "summary" : { + "offline" : 2, + "online" : 10, + "disabled" : 3 + }, + "totalAlerts" : 500, + "cards" : [ { + "numberOfDataPoints" : 24192, + "endDate" : "2023-05-16T10:14:28Z", + "cardId" : "lrxxr", + "alertSuppressionWindows" : [ { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + }, { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + } ], + "binSize" : 3600, + "previousValue" : 500.0, + "value" : 100.0, + "startDate" : "2023-05-16T10:14:28Z", + "timestamp" : 1567620000, + "status" : "No data" + }, { + "numberOfDataPoints" : 24192, + "endDate" : "2023-05-16T10:14:28Z", + "cardId" : "lrxxr", + "alertSuppressionWindows" : [ { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + }, { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + } ], + "binSize" : 3600, + "previousValue" : 500.0, + "value" : 100.0, + "startDate" : "2023-05-16T10:14:28Z", + "timestamp" : 1567620000, + "status" : "No data" + } ], + "tests" : [ { + "graphlets" : [ { + "metric" : "Availability", + "testId" : "68257", + "points" : [ { + "x" : 1580403900, + "y" : 128.249 + }, { + "x" : 1580403900, + "y" : 128.249 + } ] + }, { + "metric" : "Availability", + "testId" : "68257", + "points" : [ { + "x" : 1580403900, + "y" : 128.249 + }, { + "x" : 1580403900, + "y" : 128.249 + } ] + } ], + "alertCount" : 398, + "testType" : "Web - HTTP Server", + "testId" : "68256", + "isShared" : true, + "testName" : "Http Test Name", + "target" : "www.google.com" + }, { + "graphlets" : [ { + "metric" : "Availability", + "testId" : "68257", + "points" : [ { + "x" : 1580403900, + "y" : 128.249 + }, { + "x" : 1580403900, + "y" : 128.249 + } ] + }, { + "metric" : "Availability", + "testId" : "68257", + "points" : [ { + "x" : 1580403900, + "y" : 128.249 + }, { + "x" : 1580403900, + "y" : 128.249 + } ] + } ], + "alertCount" : 398, + "testType" : "Web - HTTP Server", + "testId" : "68256", + "isShared" : true, + "testName" : "Http Test Name", + "target" : "www.google.com" + } ], + "columns" : [ { + "columnId" : "938to", + "alertSuppressionWindows" : [ { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + }, { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + } ], + "binSize" : 3600, + "points" : [ { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + }, { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + } ], + "status" : "No data" + }, { + "columnId" : "938to", + "alertSuppressionWindows" : [ { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + }, { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + } ], + "binSize" : 3600, + "points" : [ { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + }, { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + } ], + "status" : "No data" + } ], + "alertSuppressionWindows" : [ { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + }, { + "testIds" : [ "281474976710661" ], + "repeatUnit" : "week", + "durationInSeconds" : 7200, + "repeat" : "custom", + "name" : "Test dashboards", + "repeatEvery" : 5, + "id" : "281474976710662", + "startTimes" : [ "2023-05-16T10:14:28Z" ] + } ], + "activeAlerts" : 483, + "startRound" : 1384309800, + "points" : [ { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + }, { + "numberOfDataPoints" : 23304, + "groups" : [ { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + }, { + "groupProperty" : "COUNTRY", + "groupValue" : "US" + } ], + "value" : 100.0, + "timestamp" : 1567620000 + } ], + "agents" : [ { + "agentId" : "6522", + "agentName" : "0c3898000117", + "location" : { + "locationName" : "San Francisco, California, US", + "latitude" : 37.77493, + "longitude" : -122.41942 + }, + "ipInfo" : { + "ipv6" : "ipv6", + "privateIp" : "172.58.92.31", + "operativeSystemVersion" : "operativeSystemVersion", + "publicIp" : "172.58.92.31" + }, + "status" : "online" + }, { + "agentId" : "6522", + "agentName" : "0c3898000117", + "location" : { + "locationName" : "San Francisco, California, US", + "latitude" : 37.77493, + "longitude" : -122.41942 + }, + "ipInfo" : { + "ipv6" : "ipv6", + "privateIp" : "172.58.92.31", + "operativeSystemVersion" : "operativeSystemVersion", + "publicIp" : "172.58.92.31" + }, + "status" : "online" + } ], + "status" : "No data" + }, + "endDate" : "2022-07-18T22:00:54Z", + "_links" : { + "next" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "previous" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "binSize" : 3600, + "startDate" : "2022-07-17T22:00:54Z" + }""" + + response_loaded_json = json.loads(response_body_json) + response_from_json = dashboards.models.ApiWidgetDataResponse.from_json(response_body_json) + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) + + def test_get_dashboards_for_user_models_validation(self) -> None: + """Test case for get_dashboards_for_user request a nd response models""" + + response_body_json = """ + [ { + "isMigratedReport" : false, + "dashboardCreatedBy" : "1", + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "dashboardModifiedBy" : "1", + "migratedReport" : false, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "accountId" : 1234, + "apiLink" : [ { + "key" : "" + }, { + "key" : "" + } ], + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : 1, + "globalOverride" : true, + "modifiedDate" : "2023-05-16 10:14:28", + "modifiedBy" : 1, + "isGlobalOverride" : true, + "aid" : "1234", + "dashboardModifiedDate" : "2023-05-16T10:14:28Z" + }, { + "isMigratedReport" : false, + "dashboardCreatedBy" : "1", + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "dashboardModifiedBy" : "1", + "migratedReport" : false, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "accountId" : 1234, + "apiLink" : [ { + "key" : "" + }, { + "key" : "" + } ], + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : 1, + "globalOverride" : true, + "modifiedDate" : "2023-05-16 10:14:28", + "modifiedBy" : 1, + "isGlobalOverride" : true, + "aid" : "1234", + "dashboardModifiedDate" : "2023-05-16T10:14:28Z" + } ]""" + + response_loaded_json = json.loads(response_body_json) + response_from_dict = [dashboards.models.ApiDashboard.from_dict(value) for value in response_loaded_json] + self.assertGreater(response_from_dict.__len__(), 0) + for index, element in enumerate(response_from_dict): + self.assertIsNotNone(element) + assert_constructed_model_matches_example_json(element, response_loaded_json[index]) + + def test_update_dashboard_models_validation(self) -> None: + """Test case for update_dashboard request a nd response models""" + request_body_json = """ + { + "isMigratedReport" : false, + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : "1", + "modifiedDate" : "2023-05-16T10:14:28Z", + "modifiedBy" : "1", + "isGlobalOverride" : true, + "aid" : "1234" + }""" + + request_loaded_json = json.loads(request_body_json) + request_from_json = dashboards.models.Dashboard.from_json(request_body_json) + assert_constructed_model_matches_example_json(request_from_json, request_loaded_json) + + response_body_json = """ + { + "isMigratedReport" : false, + "_links" : { + "snapshots" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + }, + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "isDefaultForAccount" : false, + "isDefaultForUser" : true, + "description" : "HTTP Server Widgets", + "isPrivate" : true, + "title" : "HTTP Server Widgets", + "isBuiltIn" : true, + "widgets" : [ { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + }, { + "embedUrl" : "https://embed.thousandeyes.com/e/00aa:3039802d-5c76-42d2-9a93-c6e5f9d3122f", + "shouldExcludeAlertSuppressionWindows" : true, + "_links" : { + "self" : { + "hreflang" : "hreflang", + "templated" : true, + "profile" : "profile", + "name" : "name", + "href" : "https://api.thousandeyes.com/v7/link/to/resource/id", + "type" : "type", + "deprecation" : "deprecation", + "title" : "title" + } + }, + "visualMode" : "Full", + "filters" : { + "TEST" : [ 5187, 5227 ], + "ENDPOINT_MACHINE_ID" : [ "fbd0050c-07f7-43f7-9631-14b32f096962" ] + }, + "title" : "Widget Title", + "type" : "Agent Status", + "metricGroup" : "BGP", + "measure" : { + "percentileValue" : 95.0, + "type" : "MEAN" + }, + "apiLink" : "apiLink", + "metric" : "ENDPOINT_GATEWAY_CPU_LOAD_PERCENT", + "isEmbedded" : true, + "id" : "1234", + "fixedTimespan" : { + "unit" : "Days", + "value" : 10 + }, + "dataSource" : "ENDPOINT_AGENTS", + "direction" : "FROM_TARGET" + } ], + "defaultTimespan" : { + "duration" : 7200, + "timespanDuration" : 7200, + "start" : "2023-05-16T10:14:28Z", + "end" : "2023-05-16T11:14:28Z", + "timespanStart" : "2023-05-16 10:14:28", + "timespanEnd" : "2023-05-16 11:14:28" + }, + "globalFilterId" : "65babd9bb90bf55b17c96c8d", + "dashboardId" : "5e1f7a99143ae6004fdc3bb4", + "createdBy" : "1", + "modifiedDate" : "2023-05-16T10:14:28Z", + "modifiedBy" : "1", + "isGlobalOverride" : true, + "aid" : "1234" + }""" + + response_loaded_json = json.loads(response_body_json) + response_from_json = dashboards.models.Dashboard.from_json(response_body_json) + assert_constructed_model_matches_example_json(response_from_json, response_loaded_json) + + +if __name__ == '__main__': + unittest.main() diff --git a/dashboards/test/test_utils.py b/dashboards/test/test_utils.py new file mode 100644 index 00000000..930528d9 --- /dev/null +++ b/dashboards/test/test_utils.py @@ -0,0 +1,16 @@ +# coding: utf-8 + +import json +import unittest + +from pydantic import BaseModel + + +def assert_constructed_model_matches_example_json(model: BaseModel, loaded_json: dict): + test_case = unittest.TestCase() + test_case.maxDiff = None + test_case.assertIsNotNone(model) + constructed_json = json.loads(model.to_json()) + sorted_loaded_json = json.dumps(loaded_json, sort_keys=True) + sorted_constructed_json = json.dumps(constructed_json, sort_keys=True) + test_case.assertEqual(sorted_loaded_json, sorted_constructed_json)