mirror of
https://github.com/thousandeyes/thousandeyes-sdk-python.git
synced 2025-12-06 06:26:51 +00:00
CP-2063 - Adds request/response model construction tests
This commit is contained in:
parent
ec2a48f18d
commit
cbe836dc16
236
credentials/test/test_credentials_api.py
Normal file
236
credentials/test/test_credentials_api.py
Normal file
@ -0,0 +1,236 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Credentials API
|
||||
|
||||
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
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
import json
|
||||
import unittest
|
||||
import credentials.models
|
||||
|
||||
from credentials.api.credentials_api import CredentialsApi
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class TestCredentialsApi(unittest.TestCase):
|
||||
"""CredentialsApi unit test stubs"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.api = CredentialsApi()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
pass
|
||||
|
||||
def test_create_transaction_tests_credential_models_validation(self) -> None:
|
||||
"""Test case for create_transaction_tests_credential request a nd response models"""
|
||||
request_body_json = """
|
||||
{
|
||||
"name" : "Example Credential 1",
|
||||
"value" : "Example Credential 1 Password"
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(request_body_json)
|
||||
model_from_constructor = credentials.models.CredentialRequest(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
request_from_json = credentials.models.CredentialRequest.from_json(request_body_json)
|
||||
self.assertIsNotNone(request_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
request_from_json.model_fields_set,
|
||||
"Model from constructor fields do not match model from json fields")
|
||||
|
||||
response_body_json = """
|
||||
{
|
||||
"_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"
|
||||
}
|
||||
},
|
||||
"name" : "Example Credential",
|
||||
"id" : "3247"
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(response_body_json)
|
||||
model_from_constructor = credentials.models.CredentialWithoutValue(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
response_from_json = credentials.models.CredentialWithoutValue.from_json(response_body_json)
|
||||
self.assertIsNotNone(response_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
response_from_json.model_fields_set,
|
||||
"Model from constructor fields do not match model from json fields")
|
||||
|
||||
def test_delete_transaction_tests_credential_models_validation(self) -> None:
|
||||
"""Test case for delete_transaction_tests_credential request a nd response models"""
|
||||
|
||||
|
||||
def test_get_transaction_tests_credential_details_models_validation(self) -> None:
|
||||
"""Test case for get_transaction_tests_credential_details request a nd response models"""
|
||||
|
||||
response_body_json = """
|
||||
{
|
||||
"_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"
|
||||
}
|
||||
},
|
||||
"name" : "Example Credential",
|
||||
"id" : "3247",
|
||||
"value" : "rwhR12uDm1Im47p5IVXgzz4ORgC7m48ajzzeWVUt"
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(response_body_json)
|
||||
model_from_constructor = credentials.models.Credential(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
response_from_json = credentials.models.Credential.from_json(response_body_json)
|
||||
self.assertIsNotNone(response_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
response_from_json.model_fields_set,
|
||||
"Model from constructor fields do not match model from json fields")
|
||||
|
||||
def test_get_transaction_tests_credentials_list_models_validation(self) -> None:
|
||||
"""Test case for get_transaction_tests_credentials_list request a nd response models"""
|
||||
|
||||
response_body_json = """
|
||||
{
|
||||
"credentials" : [ {
|
||||
"_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"
|
||||
}
|
||||
},
|
||||
"name" : "Example Credential",
|
||||
"id" : "3247",
|
||||
"value" : "rwhR12uDm1Im47p5IVXgzz4ORgC7m48ajzzeWVUt"
|
||||
}, {
|
||||
"_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"
|
||||
}
|
||||
},
|
||||
"name" : "Example Credential",
|
||||
"id" : "3247",
|
||||
"value" : "rwhR12uDm1Im47p5IVXgzz4ORgC7m48ajzzeWVUt"
|
||||
} ],
|
||||
"_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"
|
||||
}
|
||||
}
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(response_body_json)
|
||||
model_from_constructor = credentials.models.Credentials(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
response_from_json = credentials.models.Credentials.from_json(response_body_json)
|
||||
self.assertIsNotNone(response_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
response_from_json.model_fields_set,
|
||||
"Model from constructor fields do not match model from json fields")
|
||||
|
||||
def test_update_transaction_tests_credential_models_validation(self) -> None:
|
||||
"""Test case for update_transaction_tests_credential request a nd response models"""
|
||||
request_body_json = """
|
||||
{
|
||||
"name" : "Example Credential 1",
|
||||
"value" : "Example Credential 1 Password"
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(request_body_json)
|
||||
model_from_constructor = credentials.models.CredentialRequest(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
request_from_json = credentials.models.CredentialRequest.from_json(request_body_json)
|
||||
self.assertIsNotNone(request_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
request_from_json.model_fields_set,
|
||||
"Model from constructor fields do not match model from json fields")
|
||||
|
||||
response_body_json = """
|
||||
{
|
||||
"_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"
|
||||
}
|
||||
},
|
||||
"name" : "Example Credential",
|
||||
"id" : "3247"
|
||||
}"""
|
||||
|
||||
loaded_json = json.loads(response_body_json)
|
||||
model_from_constructor = credentials.models.CredentialWithoutValue(**loaded_json)
|
||||
self.recursive_assert_no_extra_fields(model_from_constructor)
|
||||
|
||||
response_from_json = credentials.models.CredentialWithoutValue.from_json(response_body_json)
|
||||
self.assertIsNotNone(response_from_json)
|
||||
self.assertCountEqual(model_from_constructor.model_fields_set,
|
||||
response_from_json.model_fields_set,
|
||||
"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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue
Block a user