From e6f8d1b844bf2527d12d05bb9cba77df44d610ec Mon Sep 17 00:00:00 2001 From: Sirija Reddy Date: Mon, 20 Apr 2026 12:41:43 +0530 Subject: [PATCH 1/2] feat: Add batch DNS records Signed-off-by: Sirija Reddy --- .../dns_records_v1.py | 1806 +++++++++++++---- test/integration/test_dns_records_v1.py | 353 ++-- test/unit/test_dns_records_v1.py | 1153 ++++++++--- 3 files changed, 2509 insertions(+), 803 deletions(-) diff --git a/ibm_cloud_networking_services/dns_records_v1.py b/ibm_cloud_networking_services/dns_records_v1.py index 4272c41..30d8934 100644 --- a/ibm_cloud_networking_services/dns_records_v1.py +++ b/ibm_cloud_networking_services/dns_records_v1.py @@ -1,6 +1,6 @@ # coding: utf-8 -# (C) Copyright IBM Corp. 2020. +# (C) Copyright IBM Corp. 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,17 +14,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +# IBM OpenAPI SDK Code Generator Version: 3.106.0-09823488-20250707-071701 + """ DNS records + +API Version: 1.0.1 """ from enum import Enum -from typing import Dict, List +from typing import Dict, List, Optional import json from ibm_cloud_sdk_core import BaseService, DetailedResponse from ibm_cloud_sdk_core.authenticators.authenticator import Authenticator from ibm_cloud_sdk_core.get_authenticator import get_authenticator_from_environment +from ibm_cloud_sdk_core.utils import convert_model from .common import get_sdk_headers @@ -32,6 +37,7 @@ # Service ############################################################################## + class DnsRecordsV1(BaseService): """The DNS Records V1 service.""" @@ -39,11 +45,12 @@ class DnsRecordsV1(BaseService): DEFAULT_SERVICE_NAME = 'dns_records' @classmethod - def new_instance(cls, - crn: str, - zone_identifier: str, - service_name: str = DEFAULT_SERVICE_NAME, - ) -> 'DnsRecordsV1': + def new_instance( + cls, + crn: str, + zone_identifier: str, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'DnsRecordsV1': """ Return a new client for the DNS Records service using the specified parameters and external configuration. @@ -66,11 +73,12 @@ def new_instance(cls, service.configure_service(service_name) return service - def __init__(self, - crn: str, - zone_identifier: str, - authenticator: Authenticator = None, - ) -> None: + def __init__( + self, + crn: str, + zone_identifier: str, + authenticator: Authenticator = None, + ) -> None: """ Construct a new client for the DNS Records service. @@ -79,7 +87,7 @@ def __init__(self, :param str zone_identifier: Zone identifier (zone id). :param Authenticator authenticator: The authenticator specifies the authentication mechanism. - Get up to date information from https://github.com/IBM/python-sdk-core/blob/master/README.md + Get up to date information from https://github.com/IBM/python-sdk-core/blob/main/README.md about initializing the authenticator of your choice. """ if crn is None: @@ -87,29 +95,26 @@ def __init__(self, if zone_identifier is None: raise ValueError('zone_identifier must be provided') - BaseService.__init__(self, - service_url=self.DEFAULT_SERVICE_URL, - authenticator=authenticator) + BaseService.__init__(self, service_url=self.DEFAULT_SERVICE_URL, authenticator=authenticator) self.crn = crn self.zone_identifier = zone_identifier - ######################### # DNS Records ######################### - - def list_all_dns_records(self, + def list_all_dns_records( + self, *, - type: str = None, - name: str = None, - content: str = None, - page: int = None, - per_page: int = None, - order: str = None, - direction: str = None, - match: str = None, - **kwargs + type: Optional[str] = None, + name: Optional[str] = None, + content: Optional[str] = None, + page: Optional[int] = None, + per_page: Optional[int] = None, + order: Optional[str] = None, + direction: Optional[str] = None, + match: Optional[str] = None, + **kwargs, ) -> DetailedResponse: """ List all DNS records. @@ -132,9 +137,11 @@ def list_all_dns_records(self, """ headers = {} - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='list_all_dns_records') + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_all_dns_records', + ) headers.update(sdk_headers) params = { @@ -145,31 +152,39 @@ def list_all_dns_records(self, 'per_page': per_page, 'order': order, 'direction': direction, - 'match': match + 'match': match, } if 'headers' in kwargs: headers.update(kwargs.get('headers')) - - url = '/v1/{0}/zones/{1}/dns_records'.format( - *self.encode_path_vars(self.crn, self.zone_identifier)) - request = self.prepare_request(method='GET', - url=url, - headers=headers, - params=params) - - response = self.send(request) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + params=params, + ) + + response = self.send(request, **kwargs) return response - - def create_dns_record(self, + def create_dns_record( + self, *, - type: str = None, - name: str = None, - content: str = None, - priority: int = None, - data: object = None, - **kwargs + type: Optional[str] = None, + name: Optional[str] = None, + ttl: Optional[int] = None, + content: Optional[str] = None, + priority: Optional[int] = None, + proxied: Optional[bool] = None, + data: Optional[dict] = None, + **kwargs, ) -> DetailedResponse: """ Create DNS record. @@ -178,26 +193,32 @@ def create_dns_record(self, :param str type: (optional) dns record type. :param str name: (optional) Required for all record types except SRV. + :param int ttl: (optional) dns record ttl value. :param str content: (optional) dns record content. :param int priority: (optional) For MX records only. - :param object data: (optional) For LOC, SRV and CAA records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse with `dict` result representing a `DnsrecordResp` object """ headers = {} - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='create_dns_record') + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_dns_record', + ) headers.update(sdk_headers) data = { 'type': type, 'name': name, + 'ttl': ttl, 'content': content, 'priority': priority, - 'data': data + 'proxied': proxied, + 'data': data, } data = {k: v for (k, v) in data.items() if v is not None} data = json.dumps(data) @@ -205,21 +226,27 @@ def create_dns_record(self, if 'headers' in kwargs: headers.update(kwargs.get('headers')) - - url = '/v1/{0}/zones/{1}/dns_records'.format( - *self.encode_path_vars(self.crn, self.zone_identifier)) - request = self.prepare_request(method='POST', - url=url, - headers=headers, - data=data) - - response = self.send(request) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) return response - - def delete_dns_record(self, + def delete_dns_record( + self, dnsrecord_identifier: str, - **kwargs + **kwargs, ) -> DetailedResponse: """ Delete DNS record. @@ -232,30 +259,38 @@ def delete_dns_record(self, :rtype: DetailedResponse with `dict` result representing a `DeleteDnsrecordResp` object """ - if dnsrecord_identifier is None: + if not dnsrecord_identifier: raise ValueError('dnsrecord_identifier must be provided') headers = {} - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='delete_dns_record') + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_dns_record', + ) headers.update(sdk_headers) if 'headers' in kwargs: headers.update(kwargs.get('headers')) - - url = '/v1/{0}/zones/{1}/dns_records/{2}'.format( - *self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier)) - request = self.prepare_request(method='DELETE', - url=url, - headers=headers) - - response = self.send(request) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'dnsrecord_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records/{dnsrecord_identifier}'.format(**path_param_dict) + request = self.prepare_request( + method='DELETE', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) return response - - def get_dns_record(self, + def get_dns_record( + self, dnsrecord_identifier: str, - **kwargs + **kwargs, ) -> DetailedResponse: """ Get DNS record. @@ -268,37 +303,46 @@ def get_dns_record(self, :rtype: DetailedResponse with `dict` result representing a `DnsrecordResp` object """ - if dnsrecord_identifier is None: + if not dnsrecord_identifier: raise ValueError('dnsrecord_identifier must be provided') headers = {} - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='get_dns_record') + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_dns_record', + ) headers.update(sdk_headers) if 'headers' in kwargs: headers.update(kwargs.get('headers')) - - url = '/v1/{0}/zones/{1}/dns_records/{2}'.format( - *self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier)) - request = self.prepare_request(method='GET', - url=url, - headers=headers) - - response = self.send(request) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'dnsrecord_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records/{dnsrecord_identifier}'.format(**path_param_dict) + request = self.prepare_request( + method='GET', + url=url, + headers=headers, + ) + + response = self.send(request, **kwargs) return response - - def update_dns_record(self, + def update_dns_record( + self, dnsrecord_identifier: str, *, - type: str = None, - name: str = None, - content: str = None, - priority: int = None, - proxied: bool = None, - data: object = None, - **kwargs + type: Optional[str] = None, + name: Optional[str] = None, + ttl: Optional[int] = None, + content: Optional[str] = None, + priority: Optional[int] = None, + proxied: Optional[bool] = None, + data: Optional[dict] = None, + **kwargs, ) -> DetailedResponse: """ Update DNS record. @@ -308,30 +352,34 @@ def update_dns_record(self, :param str dnsrecord_identifier: Identifier of DNS record. :param str type: (optional) dns record type. :param str name: (optional) Required for all record types except SRV. + :param int ttl: (optional) dns record ttl value. :param str content: (optional) content of dns record. :param int priority: (optional) For MX records only. :param bool proxied: (optional) proxied. - :param object data: (optional) For LOC, SRV and CAA records only. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. :param dict headers: A `dict` containing the request headers :return: A `DetailedResponse` containing the result, headers and HTTP status code. :rtype: DetailedResponse with `dict` result representing a `DnsrecordResp` object """ - if dnsrecord_identifier is None: + if not dnsrecord_identifier: raise ValueError('dnsrecord_identifier must be provided') headers = {} - sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, - service_version='V1', - operation_id='update_dns_record') + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_dns_record', + ) headers.update(sdk_headers) data = { 'type': type, 'name': name, + 'ttl': ttl, 'content': content, 'priority': priority, 'proxied': proxied, - 'data': data + 'data': data, } data = {k: v for (k, v) in data.items() if v is not None} data = json.dumps(data) @@ -339,15 +387,91 @@ def update_dns_record(self, if 'headers' in kwargs: headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'dnsrecord_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records/{dnsrecord_identifier}'.format(**path_param_dict) + request = self.prepare_request( + method='PUT', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) + return response + + def batch_dns_records( + self, + *, + deletes: Optional[List['BatchDnsRecordsRequestDeletesItem']] = None, + patches: Optional[List['BatchDnsRecordsRequestPatchesItem']] = None, + posts: Optional[List['DnsrecordInput']] = None, + puts: Optional[List['BatchDnsRecordsRequestPutsItem']] = None, + **kwargs, + ) -> DetailedResponse: + """ + Batch DNS records. + + Send a Batch of DNS Record API calls to be executed together. The operations you + specify within the /batch request body are always executed in the following order: + deletes, patches, puts, posts. + + :param List[BatchDnsRecordsRequestDeletesItem] deletes: (optional) + :param List[BatchDnsRecordsRequestPatchesItem] patches: (optional) + :param List[DnsrecordInput] posts: (optional) + :param List[BatchDnsRecordsRequestPutsItem] puts: (optional) + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `BatchDnsRecordsResponse` object + """ + + if deletes is not None: + deletes = [convert_model(x) for x in deletes] + if patches is not None: + patches = [convert_model(x) for x in patches] + if posts is not None: + posts = [convert_model(x) for x in posts] + if puts is not None: + puts = [convert_model(x) for x in puts] + headers = {} + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='batch_dns_records', + ) + headers.update(sdk_headers) - url = '/v1/{0}/zones/{1}/dns_records/{2}'.format( - *self.encode_path_vars(self.crn, self.zone_identifier, dnsrecord_identifier)) - request = self.prepare_request(method='PUT', - url=url, - headers=headers, - data=data) + data = { + 'deletes': deletes, + 'patches': patches, + 'posts': posts, + 'puts': puts, + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' - response = self.send(request) + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(self.crn, self.zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/dns_records/batch'.format(**path_param_dict) + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + data=data, + ) + + response = self.send(request, **kwargs) return response @@ -360,6 +484,7 @@ class Order(str, Enum): """ Field by which to order list of DNS records. """ + TYPE = 'type' NAME = 'name' CONTENT = 'content' @@ -369,12 +494,14 @@ class Direction(str, Enum): """ Direction in which to order results [ascending/descending order]. """ + ASC = 'asc' DESC = 'desc' class Match(str, Enum): """ Whether to match all (all) or atleast one search parameter (any). """ + ANY = 'any' ALL = 'all' @@ -384,35 +511,37 @@ class Match(str, Enum): ############################################################################## -class DeleteDnsrecordRespResult(): +class BatchDnsRecordsRequestDeletesItem: """ - result. + BatchDnsRecordsRequestDeletesItem. - :attr str id: dns record id. + :param str id: DNS record ID to delete. """ - def __init__(self, - id: str) -> None: + def __init__( + self, + id: str, + ) -> None: """ - Initialize a DeleteDnsrecordRespResult object. + Initialize a BatchDnsRecordsRequestDeletesItem object. - :param str id: dns record id. + :param str id: DNS record ID to delete. """ self.id = id @classmethod - def from_dict(cls, _dict: Dict) -> 'DeleteDnsrecordRespResult': - """Initialize a DeleteDnsrecordRespResult object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordsRequestDeletesItem': + """Initialize a BatchDnsRecordsRequestDeletesItem object from a json dictionary.""" args = {} - if 'id' in _dict: - args['id'] = _dict.get('id') + if (id := _dict.get('id')) is not None: + args['id'] = id else: - raise ValueError('Required property \'id\' not present in DeleteDnsrecordRespResult JSON') + raise ValueError('Required property \'id\' not present in BatchDnsRecordsRequestDeletesItem JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a DeleteDnsrecordRespResult object from a json dictionary.""" + """Initialize a BatchDnsRecordsRequestDeletesItem object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -427,85 +556,115 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this DeleteDnsrecordRespResult object.""" + """Return a `str` version of this BatchDnsRecordsRequestDeletesItem object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'DeleteDnsrecordRespResult') -> bool: + def __eq__(self, other: 'BatchDnsRecordsRequestDeletesItem') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'DeleteDnsrecordRespResult') -> bool: + def __ne__(self, other: 'BatchDnsRecordsRequestDeletesItem') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class DeleteDnsrecordResp(): - """ - dns record delete response. - :attr bool success: success response. - :attr List[List[str]] errors: errors. - :attr List[List[str]] messages: messages. - :attr DeleteDnsrecordRespResult result: result. +class BatchDnsRecordsRequestPatchesItem: + """ + BatchDnsRecordsRequestPatchesItem. + + :param str id: DNS record ID to patch. + :param str name: (optional) Required for all record types except SRV. + :param str type: (optional) dns record type. + :param int ttl: (optional) dns record ttl value. + :param str content: (optional) content of dns record. + :param int priority: (optional) For MX records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. """ - def __init__(self, - success: bool, - errors: List[List[str]], - messages: List[List[str]], - result: 'DeleteDnsrecordRespResult') -> None: + def __init__( + self, + id: str, + *, + name: Optional[str] = None, + type: Optional[str] = None, + ttl: Optional[int] = None, + content: Optional[str] = None, + priority: Optional[int] = None, + proxied: Optional[bool] = None, + data: Optional[dict] = None, + ) -> None: """ - Initialize a DeleteDnsrecordResp object. + Initialize a BatchDnsRecordsRequestPatchesItem object. - :param bool success: success response. - :param List[List[str]] errors: errors. - :param List[List[str]] messages: messages. - :param DeleteDnsrecordRespResult result: result. + :param str id: DNS record ID to patch. + :param str name: (optional) Required for all record types except SRV. + :param str type: (optional) dns record type. + :param int ttl: (optional) dns record ttl value. + :param str content: (optional) content of dns record. + :param int priority: (optional) For MX records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. """ - self.success = success - self.errors = errors - self.messages = messages - self.result = result + self.id = id + self.name = name + self.type = type + self.ttl = ttl + self.content = content + self.priority = priority + self.proxied = proxied + self.data = data @classmethod - def from_dict(cls, _dict: Dict) -> 'DeleteDnsrecordResp': - """Initialize a DeleteDnsrecordResp object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordsRequestPatchesItem': + """Initialize a BatchDnsRecordsRequestPatchesItem object from a json dictionary.""" args = {} - if 'success' in _dict: - args['success'] = _dict.get('success') - else: - raise ValueError('Required property \'success\' not present in DeleteDnsrecordResp JSON') - if 'errors' in _dict: - args['errors'] = _dict.get('errors') - else: - raise ValueError('Required property \'errors\' not present in DeleteDnsrecordResp JSON') - if 'messages' in _dict: - args['messages'] = _dict.get('messages') - else: - raise ValueError('Required property \'messages\' not present in DeleteDnsrecordResp JSON') - if 'result' in _dict: - args['result'] = DeleteDnsrecordRespResult.from_dict(_dict.get('result')) + if (id := _dict.get('id')) is not None: + args['id'] = id else: - raise ValueError('Required property \'result\' not present in DeleteDnsrecordResp JSON') + raise ValueError('Required property \'id\' not present in BatchDnsRecordsRequestPatchesItem JSON') + if (name := _dict.get('name')) is not None: + args['name'] = name + if (type := _dict.get('type')) is not None: + args['type'] = type + if (ttl := _dict.get('ttl')) is not None: + args['ttl'] = ttl + if (content := _dict.get('content')) is not None: + args['content'] = content + if (priority := _dict.get('priority')) is not None: + args['priority'] = priority + if (proxied := _dict.get('proxied')) is not None: + args['proxied'] = proxied + if (data := _dict.get('data')) is not None: + args['data'] = data return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a DeleteDnsrecordResp object from a json dictionary.""" + """Initialize a BatchDnsRecordsRequestPatchesItem object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'success') and self.success is not None: - _dict['success'] = self.success - if hasattr(self, 'errors') and self.errors is not None: - _dict['errors'] = self.errors - if hasattr(self, 'messages') and self.messages is not None: - _dict['messages'] = self.messages - if hasattr(self, 'result') and self.result is not None: - _dict['result'] = self.result.to_dict() + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'ttl') and self.ttl is not None: + _dict['ttl'] = self.ttl + if hasattr(self, 'content') and self.content is not None: + _dict['content'] = self.content + if hasattr(self, 'priority') and self.priority is not None: + _dict['priority'] = self.priority + if hasattr(self, 'proxied') and self.proxied is not None: + _dict['proxied'] = self.proxied + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data return _dict def _to_dict(self): @@ -513,121 +672,120 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this DeleteDnsrecordResp object.""" + """Return a `str` version of this BatchDnsRecordsRequestPatchesItem object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'DeleteDnsrecordResp') -> bool: + def __eq__(self, other: 'BatchDnsRecordsRequestPatchesItem') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'DeleteDnsrecordResp') -> bool: + def __ne__(self, other: 'BatchDnsRecordsRequestPatchesItem') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class DnsrecordDetails(): - """ - dns record details. + class TypeEnum(str, Enum): + """ + dns record type. + """ + + A = 'A' + AAAA = 'AAAA' + CNAME = 'CNAME' + NS = 'NS' + MX = 'MX' + TXT = 'TXT' + LOC = 'LOC' + SRV = 'SRV' + PTR = 'PTR' + CAA = 'CAA' + DS = 'DS' + - :attr str id: (optional) dns record identifier. - :attr str created_on: (optional) created on. - :attr str modified_on: (optional) modified date. - :attr str name: (optional) dns record name. - :attr str type: (optional) dns record type. - :attr str content: (optional) dns record content. - :attr str zone_id: (optional) zone identifier. - :attr str zone_name: (optional) zone name. - :attr bool proxiable: (optional) proxiable. - :attr bool proxied: (optional) proxied. - :attr int ttl: (optional) dns record ttl value. - :attr int priority: (optional) Relevant only to MX type records. - :attr object data: (optional) Data details for the DNS record. Only for LOC, - SRV, CAA records. + +class BatchDnsRecordsRequestPutsItem: + """ + BatchDnsRecordsRequestPutsItem. + + :param str id: DNS record ID to update. + :param str name: Required for all record types except SRV. + :param str type: dns record type. + :param int ttl: dns record ttl value. + :param str content: dns record content. + :param int priority: (optional) For MX records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. """ - def __init__(self, - *, - id: str = None, - created_on: str = None, - modified_on: str = None, - name: str = None, - type: str = None, - content: str = None, - zone_id: str = None, - zone_name: str = None, - proxiable: bool = None, - proxied: bool = None, - ttl: int = None, - priority: int = None, - data: object = None) -> None: + def __init__( + self, + id: str, + name: str, + type: str, + ttl: int, + content: str, + *, + priority: Optional[int] = None, + proxied: Optional[bool] = None, + data: Optional[dict] = None, + ) -> None: """ - Initialize a DnsrecordDetails object. + Initialize a BatchDnsRecordsRequestPutsItem object. - :param str id: (optional) dns record identifier. - :param str created_on: (optional) created on. - :param str modified_on: (optional) modified date. - :param str name: (optional) dns record name. - :param str type: (optional) dns record type. - :param str content: (optional) dns record content. - :param str zone_id: (optional) zone identifier. - :param str zone_name: (optional) zone name. - :param bool proxiable: (optional) proxiable. + :param str id: DNS record ID to update. + :param str name: Required for all record types except SRV. + :param str type: dns record type. + :param int ttl: dns record ttl value. + :param str content: dns record content. + :param int priority: (optional) For MX records only. :param bool proxied: (optional) proxied. - :param int ttl: (optional) dns record ttl value. - :param int priority: (optional) Relevant only to MX type records. - :param object data: (optional) Data details for the DNS record. Only for - LOC, SRV, CAA records. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. """ self.id = id - self.created_on = created_on - self.modified_on = modified_on self.name = name self.type = type - self.content = content - self.zone_id = zone_id - self.zone_name = zone_name - self.proxiable = proxiable - self.proxied = proxied self.ttl = ttl + self.content = content self.priority = priority + self.proxied = proxied self.data = data @classmethod - def from_dict(cls, _dict: Dict) -> 'DnsrecordDetails': - """Initialize a DnsrecordDetails object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordsRequestPutsItem': + """Initialize a BatchDnsRecordsRequestPutsItem object from a json dictionary.""" args = {} - if 'id' in _dict: - args['id'] = _dict.get('id') - if 'created_on' in _dict: - args['created_on'] = _dict.get('created_on') - if 'modified_on' in _dict: - args['modified_on'] = _dict.get('modified_on') - if 'name' in _dict: - args['name'] = _dict.get('name') - if 'type' in _dict: - args['type'] = _dict.get('type') - if 'content' in _dict: - args['content'] = _dict.get('content') - if 'zone_id' in _dict: - args['zone_id'] = _dict.get('zone_id') - if 'zone_name' in _dict: - args['zone_name'] = _dict.get('zone_name') - if 'proxiable' in _dict: - args['proxiable'] = _dict.get('proxiable') - if 'proxied' in _dict: - args['proxied'] = _dict.get('proxied') - if 'ttl' in _dict: - args['ttl'] = _dict.get('ttl') - if 'priority' in _dict: - args['priority'] = _dict.get('priority') - if 'data' in _dict: - args['data'] = _dict.get('data') + if (id := _dict.get('id')) is not None: + args['id'] = id + else: + raise ValueError('Required property \'id\' not present in BatchDnsRecordsRequestPutsItem JSON') + if (name := _dict.get('name')) is not None: + args['name'] = name + else: + raise ValueError('Required property \'name\' not present in BatchDnsRecordsRequestPutsItem JSON') + if (type := _dict.get('type')) is not None: + args['type'] = type + else: + raise ValueError('Required property \'type\' not present in BatchDnsRecordsRequestPutsItem JSON') + if (ttl := _dict.get('ttl')) is not None: + args['ttl'] = ttl + else: + raise ValueError('Required property \'ttl\' not present in BatchDnsRecordsRequestPutsItem JSON') + if (content := _dict.get('content')) is not None: + args['content'] = content + else: + raise ValueError('Required property \'content\' not present in BatchDnsRecordsRequestPutsItem JSON') + if (priority := _dict.get('priority')) is not None: + args['priority'] = priority + if (proxied := _dict.get('proxied')) is not None: + args['proxied'] = proxied + if (data := _dict.get('data')) is not None: + args['data'] = data return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a DnsrecordDetails object from a json dictionary.""" + """Initialize a BatchDnsRecordsRequestPutsItem object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: @@ -635,28 +793,18 @@ def to_dict(self) -> Dict: _dict = {} if hasattr(self, 'id') and self.id is not None: _dict['id'] = self.id - if hasattr(self, 'created_on') and self.created_on is not None: - _dict['created_on'] = self.created_on - if hasattr(self, 'modified_on') and self.modified_on is not None: - _dict['modified_on'] = self.modified_on if hasattr(self, 'name') and self.name is not None: _dict['name'] = self.name if hasattr(self, 'type') and self.type is not None: _dict['type'] = self.type - if hasattr(self, 'content') and self.content is not None: - _dict['content'] = self.content - if hasattr(self, 'zone_id') and self.zone_id is not None: - _dict['zone_id'] = self.zone_id - if hasattr(self, 'zone_name') and self.zone_name is not None: - _dict['zone_name'] = self.zone_name - if hasattr(self, 'proxiable') and self.proxiable is not None: - _dict['proxiable'] = self.proxiable - if hasattr(self, 'proxied') and self.proxied is not None: - _dict['proxied'] = self.proxied if hasattr(self, 'ttl') and self.ttl is not None: _dict['ttl'] = self.ttl + if hasattr(self, 'content') and self.content is not None: + _dict['content'] = self.content if hasattr(self, 'priority') and self.priority is not None: _dict['priority'] = self.priority + if hasattr(self, 'proxied') and self.proxied is not None: + _dict['proxied'] = self.proxied if hasattr(self, 'data') and self.data is not None: _dict['data'] = self.data return _dict @@ -666,16 +814,16 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this DnsrecordDetails object.""" + """Return a `str` version of this BatchDnsRecordsRequestPutsItem object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'DnsrecordDetails') -> bool: + def __eq__(self, other: 'BatchDnsRecordsRequestPutsItem') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'DnsrecordDetails') -> bool: + def __ne__(self, other: 'BatchDnsRecordsRequestPutsItem') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other @@ -683,6 +831,7 @@ class TypeEnum(str, Enum): """ dns record type. """ + A = 'A' AAAA = 'AAAA' CNAME = 'CNAME' @@ -691,76 +840,97 @@ class TypeEnum(str, Enum): TXT = 'TXT' LOC = 'LOC' SRV = 'SRV' - SPF = 'SPF' + PTR = 'PTR' CAA = 'CAA' + DS = 'DS' + -class DnsrecordResp(): +class BatchDnsRecordsResponseResult: """ - dns record response. + BatchDnsRecordsResponseResult. - :attr bool success: success response. - :attr List[List[str]] errors: errors. - :attr List[List[str]] messages: messages. - :attr DnsrecordDetails result: dns record details. + :param List[BatchDnsRecordDetails] deletes: (optional) + :param List[BatchDnsRecordDetails] patches: (optional) + :param List[BatchDnsRecordDetails] posts: (optional) + :param List[BatchDnsRecordDetails] puts: (optional) """ - def __init__(self, - success: bool, - errors: List[List[str]], - messages: List[List[str]], - result: 'DnsrecordDetails') -> None: + def __init__( + self, + *, + deletes: Optional[List['BatchDnsRecordDetails']] = None, + patches: Optional[List['BatchDnsRecordDetails']] = None, + posts: Optional[List['BatchDnsRecordDetails']] = None, + puts: Optional[List['BatchDnsRecordDetails']] = None, + ) -> None: """ - Initialize a DnsrecordResp object. + Initialize a BatchDnsRecordsResponseResult object. - :param bool success: success response. - :param List[List[str]] errors: errors. - :param List[List[str]] messages: messages. - :param DnsrecordDetails result: dns record details. + :param List[BatchDnsRecordDetails] deletes: (optional) + :param List[BatchDnsRecordDetails] patches: (optional) + :param List[BatchDnsRecordDetails] posts: (optional) + :param List[BatchDnsRecordDetails] puts: (optional) """ - self.success = success - self.errors = errors - self.messages = messages - self.result = result + self.deletes = deletes + self.patches = patches + self.posts = posts + self.puts = puts @classmethod - def from_dict(cls, _dict: Dict) -> 'DnsrecordResp': - """Initialize a DnsrecordResp object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordsResponseResult': + """Initialize a BatchDnsRecordsResponseResult object from a json dictionary.""" args = {} - if 'success' in _dict: - args['success'] = _dict.get('success') - else: - raise ValueError('Required property \'success\' not present in DnsrecordResp JSON') - if 'errors' in _dict: - args['errors'] = _dict.get('errors') - else: - raise ValueError('Required property \'errors\' not present in DnsrecordResp JSON') - if 'messages' in _dict: - args['messages'] = _dict.get('messages') - else: - raise ValueError('Required property \'messages\' not present in DnsrecordResp JSON') - if 'result' in _dict: - args['result'] = DnsrecordDetails.from_dict(_dict.get('result')) - else: - raise ValueError('Required property \'result\' not present in DnsrecordResp JSON') + if (deletes := _dict.get('deletes')) is not None: + args['deletes'] = [BatchDnsRecordDetails.from_dict(v) for v in deletes] + if (patches := _dict.get('patches')) is not None: + args['patches'] = [BatchDnsRecordDetails.from_dict(v) for v in patches] + if (posts := _dict.get('posts')) is not None: + args['posts'] = [BatchDnsRecordDetails.from_dict(v) for v in posts] + if (puts := _dict.get('puts')) is not None: + args['puts'] = [BatchDnsRecordDetails.from_dict(v) for v in puts] return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a DnsrecordResp object from a json dictionary.""" + """Initialize a BatchDnsRecordsResponseResult object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'success') and self.success is not None: - _dict['success'] = self.success - if hasattr(self, 'errors') and self.errors is not None: - _dict['errors'] = self.errors - if hasattr(self, 'messages') and self.messages is not None: - _dict['messages'] = self.messages - if hasattr(self, 'result') and self.result is not None: - _dict['result'] = self.result.to_dict() + if hasattr(self, 'deletes') and self.deletes is not None: + deletes_list = [] + for v in self.deletes: + if isinstance(v, dict): + deletes_list.append(v) + else: + deletes_list.append(v.to_dict()) + _dict['deletes'] = deletes_list + if hasattr(self, 'patches') and self.patches is not None: + patches_list = [] + for v in self.patches: + if isinstance(v, dict): + patches_list.append(v) + else: + patches_list.append(v.to_dict()) + _dict['patches'] = patches_list + if hasattr(self, 'posts') and self.posts is not None: + posts_list = [] + for v in self.posts: + if isinstance(v, dict): + posts_list.append(v) + else: + posts_list.append(v.to_dict()) + _dict['posts'] = posts_list + if hasattr(self, 'puts') and self.puts is not None: + puts_list = [] + for v in self.puts: + if isinstance(v, dict): + puts_list.append(v) + else: + puts_list.append(v.to_dict()) + _dict['puts'] = puts_list return _dict def _to_dict(self): @@ -768,95 +938,932 @@ def _to_dict(self): return self.to_dict() def __str__(self) -> str: - """Return a `str` version of this DnsrecordResp object.""" + """Return a `str` version of this BatchDnsRecordsResponseResult object.""" return json.dumps(self.to_dict(), indent=2) - def __eq__(self, other: 'DnsrecordResp') -> bool: + def __eq__(self, other: 'BatchDnsRecordsResponseResult') -> bool: """Return `true` when self and other are equal, false otherwise.""" if not isinstance(other, self.__class__): return False return self.__dict__ == other.__dict__ - def __ne__(self, other: 'DnsrecordResp') -> bool: + def __ne__(self, other: 'BatchDnsRecordsResponseResult') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class ListDnsrecordsResp(): + +class DeleteDnsrecordRespResult: """ - dns records list response. + result. - :attr bool success: success response. - :attr List[List[str]] errors: errors. - :attr List[List[str]] messages: messages. - :attr List[DnsrecordDetails] result: dns record list. - :attr ResultInfo result_info: result information. + :param str id: dns record id. """ - def __init__(self, - success: bool, - errors: List[List[str]], - messages: List[List[str]], - result: List['DnsrecordDetails'], - result_info: 'ResultInfo') -> None: + def __init__( + self, + id: str, + ) -> None: """ - Initialize a ListDnsrecordsResp object. + Initialize a DeleteDnsrecordRespResult object. - :param bool success: success response. - :param List[List[str]] errors: errors. - :param List[List[str]] messages: messages. - :param List[DnsrecordDetails] result: dns record list. - :param ResultInfo result_info: result information. + :param str id: dns record id. """ - self.success = success - self.errors = errors - self.messages = messages - self.result = result - self.result_info = result_info + self.id = id @classmethod - def from_dict(cls, _dict: Dict) -> 'ListDnsrecordsResp': - """Initialize a ListDnsrecordsResp object from a json dictionary.""" + def from_dict(cls, _dict: Dict) -> 'DeleteDnsrecordRespResult': + """Initialize a DeleteDnsrecordRespResult object from a json dictionary.""" args = {} - if 'success' in _dict: - args['success'] = _dict.get('success') - else: - raise ValueError('Required property \'success\' not present in ListDnsrecordsResp JSON') - if 'errors' in _dict: - args['errors'] = _dict.get('errors') - else: - raise ValueError('Required property \'errors\' not present in ListDnsrecordsResp JSON') - if 'messages' in _dict: - args['messages'] = _dict.get('messages') - else: - raise ValueError('Required property \'messages\' not present in ListDnsrecordsResp JSON') - if 'result' in _dict: - args['result'] = [DnsrecordDetails.from_dict(x) for x in _dict.get('result')] - else: - raise ValueError('Required property \'result\' not present in ListDnsrecordsResp JSON') - if 'result_info' in _dict: - args['result_info'] = ResultInfo.from_dict(_dict.get('result_info')) + if (id := _dict.get('id')) is not None: + args['id'] = id else: - raise ValueError('Required property \'result_info\' not present in ListDnsrecordsResp JSON') + raise ValueError('Required property \'id\' not present in DeleteDnsrecordRespResult JSON') return cls(**args) @classmethod def _from_dict(cls, _dict): - """Initialize a ListDnsrecordsResp object from a json dictionary.""" + """Initialize a DeleteDnsrecordRespResult object from a json dictionary.""" return cls.from_dict(_dict) def to_dict(self) -> Dict: """Return a json dictionary representing this model.""" _dict = {} - if hasattr(self, 'success') and self.success is not None: + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DeleteDnsrecordRespResult object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteDnsrecordRespResult') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DeleteDnsrecordRespResult') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class BatchDnsRecordDetails: + """ + dns record details as returned by the batch API. + + :param str id: (optional) dns record identifier. + :param str created_on: (optional) created on. + :param str modified_on: (optional) modified date. + :param str name: (optional) dns record name. + :param str type: (optional) dns record type. + :param str content: (optional) dns record content. + :param bool proxiable: (optional) proxiable. + :param bool proxied: (optional) proxied. + :param int ttl: (optional) dns record ttl value. + :param int priority: (optional) Relevant only to MX type records. + :param dict data: (optional) Data details for the DNS record. Only for LOC, SRV, + CAA records. + :param dict settings: (optional) DNS record settings. + :param dict meta: (optional) DNS record metadata. + :param str comment: (optional) Optional comment for the DNS record. + :param List[str] tags: (optional) Tags associated with the DNS record. + """ + + def __init__( + self, + *, + id: Optional[str] = None, + created_on: Optional[str] = None, + modified_on: Optional[str] = None, + name: Optional[str] = None, + type: Optional[str] = None, + content: Optional[str] = None, + proxiable: Optional[bool] = None, + proxied: Optional[bool] = None, + ttl: Optional[int] = None, + priority: Optional[int] = None, + data: Optional[dict] = None, + settings: Optional[dict] = None, + meta: Optional[dict] = None, + comment: Optional[str] = None, + tags: Optional[List[str]] = None, + ) -> None: + """ + Initialize a BatchDnsRecordDetails object. + + :param str id: (optional) dns record identifier. + :param str created_on: (optional) created on. + :param str modified_on: (optional) modified date. + :param str name: (optional) dns record name. + :param str type: (optional) dns record type. + :param str content: (optional) dns record content. + :param bool proxiable: (optional) proxiable. + :param bool proxied: (optional) proxied. + :param int ttl: (optional) dns record ttl value. + :param int priority: (optional) Relevant only to MX type records. + :param dict data: (optional) Data details for the DNS record. Only for LOC, + SRV, CAA records. + :param dict settings: (optional) DNS record settings. + :param dict meta: (optional) DNS record metadata. + :param str comment: (optional) Optional comment for the DNS record. + :param List[str] tags: (optional) Tags associated with the DNS record. + """ + self.id = id + self.created_on = created_on + self.modified_on = modified_on + self.name = name + self.type = type + self.content = content + self.proxiable = proxiable + self.proxied = proxied + self.ttl = ttl + self.priority = priority + self.data = data + self.settings = settings + self.meta = meta + self.comment = comment + self.tags = tags + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordDetails': + """Initialize a BatchDnsRecordDetails object from a json dictionary.""" + args = {} + if (id := _dict.get('id')) is not None: + args['id'] = id + if (created_on := _dict.get('created_on')) is not None: + args['created_on'] = created_on + if (modified_on := _dict.get('modified_on')) is not None: + args['modified_on'] = modified_on + if (name := _dict.get('name')) is not None: + args['name'] = name + if (type := _dict.get('type')) is not None: + args['type'] = type + if (content := _dict.get('content')) is not None: + args['content'] = content + if (proxiable := _dict.get('proxiable')) is not None: + args['proxiable'] = proxiable + if (proxied := _dict.get('proxied')) is not None: + args['proxied'] = proxied + if (ttl := _dict.get('ttl')) is not None: + args['ttl'] = ttl + if (priority := _dict.get('priority')) is not None: + args['priority'] = priority + if (data := _dict.get('data')) is not None: + args['data'] = data + if (settings := _dict.get('settings')) is not None: + args['settings'] = settings + if (meta := _dict.get('meta')) is not None: + args['meta'] = meta + if (comment := _dict.get('comment')) is not None: + args['comment'] = comment + if (tags := _dict.get('tags')) is not None: + args['tags'] = tags + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BatchDnsRecordDetails object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'created_on') and self.created_on is not None: + _dict['created_on'] = self.created_on + if hasattr(self, 'modified_on') and self.modified_on is not None: + _dict['modified_on'] = self.modified_on + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'content') and self.content is not None: + _dict['content'] = self.content + if hasattr(self, 'proxiable') and self.proxiable is not None: + _dict['proxiable'] = self.proxiable + if hasattr(self, 'proxied') and self.proxied is not None: + _dict['proxied'] = self.proxied + if hasattr(self, 'ttl') and self.ttl is not None: + _dict['ttl'] = self.ttl + if hasattr(self, 'priority') and self.priority is not None: + _dict['priority'] = self.priority + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data + if hasattr(self, 'settings') and self.settings is not None: + _dict['settings'] = self.settings + if hasattr(self, 'meta') and self.meta is not None: + _dict['meta'] = self.meta + if hasattr(self, 'comment') and self.comment is not None: + _dict['comment'] = self.comment + if hasattr(self, 'tags') and self.tags is not None: + _dict['tags'] = self.tags + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BatchDnsRecordDetails object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BatchDnsRecordDetails') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BatchDnsRecordDetails') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + dns record type. + """ + + A = 'A' + AAAA = 'AAAA' + CNAME = 'CNAME' + NS = 'NS' + MX = 'MX' + TXT = 'TXT' + LOC = 'LOC' + SRV = 'SRV' + PTR = 'PTR' + CAA = 'CAA' + DS = 'DS' + + + +class BatchDnsRecordsResponse: + """ + Batch DNS records response. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param BatchDnsRecordsResponseResult result: + """ + + def __init__( + self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'BatchDnsRecordsResponseResult', + ) -> None: + """ + Initialize a BatchDnsRecordsResponse object. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param BatchDnsRecordsResponseResult result: + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'BatchDnsRecordsResponse': + """Initialize a BatchDnsRecordsResponse object from a json dictionary.""" + args = {} + if (success := _dict.get('success')) is not None: + args['success'] = success + else: + raise ValueError('Required property \'success\' not present in BatchDnsRecordsResponse JSON') + if (errors := _dict.get('errors')) is not None: + args['errors'] = errors + else: + raise ValueError('Required property \'errors\' not present in BatchDnsRecordsResponse JSON') + if (messages := _dict.get('messages')) is not None: + args['messages'] = messages + else: + raise ValueError('Required property \'messages\' not present in BatchDnsRecordsResponse JSON') + if (result := _dict.get('result')) is not None: + args['result'] = BatchDnsRecordsResponseResult.from_dict(result) + else: + raise ValueError('Required property \'result\' not present in BatchDnsRecordsResponse JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a BatchDnsRecordsResponse object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'success') and self.success is not None: + _dict['success'] = self.success + if hasattr(self, 'errors') and self.errors is not None: + _dict['errors'] = self.errors + if hasattr(self, 'messages') and self.messages is not None: + _dict['messages'] = self.messages + if hasattr(self, 'result') and self.result is not None: + if isinstance(self.result, dict): + _dict['result'] = self.result + else: + _dict['result'] = self.result.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this BatchDnsRecordsResponse object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'BatchDnsRecordsResponse') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'BatchDnsRecordsResponse') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class DeleteDnsrecordResp: + """ + dns record delete response. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param DeleteDnsrecordRespResult result: result. + """ + + def __init__( + self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'DeleteDnsrecordRespResult', + ) -> None: + """ + Initialize a DeleteDnsrecordResp object. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param DeleteDnsrecordRespResult result: result. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteDnsrecordResp': + """Initialize a DeleteDnsrecordResp object from a json dictionary.""" + args = {} + if (success := _dict.get('success')) is not None: + args['success'] = success + else: + raise ValueError('Required property \'success\' not present in DeleteDnsrecordResp JSON') + if (errors := _dict.get('errors')) is not None: + args['errors'] = errors + else: + raise ValueError('Required property \'errors\' not present in DeleteDnsrecordResp JSON') + if (messages := _dict.get('messages')) is not None: + args['messages'] = messages + else: + raise ValueError('Required property \'messages\' not present in DeleteDnsrecordResp JSON') + if (result := _dict.get('result')) is not None: + args['result'] = DeleteDnsrecordRespResult.from_dict(result) + else: + raise ValueError('Required property \'result\' not present in DeleteDnsrecordResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteDnsrecordResp object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'success') and self.success is not None: + _dict['success'] = self.success + if hasattr(self, 'errors') and self.errors is not None: + _dict['errors'] = self.errors + if hasattr(self, 'messages') and self.messages is not None: + _dict['messages'] = self.messages + if hasattr(self, 'result') and self.result is not None: + if isinstance(self.result, dict): + _dict['result'] = self.result + else: + _dict['result'] = self.result.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DeleteDnsrecordResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteDnsrecordResp') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DeleteDnsrecordResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class DnsrecordDetails: + """ + dns record details. + + :param str id: (optional) dns record identifier. + :param str created_on: (optional) created on. + :param str modified_on: (optional) modified date. + :param str name: (optional) dns record name. + :param str type: (optional) dns record type. + :param str content: (optional) dns record content. + :param str zone_id: (optional) zone identifier. + :param str zone_name: (optional) zone name. + :param bool proxiable: (optional) proxiable. + :param bool proxied: (optional) proxied. + :param int ttl: (optional) dns record ttl value. + :param int priority: (optional) Relevant only to MX type records. + :param dict data: (optional) Data details for the DNS record. Only for LOC, SRV, + CAA records. + """ + + def __init__( + self, + *, + id: Optional[str] = None, + created_on: Optional[str] = None, + modified_on: Optional[str] = None, + name: Optional[str] = None, + type: Optional[str] = None, + content: Optional[str] = None, + zone_id: Optional[str] = None, + zone_name: Optional[str] = None, + proxiable: Optional[bool] = None, + proxied: Optional[bool] = None, + ttl: Optional[int] = None, + priority: Optional[int] = None, + data: Optional[dict] = None, + ) -> None: + """ + Initialize a DnsrecordDetails object. + + :param str id: (optional) dns record identifier. + :param str created_on: (optional) created on. + :param str modified_on: (optional) modified date. + :param str name: (optional) dns record name. + :param str type: (optional) dns record type. + :param str content: (optional) dns record content. + :param str zone_id: (optional) zone identifier. + :param str zone_name: (optional) zone name. + :param bool proxiable: (optional) proxiable. + :param bool proxied: (optional) proxied. + :param int ttl: (optional) dns record ttl value. + :param int priority: (optional) Relevant only to MX type records. + :param dict data: (optional) Data details for the DNS record. Only for LOC, + SRV, CAA records. + """ + self.id = id + self.created_on = created_on + self.modified_on = modified_on + self.name = name + self.type = type + self.content = content + self.zone_id = zone_id + self.zone_name = zone_name + self.proxiable = proxiable + self.proxied = proxied + self.ttl = ttl + self.priority = priority + self.data = data + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DnsrecordDetails': + """Initialize a DnsrecordDetails object from a json dictionary.""" + args = {} + if (id := _dict.get('id')) is not None: + args['id'] = id + if (created_on := _dict.get('created_on')) is not None: + args['created_on'] = created_on + if (modified_on := _dict.get('modified_on')) is not None: + args['modified_on'] = modified_on + if (name := _dict.get('name')) is not None: + args['name'] = name + if (type := _dict.get('type')) is not None: + args['type'] = type + if (content := _dict.get('content')) is not None: + args['content'] = content + if (zone_id := _dict.get('zone_id')) is not None: + args['zone_id'] = zone_id + if (zone_name := _dict.get('zone_name')) is not None: + args['zone_name'] = zone_name + if (proxiable := _dict.get('proxiable')) is not None: + args['proxiable'] = proxiable + if (proxied := _dict.get('proxied')) is not None: + args['proxied'] = proxied + if (ttl := _dict.get('ttl')) is not None: + args['ttl'] = ttl + if (priority := _dict.get('priority')) is not None: + args['priority'] = priority + if (data := _dict.get('data')) is not None: + args['data'] = data + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DnsrecordDetails object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'id') and self.id is not None: + _dict['id'] = self.id + if hasattr(self, 'created_on') and self.created_on is not None: + _dict['created_on'] = self.created_on + if hasattr(self, 'modified_on') and self.modified_on is not None: + _dict['modified_on'] = self.modified_on + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'content') and self.content is not None: + _dict['content'] = self.content + if hasattr(self, 'zone_id') and self.zone_id is not None: + _dict['zone_id'] = self.zone_id + if hasattr(self, 'zone_name') and self.zone_name is not None: + _dict['zone_name'] = self.zone_name + if hasattr(self, 'proxiable') and self.proxiable is not None: + _dict['proxiable'] = self.proxiable + if hasattr(self, 'proxied') and self.proxied is not None: + _dict['proxied'] = self.proxied + if hasattr(self, 'ttl') and self.ttl is not None: + _dict['ttl'] = self.ttl + if hasattr(self, 'priority') and self.priority is not None: + _dict['priority'] = self.priority + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DnsrecordDetails object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DnsrecordDetails') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DnsrecordDetails') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + dns record type. + """ + + A = 'A' + AAAA = 'AAAA' + CNAME = 'CNAME' + NS = 'NS' + MX = 'MX' + TXT = 'TXT' + LOC = 'LOC' + SRV = 'SRV' + PTR = 'PTR' + CAA = 'CAA' + DS = 'DS' + + + +class DnsrecordInput: + """ + dns record input. + + :param str name: (optional) Required for all record types except SRV. + :param str type: dns record type. + :param int ttl: (optional) dns record ttl value. + :param str content: (optional) dns record content. + :param int priority: (optional) For MX records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. + """ + + def __init__( + self, + type: str, + *, + name: Optional[str] = None, + ttl: Optional[int] = None, + content: Optional[str] = None, + priority: Optional[int] = None, + proxied: Optional[bool] = None, + data: Optional[dict] = None, + ) -> None: + """ + Initialize a DnsrecordInput object. + + :param str type: dns record type. + :param str name: (optional) Required for all record types except SRV. + :param int ttl: (optional) dns record ttl value. + :param str content: (optional) dns record content. + :param int priority: (optional) For MX records only. + :param bool proxied: (optional) proxied. + :param dict data: (optional) For LOC, SRV, CAA, DS records only. + """ + self.name = name + self.type = type + self.ttl = ttl + self.content = content + self.priority = priority + self.proxied = proxied + self.data = data + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DnsrecordInput': + """Initialize a DnsrecordInput object from a json dictionary.""" + args = {} + if (name := _dict.get('name')) is not None: + args['name'] = name + if (type := _dict.get('type')) is not None: + args['type'] = type + else: + raise ValueError('Required property \'type\' not present in DnsrecordInput JSON') + if (ttl := _dict.get('ttl')) is not None: + args['ttl'] = ttl + if (content := _dict.get('content')) is not None: + args['content'] = content + if (priority := _dict.get('priority')) is not None: + args['priority'] = priority + if (proxied := _dict.get('proxied')) is not None: + args['proxied'] = proxied + if (data := _dict.get('data')) is not None: + args['data'] = data + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DnsrecordInput object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'name') and self.name is not None: + _dict['name'] = self.name + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'ttl') and self.ttl is not None: + _dict['ttl'] = self.ttl + if hasattr(self, 'content') and self.content is not None: + _dict['content'] = self.content + if hasattr(self, 'priority') and self.priority is not None: + _dict['priority'] = self.priority + if hasattr(self, 'proxied') and self.proxied is not None: + _dict['proxied'] = self.proxied + if hasattr(self, 'data') and self.data is not None: + _dict['data'] = self.data + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DnsrecordInput object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DnsrecordInput') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DnsrecordInput') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + dns record type. + """ + + A = 'A' + AAAA = 'AAAA' + CNAME = 'CNAME' + NS = 'NS' + MX = 'MX' + TXT = 'TXT' + LOC = 'LOC' + SRV = 'SRV' + PTR = 'PTR' + CAA = 'CAA' + DS = 'DS' + + + +class DnsrecordResp: + """ + dns record response. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param DnsrecordDetails result: dns record details. + """ + + def __init__( + self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'DnsrecordDetails', + ) -> None: + """ + Initialize a DnsrecordResp object. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param DnsrecordDetails result: dns record details. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DnsrecordResp': + """Initialize a DnsrecordResp object from a json dictionary.""" + args = {} + if (success := _dict.get('success')) is not None: + args['success'] = success + else: + raise ValueError('Required property \'success\' not present in DnsrecordResp JSON') + if (errors := _dict.get('errors')) is not None: + args['errors'] = errors + else: + raise ValueError('Required property \'errors\' not present in DnsrecordResp JSON') + if (messages := _dict.get('messages')) is not None: + args['messages'] = messages + else: + raise ValueError('Required property \'messages\' not present in DnsrecordResp JSON') + if (result := _dict.get('result')) is not None: + args['result'] = DnsrecordDetails.from_dict(result) + else: + raise ValueError('Required property \'result\' not present in DnsrecordResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DnsrecordResp object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'success') and self.success is not None: + _dict['success'] = self.success + if hasattr(self, 'errors') and self.errors is not None: + _dict['errors'] = self.errors + if hasattr(self, 'messages') and self.messages is not None: + _dict['messages'] = self.messages + if hasattr(self, 'result') and self.result is not None: + if isinstance(self.result, dict): + _dict['result'] = self.result + else: + _dict['result'] = self.result.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DnsrecordResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DnsrecordResp') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DnsrecordResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class ListDnsrecordsResp: + """ + dns records list response. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param List[DnsrecordDetails] result: dns record list. + :param ResultInfo result_info: result information. + """ + + def __init__( + self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['DnsrecordDetails'], + result_info: 'ResultInfo', + ) -> None: + """ + Initialize a ListDnsrecordsResp object. + + :param bool success: success response. + :param List[List[str]] errors: errors. + :param List[List[str]] messages: messages. + :param List[DnsrecordDetails] result: dns record list. + :param ResultInfo result_info: result information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + self.result_info = result_info + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListDnsrecordsResp': + """Initialize a ListDnsrecordsResp object from a json dictionary.""" + args = {} + if (success := _dict.get('success')) is not None: + args['success'] = success + else: + raise ValueError('Required property \'success\' not present in ListDnsrecordsResp JSON') + if (errors := _dict.get('errors')) is not None: + args['errors'] = errors + else: + raise ValueError('Required property \'errors\' not present in ListDnsrecordsResp JSON') + if (messages := _dict.get('messages')) is not None: + args['messages'] = messages + else: + raise ValueError('Required property \'messages\' not present in ListDnsrecordsResp JSON') + if (result := _dict.get('result')) is not None: + args['result'] = [DnsrecordDetails.from_dict(v) for v in result] + else: + raise ValueError('Required property \'result\' not present in ListDnsrecordsResp JSON') + if (result_info := _dict.get('result_info')) is not None: + args['result_info'] = ResultInfo.from_dict(result_info) + else: + raise ValueError('Required property \'result_info\' not present in ListDnsrecordsResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListDnsrecordsResp object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'success') and self.success is not None: _dict['success'] = self.success if hasattr(self, 'errors') and self.errors is not None: _dict['errors'] = self.errors if hasattr(self, 'messages') and self.messages is not None: _dict['messages'] = self.messages if hasattr(self, 'result') and self.result is not None: - _dict['result'] = [x.to_dict() for x in self.result] + result_list = [] + for v in self.result: + if isinstance(v, dict): + result_list.append(v) + else: + result_list.append(v.to_dict()) + _dict['result'] = result_list if hasattr(self, 'result_info') and self.result_info is not None: - _dict['result_info'] = self.result_info.to_dict() + if isinstance(self.result_info, dict): + _dict['result_info'] = self.result_info + else: + _dict['result_info'] = self.result_info.to_dict() return _dict def _to_dict(self): @@ -877,21 +1884,24 @@ def __ne__(self, other: 'ListDnsrecordsResp') -> bool: """Return `true` when self and other are not equal, false otherwise.""" return not self == other -class ResultInfo(): + +class ResultInfo: """ result information. - :attr int page: page. - :attr int per_page: per page. - :attr int count: count. - :attr int total_count: total count. + :param int page: page. + :param int per_page: per page. + :param int count: count. + :param int total_count: total count. """ - def __init__(self, - page: int, - per_page: int, - count: int, - total_count: int) -> None: + def __init__( + self, + page: int, + per_page: int, + count: int, + total_count: int, + ) -> None: """ Initialize a ResultInfo object. @@ -909,20 +1919,20 @@ def __init__(self, def from_dict(cls, _dict: Dict) -> 'ResultInfo': """Initialize a ResultInfo object from a json dictionary.""" args = {} - if 'page' in _dict: - args['page'] = _dict.get('page') + if (page := _dict.get('page')) is not None: + args['page'] = page else: raise ValueError('Required property \'page\' not present in ResultInfo JSON') - if 'per_page' in _dict: - args['per_page'] = _dict.get('per_page') + if (per_page := _dict.get('per_page')) is not None: + args['per_page'] = per_page else: raise ValueError('Required property \'per_page\' not present in ResultInfo JSON') - if 'count' in _dict: - args['count'] = _dict.get('count') + if (count := _dict.get('count')) is not None: + args['count'] = count else: raise ValueError('Required property \'count\' not present in ResultInfo JSON') - if 'total_count' in _dict: - args['total_count'] = _dict.get('total_count') + if (total_count := _dict.get('total_count')) is not None: + args['total_count'] = total_count else: raise ValueError('Required property \'total_count\' not present in ResultInfo JSON') return cls(**args) diff --git a/test/integration/test_dns_records_v1.py b/test/integration/test_dns_records_v1.py index 46d7826..9a61775 100644 --- a/test/integration/test_dns_records_v1.py +++ b/test/integration/test_dns_records_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2020. +# (C) Copyright IBM Corp. 2026. """ Integration test code to execute dns record client functions @@ -8,7 +8,14 @@ import os import unittest from dotenv import load_dotenv, find_dotenv -from ibm_cloud_networking_services import DnsRecordsV1 +from ibm_cloud_sdk_core.authenticators import IAMAuthenticator +from ibm_cloud_networking_services.dns_records_v1 import ( + DnsRecordsV1, + BatchDnsRecordsRequestDeletesItem, + BatchDnsRecordsRequestPatchesItem, + BatchDnsRecordsRequestPutsItem, + DnsrecordInput, +) configFile = "cis.env" @@ -22,26 +29,38 @@ class TestDnsRecordV1(unittest.TestCase): """ Test class to call dns record sdk functions """ - @unittest.skip("skipping") - - def setUp(self): - """ test case setup """ + @classmethod + def setUpClass(cls): if not os.path.exists(configFile): raise unittest.SkipTest( 'External configuration not available, skipping...') - self.crn = os.getenv("CRN") - self.zone_id = os.getenv("ZONE_ID") - self.endpoint = os.getenv("API_ENDPOINT") - # create dns record class object - self.dns = DnsRecordsV1.new_instance( - crn=self.crn, zone_identifier=self.zone_id, service_name="cis_services") - self.dns.set_service_url(self.endpoint) - self._clean_dns_records() - def tearDown(self): - """ tear down """ - # Delete the resources - print("Clean up complete") + api_key = os.getenv("CIS_SERVICES_APIKEY") + auth_url = os.getenv("CIS_SERVICES_AUTH_URL") + crn = os.getenv("CRN") + zone_id = os.getenv("ZONE_ID") + service_url = os.getenv("API_ENDPOINT") + + if not all([api_key, crn, zone_id]): + raise unittest.SkipTest("Environment variables not set properly") + + authenticator = IAMAuthenticator(api_key, url=auth_url) + cls.dns = DnsRecordsV1( + authenticator=authenticator, + crn=crn, + zone_identifier=zone_id, + ) + if service_url: + cls.dns.set_service_url(service_url) + + cls.dns.enable_retries(max_retries=4, retry_interval=30) + + try: + cls.dns.list_all_dns_records() + except Exception as e: + raise unittest.SkipTest(f"Authentication failed: {e}") + + cls._clean_dns_records(cls) def _clean_dns_records(self): response = self.dns.list_all_dns_records() @@ -49,239 +68,281 @@ def _clean_dns_records(self): assert response.status_code == 200 resp = response.get_result().get("result") for record in resp: - if "example" in record.get("name"): + if "example" in record.get("name") or "ibm-example" in record.get("name"): self.dns.delete_dns_record( dnsrecord_identifier=record.get("id")) + def tearDown(self): + """ tear down """ + print("Clean up complete") + ################## list_all_dns_records ################### - def test_1_list_all_dns_records(self): - """ test for success """ - response = self.dns.list_all_dns_records().get_result() - assert response is not None and response.get('success') is True + def test_01_list_all_dns_records(self): + """ test list all dns records """ + response = self.dns.list_all_dns_records() + assert response is not None + assert response.status_code == 200 + result = response.get_result() + assert result.get('success') is True + + def test_02_list_all_dns_records_with_filters(self): + """ test list dns records with filter params """ + response = self.dns.list_all_dns_records( + type='A', + per_page=20, + page=1, + order='name', + direction='asc', + match='all', + ) + assert response is not None + assert response.status_code == 200 + + ################### A record ################################# - ################### dns record actions ############################ - def test_1_dns_record_actions(self): - """ test create/get/update/delete dns A record success """ - # create dns A records + def test_03_dns_record_a(self): + """ test create/get/update/delete dns A record """ record_type = 'A' - name = 'example_ip' + name = 'example-ip' content = '1.1.1.1' + + # create response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type=record_type, name=name, content=content, ttl=120) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns A record - response = self.dns.get_dns_record( - dnsrecord_identifier=record_id) + # get + response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns A records - content = '2.2.2.2' + # update response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type=record_type, name=name, content='2.2.2.2', ttl=240) assert response is not None assert response.status_code == 200 - # delete dns A records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + # delete + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_2_dns_record_actions(self): - """ test create/get/update/delete dns AAAA record success """ - # create dns AAAA records + ################### AAAA record ############################## + + def test_04_dns_record_aaaa(self): + """ test create/get/update/delete dns AAAA record """ record_type = 'AAAA' - name = 'example_ipv6' + name = 'example-ipv6' content = '2001::9' + response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type=record_type, name=name, content=content, ttl=120) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns AAAA record response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns AAAA records - content = '2002::10' response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type=record_type, name=name, content='2002::10', ttl=240) assert response is not None assert response.status_code == 200 - # delete dns AAAA records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_3_dns_record_actions(self): - """ test create/get/update/delete dns CNAME record success """ - # create dns CNAME records + ################### CNAME record ############################# + + def test_05_dns_record_cname(self): + """ test create/get/update/delete dns CNAME record """ record_type = 'CNAME' - name = 'example_alias' - content = 'ibm_alias.com' + name = 'example-alias' + content = 'ibm-alias.com' + response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type=record_type, name=name, content=content) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns CNAME record - response = self.dns.get_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns CNAME records - content = 'ibm_alias_1.com' response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type=record_type, name=name, content='ibm-alias-1.com') assert response is not None assert response.status_code == 200 - # delete dns CNAME records response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_4_dns_record_actions(self): - """ test create/get/update/delete dns MX record success """ - # create dns MX records + ################### MX record ################################ + + def test_06_dns_record_mx(self): + """ test create/get/update/delete dns MX record """ record_type = 'MX' - name = 'example_mail' + name = 'example-mail' content = 'mail.dummy.com' - priority = 3 + response = self.dns.create_dns_record( - type=record_type, - name=name, content=content, priority=priority) + type=record_type, name=name, content=content, priority=3) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns MX record response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns MX records - content = 'dummy_mail.ibm.com' - priority = 6 response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, name=name, content=content, priority=priority) + dnsrecord_identifier=record_id, + type=record_type, name=name, content='dummy-mail.ibm.com', priority=6) assert response is not None assert response.status_code == 200 - # delete dns MX records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_5_dns_record_actions(self): - """ test create/get/update/delete dns SPF record success """ - # create dns SPF records - record_type = 'SPF' - name = 'example_spf' - content = 'v=spf1 a mx -all' + ################### TXT record ################################ + + def test_07_dns_record_txt(self): + """ test create/get/update/delete dns TXT record """ + record_type = 'TXT' + name = 'ibm-example' + content = 'sample text' + response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type=record_type, name=name, content=content) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns SPF record response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns SPF records - content = 'v=spf4 a mx -all' response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type=record_type, name=name, content='sample text update') assert response is not None assert response.status_code == 200 - # delete dns SPF records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_6_dns_record_actions(self): - """ test create/get/update/delete dns TXT record success """ - # create dns TXT records - record_type = 'TXT' - name = 'ibm-example' - content = 'sample text' + ################### NS record ################################ + + def test_08_dns_record_ns(self): + """ test create/get/update/delete dns NS record """ + record_type = 'NS' + name = 'example-beta' + content = 'ns765.beta.com' + response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type=record_type, name=name, content=content) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] + record_id = response.get_result()["result"]["id"] - # get dns TXT record - response = self.dns.get_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.get_dns_record(dnsrecord_identifier=record_id) assert response.status_code == 200 - # update dns TXT records - content = 'sample text update' response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type=record_type, name='example-ns', content='ns765.name.com') assert response is not None assert response.status_code == 200 - # delete dns TXT records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) assert response is not None assert response.status_code == 200 - def test_7_dns_record_actions(self): - """ test create/get/update/delete dns NS record success """ - # create dns NS records - record_type = 'NS' - name = 'example_beta' - content = 'ns765.beta.com' + ################### proxied field ############################ + + def test_09_dns_record_proxied(self): + """ test create A record with proxied=True """ response = self.dns.create_dns_record( - type=record_type, - name=name, content=content) + type='A', name='example-proxied', content='3.3.3.3', proxied=True) assert response is not None assert response.status_code == 200 - record_id = response.get_result().get("result")["id"] - - # get dns NS record - response = self.dns.get_dns_record( - dnsrecord_identifier=record_id) - assert response.status_code == 200 + record_id = response.get_result()["result"]["id"] + assert response.get_result()["result"]["proxied"] is True - # update dns NS records - name = 'example-ns' - content = 'ns765.name.com' response = self.dns.update_dns_record( - dnsrecord_identifier=record_id, type=record_type, - name=name, content=content) + dnsrecord_identifier=record_id, + type='A', name='example-proxied', content='3.3.3.3', proxied=False) assert response is not None assert response.status_code == 200 - # delete dns NS records - response = self.dns.delete_dns_record( - dnsrecord_identifier=record_id) + response = self.dns.delete_dns_record(dnsrecord_identifier=record_id) + assert response.status_code == 200 + + ################### batch_dns_records ######################## + + def test_10_batch_dns_records_posts(self): + """ test batch dns records with posts (create) """ + posts = [ + DnsrecordInput(type='A', name='example-batch-a', content='10.0.0.1', ttl=120), + DnsrecordInput(type='AAAA', name='example-batch-aaaa', content='2003::1', ttl=120), + ] + response = self.dns.batch_dns_records(posts=posts) + assert response is not None + assert response.status_code == 200 + result = response.get_result() + assert result.get('success') is True + created = result["result"]["posts"] + assert len(created) == 2 + + # cleanup + for record in created: + self.dns.delete_dns_record(dnsrecord_identifier=record["id"]) + + def test_11_batch_dns_records_mixed(self): + """ test batch dns records with deletes, patches, puts, posts in one call """ + # pre-create two records to use in deletes/puts/patches + r1 = self.dns.create_dns_record( + type='A', name='example-batch-del', content='10.0.1.1', ttl=120) + assert r1.status_code == 200 + del_id = r1.get_result()["result"]["id"] + + r2 = self.dns.create_dns_record( + type='A', name='example-batch-patch', content='10.0.1.2', ttl=120) + assert r2.status_code == 200 + patch_id = r2.get_result()["result"]["id"] + + r3 = self.dns.create_dns_record( + type='A', name='example-batch-put', content='10.0.1.3', ttl=120) + assert r3.status_code == 200 + put_id = r3.get_result()["result"]["id"] + + deletes = [BatchDnsRecordsRequestDeletesItem(id=del_id)] + patches = [BatchDnsRecordsRequestPatchesItem(id=patch_id, content='10.0.1.22')] + puts = [BatchDnsRecordsRequestPutsItem( + id=put_id, name='example-batch-put', type='A', ttl=240, content='10.0.1.33')] + posts = [DnsrecordInput(type='TXT', name='example-batch-post', content='batchtest')] + + response = self.dns.batch_dns_records( + deletes=deletes, patches=patches, puts=puts, posts=posts) assert response is not None assert response.status_code == 200 + result = response.get_result() + assert result.get('success') is True + + # cleanup records created by puts/posts + for record in result["result"].get("puts", []): + self.dns.delete_dns_record(dnsrecord_identifier=record["id"]) + for record in result["result"].get("posts", []): + self.dns.delete_dns_record(dnsrecord_identifier=record["id"]) + # patch_id still exists, clean it up + self.dns.delete_dns_record(dnsrecord_identifier=patch_id) if __name__ == '__main__': diff --git a/test/unit/test_dns_records_v1.py b/test/unit/test_dns_records_v1.py index 88e759d..3c8f685 100644 --- a/test/unit/test_dns_records_v1.py +++ b/test/unit/test_dns_records_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2020. +# (C) Copyright IBM Corp. 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,70 +13,140 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Unit Tests for DnsRecordsV1 +""" + from ibm_cloud_sdk_core.authenticators.no_auth_authenticator import NoAuthAuthenticator import inspect import json +import os import pytest import re import requests import responses +import urllib from ibm_cloud_networking_services.dns_records_v1 import * crn = 'testString' zone_identifier = 'testString' -service = DnsRecordsV1( +_service = DnsRecordsV1( authenticator=NoAuthAuthenticator(), crn=crn, - zone_identifier=zone_identifier - ) + zone_identifier=zone_identifier, +) + +_base_url = 'https://api.cis.cloud.ibm.com' +_service.set_service_url(_base_url) + + +def preprocess_url(operation_path: str): + """ + Returns the request url associated with the specified operation path. + This will be base_url concatenated with a quoted version of operation_path. + The returned request URL is used to register the mock response so it needs + to match the request URL that is formed by the requests library. + """ + + # Form the request URL from the base URL and operation path. + request_url = _base_url + operation_path + + # If the request url does NOT end with a /, then just return it as-is. + # Otherwise, return a regular expression that matches one or more trailing /. + if not request_url.endswith('/'): + return request_url + return re.compile(request_url.rstrip('/') + '/+') -base_url = 'https://api.cis.cloud.ibm.com' -service.set_service_url(base_url) ############################################################################## # Start of Service: DNSRecords ############################################################################## # region -#----------------------------------------------------------------------------- -# Test Class for list_all_dns_records -#----------------------------------------------------------------------------- -class TestListAllDnsRecords(): - - # Preprocess the request URL to ensure the mock response will be found. - def preprocess_url(self, request_url: str): - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') - - #-------------------------------------------------------- - # list_all_dns_records() - #-------------------------------------------------------- + +class TestNewInstance: + """ + Test Class for new_instance + """ + + def test_new_instance(self): + """ + new_instance() + """ + os.environ['TEST_SERVICE_AUTH_TYPE'] = 'noAuth' + + service = DnsRecordsV1.new_instance( + crn=crn, + zone_identifier=zone_identifier, + service_name='TEST_SERVICE', + ) + + assert service is not None + assert isinstance(service, DnsRecordsV1) + + def test_new_instance_without_authenticator(self): + """ + new_instance_without_authenticator() + """ + with pytest.raises(ValueError, match='authenticator must be provided'): + service = DnsRecordsV1.new_instance( + crn=crn, + zone_identifier=zone_identifier, + service_name='TEST_SERVICE_NOT_FOUND', + ) + + def test_new_instance_without_required_params(self): + """ + new_instance_without_required_params() + """ + with pytest.raises(TypeError, match='new_instance\\(\\) missing \\d required positional arguments?: \'.*\''): + service = DnsRecordsV1.new_instance() + + def test_new_instance_required_param_none(self): + """ + new_instance_required_param_none() + """ + with pytest.raises(ValueError, match='crn must be provided must be provided'): + service = DnsRecordsV1.new_instance( + crn=None, + zone_identifier=None, + ) + + +class TestListAllDnsRecords: + """ + Test Class for list_all_dns_records + """ + @responses.activate def test_list_all_dns_records_all_params(self): + """ + list_all_dns_records() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}], "result_info": {"page": 1, "per_page": 20, "count": 1, "total_count": 2000}}' - responses.add(responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values type = 'testString' name = 'host1.test-example.com' content = '1.2.3.4' - page = 38 - per_page = 5 + page = 1 + per_page = 20 order = 'type' direction = 'asc' match = 'any' # Invoke method - response = service.list_all_dns_records( + response = _service.list_all_dns_records( type=type, name=name, content=content, @@ -85,15 +155,15 @@ def test_list_all_dns_records_all_params(self): order=order, direction=direction, match=match, - headers={} + headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 # Validate query params - query_string = responses.calls[0].request.url.split('?',1)[1] - query_string = requests.utils.unquote(query_string) + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) assert 'type={}'.format(type) in query_string assert 'name={}'.format(name) in query_string assert 'content={}'.format(content) in query_string @@ -103,95 +173,121 @@ def test_list_all_dns_records_all_params(self): assert 'direction={}'.format(direction) in query_string assert 'match={}'.format(match) in query_string + def test_list_all_dns_records_all_params_with_retries(self): + # Enable retries and run test_list_all_dns_records_all_params. + _service.enable_retries() + self.test_list_all_dns_records_all_params() + + # Disable retries and run test_list_all_dns_records_all_params. + _service.disable_retries() + self.test_list_all_dns_records_all_params() - #-------------------------------------------------------- - # test_list_all_dns_records_required_params() - #-------------------------------------------------------- @responses.activate def test_list_all_dns_records_required_params(self): + """ + test_list_all_dns_records_required_params() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}], "result_info": {"page": 1, "per_page": 20, "count": 1, "total_count": 2000}}' - responses.add(responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Invoke method - response = service.list_all_dns_records() - + response = _service.list_all_dns_records() # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + def test_list_all_dns_records_required_params_with_retries(self): + # Enable retries and run test_list_all_dns_records_required_params. + _service.enable_retries() + self.test_list_all_dns_records_required_params() + + # Disable retries and run test_list_all_dns_records_required_params. + _service.disable_retries() + self.test_list_all_dns_records_required_params() - #-------------------------------------------------------- - # test_list_all_dns_records_value_error() - #-------------------------------------------------------- @responses.activate def test_list_all_dns_records_value_error(self): + """ + test_list_all_dns_records_value_error() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}], "result_info": {"page": 1, "per_page": 20, "count": 1, "total_count": 2000}}' - responses.add(responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Pass in all but one required param and check for a ValueError req_param_dict = { } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - service.list_all_dns_records(**req_copy) + _service.list_all_dns_records(**req_copy) + def test_list_all_dns_records_value_error_with_retries(self): + # Enable retries and run test_list_all_dns_records_value_error. + _service.enable_retries() + self.test_list_all_dns_records_value_error() + # Disable retries and run test_list_all_dns_records_value_error. + _service.disable_retries() + self.test_list_all_dns_records_value_error() -#----------------------------------------------------------------------------- -# Test Class for create_dns_record -#----------------------------------------------------------------------------- -class TestCreateDnsRecord(): - # Preprocess the request URL to ensure the mock response will be found. - def preprocess_url(self, request_url: str): - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') +class TestCreateDnsRecord: + """ + Test Class for create_dns_record + """ - #-------------------------------------------------------- - # create_dns_record() - #-------------------------------------------------------- @responses.activate def test_create_dns_record_all_params(self): + """ + create_dns_record() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.POST, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values type = 'A' name = 'host-1.test-example.com' + ttl = 120 content = '1.2.3.4' priority = 5 - data = { 'foo': 'bar' } + proxied = False + data = {'anyKey': 'anyValue'} # Invoke method - response = service.create_dns_record( + response = _service.create_dns_record( type=type, name=name, + ttl=ttl, content=content, priority=priority, + proxied=proxied, data=data, - headers={} + headers={}, ) # Check for correct operation @@ -201,111 +297,145 @@ def test_create_dns_record_all_params(self): req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) assert req_body['type'] == 'A' assert req_body['name'] == 'host-1.test-example.com' + assert req_body['ttl'] == 120 assert req_body['content'] == '1.2.3.4' assert req_body['priority'] == 5 - assert req_body['data'] == { 'foo': 'bar' } + assert req_body['proxied'] == False + assert req_body['data'] == {'anyKey': 'anyValue'} + def test_create_dns_record_all_params_with_retries(self): + # Enable retries and run test_create_dns_record_all_params. + _service.enable_retries() + self.test_create_dns_record_all_params() + + # Disable retries and run test_create_dns_record_all_params. + _service.disable_retries() + self.test_create_dns_record_all_params() - #-------------------------------------------------------- - # test_create_dns_record_required_params() - #-------------------------------------------------------- @responses.activate def test_create_dns_record_required_params(self): + """ + test_create_dns_record_required_params() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.POST, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Invoke method - response = service.create_dns_record() - + response = _service.create_dns_record() # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + def test_create_dns_record_required_params_with_retries(self): + # Enable retries and run test_create_dns_record_required_params. + _service.enable_retries() + self.test_create_dns_record_required_params() + + # Disable retries and run test_create_dns_record_required_params. + _service.disable_retries() + self.test_create_dns_record_required_params() - #-------------------------------------------------------- - # test_create_dns_record_value_error() - #-------------------------------------------------------- @responses.activate def test_create_dns_record_value_error(self): + """ + test_create_dns_record_value_error() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records') + url = preprocess_url('/v1/testString/zones/testString/dns_records') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.POST, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Pass in all but one required param and check for a ValueError req_param_dict = { } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - service.create_dns_record(**req_copy) + _service.create_dns_record(**req_copy) + def test_create_dns_record_value_error_with_retries(self): + # Enable retries and run test_create_dns_record_value_error. + _service.enable_retries() + self.test_create_dns_record_value_error() + # Disable retries and run test_create_dns_record_value_error. + _service.disable_retries() + self.test_create_dns_record_value_error() -#----------------------------------------------------------------------------- -# Test Class for delete_dns_record -#----------------------------------------------------------------------------- -class TestDeleteDnsRecord(): - # Preprocess the request URL to ensure the mock response will be found. - def preprocess_url(self, request_url: str): - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') +class TestDeleteDnsRecord: + """ + Test Class for delete_dns_record + """ - #-------------------------------------------------------- - # delete_dns_record() - #-------------------------------------------------------- @responses.activate def test_delete_dns_record_all_params(self): + """ + delete_dns_record() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc"}}' - responses.add(responses.DELETE, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' # Invoke method - response = service.delete_dns_record( + response = _service.delete_dns_record( dnsrecord_identifier, - headers={} + headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + def test_delete_dns_record_all_params_with_retries(self): + # Enable retries and run test_delete_dns_record_all_params. + _service.enable_retries() + self.test_delete_dns_record_all_params() + + # Disable retries and run test_delete_dns_record_all_params. + _service.disable_retries() + self.test_delete_dns_record_all_params() - #-------------------------------------------------------- - # test_delete_dns_record_value_error() - #-------------------------------------------------------- @responses.activate def test_delete_dns_record_value_error(self): + """ + test_delete_dns_record_value_error() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc"}}' - responses.add(responses.DELETE, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' @@ -315,65 +445,78 @@ def test_delete_dns_record_value_error(self): "dnsrecord_identifier": dnsrecord_identifier, } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - service.delete_dns_record(**req_copy) + _service.delete_dns_record(**req_copy) + def test_delete_dns_record_value_error_with_retries(self): + # Enable retries and run test_delete_dns_record_value_error. + _service.enable_retries() + self.test_delete_dns_record_value_error() + # Disable retries and run test_delete_dns_record_value_error. + _service.disable_retries() + self.test_delete_dns_record_value_error() -#----------------------------------------------------------------------------- -# Test Class for get_dns_record -#----------------------------------------------------------------------------- -class TestGetDnsRecord(): - # Preprocess the request URL to ensure the mock response will be found. - def preprocess_url(self, request_url: str): - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') +class TestGetDnsRecord: + """ + Test Class for get_dns_record + """ - #-------------------------------------------------------- - # get_dns_record() - #-------------------------------------------------------- @responses.activate def test_get_dns_record_all_params(self): + """ + get_dns_record() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' # Invoke method - response = service.get_dns_record( + response = _service.get_dns_record( dnsrecord_identifier, - headers={} + headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + def test_get_dns_record_all_params_with_retries(self): + # Enable retries and run test_get_dns_record_all_params. + _service.enable_retries() + self.test_get_dns_record_all_params() + + # Disable retries and run test_get_dns_record_all_params. + _service.disable_retries() + self.test_get_dns_record_all_params() - #-------------------------------------------------------- - # test_get_dns_record_value_error() - #-------------------------------------------------------- @responses.activate def test_get_dns_record_value_error(self): + """ + test_get_dns_record_value_error() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.GET, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' @@ -383,57 +526,62 @@ def test_get_dns_record_value_error(self): "dnsrecord_identifier": dnsrecord_identifier, } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - service.get_dns_record(**req_copy) + _service.get_dns_record(**req_copy) + def test_get_dns_record_value_error_with_retries(self): + # Enable retries and run test_get_dns_record_value_error. + _service.enable_retries() + self.test_get_dns_record_value_error() + # Disable retries and run test_get_dns_record_value_error. + _service.disable_retries() + self.test_get_dns_record_value_error() -#----------------------------------------------------------------------------- -# Test Class for update_dns_record -#----------------------------------------------------------------------------- -class TestUpdateDnsRecord(): - # Preprocess the request URL to ensure the mock response will be found. - def preprocess_url(self, request_url: str): - if re.fullmatch('.*/+', request_url) is None: - return request_url - else: - return re.compile(request_url.rstrip('/') + '/+') +class TestUpdateDnsRecord: + """ + Test Class for update_dns_record + """ - #-------------------------------------------------------- - # update_dns_record() - #-------------------------------------------------------- @responses.activate def test_update_dns_record_all_params(self): + """ + update_dns_record() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.PUT, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' type = 'A' name = 'host-1.test-example.com' + ttl = 120 content = '1.2.3.4' priority = 5 proxied = False - data = { 'foo': 'bar' } + data = {'anyKey': 'anyValue'} # Invoke method - response = service.update_dns_record( + response = _service.update_dns_record( dnsrecord_identifier, type=type, name=name, + ttl=ttl, content=content, priority=priority, proxied=proxied, data=data, - headers={} + headers={}, ) # Check for correct operation @@ -443,53 +591,74 @@ def test_update_dns_record_all_params(self): req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) assert req_body['type'] == 'A' assert req_body['name'] == 'host-1.test-example.com' + assert req_body['ttl'] == 120 assert req_body['content'] == '1.2.3.4' assert req_body['priority'] == 5 assert req_body['proxied'] == False - assert req_body['data'] == { 'foo': 'bar' } + assert req_body['data'] == {'anyKey': 'anyValue'} + + def test_update_dns_record_all_params_with_retries(self): + # Enable retries and run test_update_dns_record_all_params. + _service.enable_retries() + self.test_update_dns_record_all_params() + # Disable retries and run test_update_dns_record_all_params. + _service.disable_retries() + self.test_update_dns_record_all_params() - #-------------------------------------------------------- - # test_update_dns_record_required_params() - #-------------------------------------------------------- @responses.activate def test_update_dns_record_required_params(self): + """ + test_update_dns_record_required_params() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.PUT, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' # Invoke method - response = service.update_dns_record( + response = _service.update_dns_record( dnsrecord_identifier, - headers={} + headers={}, ) # Check for correct operation assert len(responses.calls) == 1 assert response.status_code == 200 + def test_update_dns_record_required_params_with_retries(self): + # Enable retries and run test_update_dns_record_required_params. + _service.enable_retries() + self.test_update_dns_record_required_params() + + # Disable retries and run test_update_dns_record_required_params. + _service.disable_retries() + self.test_update_dns_record_required_params() - #-------------------------------------------------------- - # test_update_dns_record_value_error() - #-------------------------------------------------------- @responses.activate def test_update_dns_record_value_error(self): + """ + test_update_dns_record_value_error() + """ # Set up mock - url = self.preprocess_url(base_url + '/v1/testString/zones/testString/dns_records/testString') + url = preprocess_url('/v1/testString/zones/testString/dns_records/testString') mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "169.154.10.10", "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", "zone_name": "test-example.com", "proxiable": true, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}}}' - responses.add(responses.PUT, - url, - body=mock_response, - content_type='application/json', - status=200) + responses.add( + responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200, + ) # Set up parameter values dnsrecord_identifier = 'testString' @@ -499,10 +668,175 @@ def test_update_dns_record_value_error(self): "dnsrecord_identifier": dnsrecord_identifier, } for param in req_param_dict.keys(): - req_copy = {key:val if key is not param else None for (key,val) in req_param_dict.items()} + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} with pytest.raises(ValueError): - service.update_dns_record(**req_copy) + _service.update_dns_record(**req_copy) + + def test_update_dns_record_value_error_with_retries(self): + # Enable retries and run test_update_dns_record_value_error. + _service.enable_retries() + self.test_update_dns_record_value_error() + + # Disable retries and run test_update_dns_record_value_error. + _service.disable_retries() + self.test_update_dns_record_value_error() + + +class TestBatchDnsRecords: + """ + Test Class for batch_dns_records + """ + + @responses.activate + def test_batch_dns_records_all_params(self): + """ + batch_dns_records() + """ + # Set up mock + url = preprocess_url('/v1/testString/zones/testString/dns_records/batch') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"deletes": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "patches": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "posts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "puts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Construct a dict representation of a BatchDnsRecordsRequestDeletesItem model + batch_dns_records_request_deletes_item_model = {} + batch_dns_records_request_deletes_item_model['id'] = 'testString' + + # Construct a dict representation of a BatchDnsRecordsRequestPatchesItem model + batch_dns_records_request_patches_item_model = {} + batch_dns_records_request_patches_item_model['id'] = 'testString' + batch_dns_records_request_patches_item_model['name'] = 'host-1.test-example.com' + batch_dns_records_request_patches_item_model['type'] = 'A' + batch_dns_records_request_patches_item_model['ttl'] = 120 + batch_dns_records_request_patches_item_model['content'] = '1.2.3.4' + batch_dns_records_request_patches_item_model['priority'] = 5 + batch_dns_records_request_patches_item_model['proxied'] = False + batch_dns_records_request_patches_item_model['data'] = {'anyKey': 'anyValue'} + + # Construct a dict representation of a DnsrecordInput model + dnsrecord_input_model = {} + dnsrecord_input_model['name'] = 'host-1.test-example.com' + dnsrecord_input_model['type'] = 'A' + dnsrecord_input_model['ttl'] = 120 + dnsrecord_input_model['content'] = '1.2.3.4' + dnsrecord_input_model['priority'] = 5 + dnsrecord_input_model['proxied'] = False + dnsrecord_input_model['data'] = {'anyKey': 'anyValue'} + + # Construct a dict representation of a BatchDnsRecordsRequestPutsItem model + batch_dns_records_request_puts_item_model = {} + batch_dns_records_request_puts_item_model['id'] = 'testString' + batch_dns_records_request_puts_item_model['name'] = 'host-1.test-example.com' + batch_dns_records_request_puts_item_model['type'] = 'A' + batch_dns_records_request_puts_item_model['ttl'] = 120 + batch_dns_records_request_puts_item_model['content'] = '1.2.3.4' + batch_dns_records_request_puts_item_model['priority'] = 5 + batch_dns_records_request_puts_item_model['proxied'] = False + batch_dns_records_request_puts_item_model['data'] = {'anyKey': 'anyValue'} + + # Set up parameter values + deletes = [batch_dns_records_request_deletes_item_model] + patches = [batch_dns_records_request_patches_item_model] + posts = [dnsrecord_input_model] + puts = [batch_dns_records_request_puts_item_model] + + # Invoke method + response = _service.batch_dns_records( + deletes=deletes, + patches=patches, + posts=posts, + puts=puts, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate body params + req_body = json.loads(str(responses.calls[0].request.body, 'utf-8')) + assert req_body['deletes'] == [batch_dns_records_request_deletes_item_model] + assert req_body['patches'] == [batch_dns_records_request_patches_item_model] + assert req_body['posts'] == [dnsrecord_input_model] + assert req_body['puts'] == [batch_dns_records_request_puts_item_model] + + def test_batch_dns_records_all_params_with_retries(self): + # Enable retries and run test_batch_dns_records_all_params. + _service.enable_retries() + self.test_batch_dns_records_all_params() + + # Disable retries and run test_batch_dns_records_all_params. + _service.disable_retries() + self.test_batch_dns_records_all_params() + + @responses.activate + def test_batch_dns_records_required_params(self): + """ + test_batch_dns_records_required_params() + """ + # Set up mock + url = preprocess_url('/v1/testString/zones/testString/dns_records/batch') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"deletes": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "patches": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "posts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "puts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + # Invoke method + response = _service.batch_dns_records() + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + def test_batch_dns_records_required_params_with_retries(self): + # Enable retries and run test_batch_dns_records_required_params. + _service.enable_retries() + self.test_batch_dns_records_required_params() + + # Disable retries and run test_batch_dns_records_required_params. + _service.disable_retries() + self.test_batch_dns_records_required_params() + + @responses.activate + def test_batch_dns_records_value_error(self): + """ + test_batch_dns_records_value_error() + """ + # Set up mock + url = preprocess_url('/v1/testString/zones/testString/dns_records/batch') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"deletes": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "patches": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "posts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}], "puts": [{"id": "f1aba936b94213e5b8dca0c0dbf1f9cc", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "host-1.test-example.com", "type": "A", "content": "1.2.3.4", "proxiable": false, "proxied": false, "ttl": 120, "priority": 5, "data": {"anyKey": "anyValue"}, "settings": {"anyKey": "anyValue"}, "meta": {"anyKey": "anyValue"}, "comment": "comment", "tags": ["tags"]}]}}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.batch_dns_records(**req_copy) + + def test_batch_dns_records_value_error_with_retries(self): + # Enable retries and run test_batch_dns_records_value_error. + _service.enable_retries() + self.test_batch_dns_records_value_error() + + # Disable retries and run test_batch_dns_records_value_error. + _service.disable_retries() + self.test_batch_dns_records_value_error() # endregion @@ -515,15 +849,173 @@ def test_update_dns_record_value_error(self): # Start of Model Tests ############################################################################## # region -#----------------------------------------------------------------------------- -# Test Class for DeleteDnsrecordRespResult -#----------------------------------------------------------------------------- -class TestDeleteDnsrecordRespResult(): - - #-------------------------------------------------------- - # Test serialization/deserialization for DeleteDnsrecordRespResult - #-------------------------------------------------------- + + +class TestModel_BatchDnsRecordsRequestDeletesItem: + """ + Test Class for BatchDnsRecordsRequestDeletesItem + """ + + def test_batch_dns_records_request_deletes_item_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordsRequestDeletesItem + """ + + # Construct a json representation of a BatchDnsRecordsRequestDeletesItem model + batch_dns_records_request_deletes_item_model_json = {} + batch_dns_records_request_deletes_item_model_json['id'] = 'testString' + + # Construct a model instance of BatchDnsRecordsRequestDeletesItem by calling from_dict on the json representation + batch_dns_records_request_deletes_item_model = BatchDnsRecordsRequestDeletesItem.from_dict(batch_dns_records_request_deletes_item_model_json) + assert batch_dns_records_request_deletes_item_model != False + + # Construct a model instance of BatchDnsRecordsRequestDeletesItem by calling from_dict on the json representation + batch_dns_records_request_deletes_item_model_dict = BatchDnsRecordsRequestDeletesItem.from_dict(batch_dns_records_request_deletes_item_model_json).__dict__ + batch_dns_records_request_deletes_item_model2 = BatchDnsRecordsRequestDeletesItem(**batch_dns_records_request_deletes_item_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_records_request_deletes_item_model == batch_dns_records_request_deletes_item_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_records_request_deletes_item_model_json2 = batch_dns_records_request_deletes_item_model.to_dict() + assert batch_dns_records_request_deletes_item_model_json2 == batch_dns_records_request_deletes_item_model_json + + +class TestModel_BatchDnsRecordsRequestPatchesItem: + """ + Test Class for BatchDnsRecordsRequestPatchesItem + """ + + def test_batch_dns_records_request_patches_item_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordsRequestPatchesItem + """ + + # Construct a json representation of a BatchDnsRecordsRequestPatchesItem model + batch_dns_records_request_patches_item_model_json = {} + batch_dns_records_request_patches_item_model_json['id'] = 'testString' + batch_dns_records_request_patches_item_model_json['name'] = 'host-1.test-example.com' + batch_dns_records_request_patches_item_model_json['type'] = 'A' + batch_dns_records_request_patches_item_model_json['ttl'] = 120 + batch_dns_records_request_patches_item_model_json['content'] = '1.2.3.4' + batch_dns_records_request_patches_item_model_json['priority'] = 5 + batch_dns_records_request_patches_item_model_json['proxied'] = False + batch_dns_records_request_patches_item_model_json['data'] = {'anyKey': 'anyValue'} + + # Construct a model instance of BatchDnsRecordsRequestPatchesItem by calling from_dict on the json representation + batch_dns_records_request_patches_item_model = BatchDnsRecordsRequestPatchesItem.from_dict(batch_dns_records_request_patches_item_model_json) + assert batch_dns_records_request_patches_item_model != False + + # Construct a model instance of BatchDnsRecordsRequestPatchesItem by calling from_dict on the json representation + batch_dns_records_request_patches_item_model_dict = BatchDnsRecordsRequestPatchesItem.from_dict(batch_dns_records_request_patches_item_model_json).__dict__ + batch_dns_records_request_patches_item_model2 = BatchDnsRecordsRequestPatchesItem(**batch_dns_records_request_patches_item_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_records_request_patches_item_model == batch_dns_records_request_patches_item_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_records_request_patches_item_model_json2 = batch_dns_records_request_patches_item_model.to_dict() + assert batch_dns_records_request_patches_item_model_json2 == batch_dns_records_request_patches_item_model_json + + +class TestModel_BatchDnsRecordsRequestPutsItem: + """ + Test Class for BatchDnsRecordsRequestPutsItem + """ + + def test_batch_dns_records_request_puts_item_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordsRequestPutsItem + """ + + # Construct a json representation of a BatchDnsRecordsRequestPutsItem model + batch_dns_records_request_puts_item_model_json = {} + batch_dns_records_request_puts_item_model_json['id'] = 'testString' + batch_dns_records_request_puts_item_model_json['name'] = 'host-1.test-example.com' + batch_dns_records_request_puts_item_model_json['type'] = 'A' + batch_dns_records_request_puts_item_model_json['ttl'] = 120 + batch_dns_records_request_puts_item_model_json['content'] = '1.2.3.4' + batch_dns_records_request_puts_item_model_json['priority'] = 5 + batch_dns_records_request_puts_item_model_json['proxied'] = False + batch_dns_records_request_puts_item_model_json['data'] = {'anyKey': 'anyValue'} + + # Construct a model instance of BatchDnsRecordsRequestPutsItem by calling from_dict on the json representation + batch_dns_records_request_puts_item_model = BatchDnsRecordsRequestPutsItem.from_dict(batch_dns_records_request_puts_item_model_json) + assert batch_dns_records_request_puts_item_model != False + + # Construct a model instance of BatchDnsRecordsRequestPutsItem by calling from_dict on the json representation + batch_dns_records_request_puts_item_model_dict = BatchDnsRecordsRequestPutsItem.from_dict(batch_dns_records_request_puts_item_model_json).__dict__ + batch_dns_records_request_puts_item_model2 = BatchDnsRecordsRequestPutsItem(**batch_dns_records_request_puts_item_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_records_request_puts_item_model == batch_dns_records_request_puts_item_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_records_request_puts_item_model_json2 = batch_dns_records_request_puts_item_model.to_dict() + assert batch_dns_records_request_puts_item_model_json2 == batch_dns_records_request_puts_item_model_json + + +class TestModel_BatchDnsRecordsResponseResult: + """ + Test Class for BatchDnsRecordsResponseResult + """ + + def test_batch_dns_records_response_result_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordsResponseResult + """ + + # Construct dict forms of any model objects needed in order to build this model. + + batch_dns_record_details_model = {} # BatchDnsRecordDetails + batch_dns_record_details_model['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' + batch_dns_record_details_model['created_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model['modified_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model['name'] = 'host-1.test-example.com' + batch_dns_record_details_model['type'] = 'A' + batch_dns_record_details_model['content'] = '1.2.3.4' + batch_dns_record_details_model['proxiable'] = False + batch_dns_record_details_model['proxied'] = False + batch_dns_record_details_model['ttl'] = 120 + batch_dns_record_details_model['priority'] = 5 + batch_dns_record_details_model['data'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['settings'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['meta'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['comment'] = 'testString' + batch_dns_record_details_model['tags'] = ['testString'] + + # Construct a json representation of a BatchDnsRecordsResponseResult model + batch_dns_records_response_result_model_json = {} + batch_dns_records_response_result_model_json['deletes'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model_json['patches'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model_json['posts'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model_json['puts'] = [batch_dns_record_details_model] + + # Construct a model instance of BatchDnsRecordsResponseResult by calling from_dict on the json representation + batch_dns_records_response_result_model = BatchDnsRecordsResponseResult.from_dict(batch_dns_records_response_result_model_json) + assert batch_dns_records_response_result_model != False + + # Construct a model instance of BatchDnsRecordsResponseResult by calling from_dict on the json representation + batch_dns_records_response_result_model_dict = BatchDnsRecordsResponseResult.from_dict(batch_dns_records_response_result_model_json).__dict__ + batch_dns_records_response_result_model2 = BatchDnsRecordsResponseResult(**batch_dns_records_response_result_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_records_response_result_model == batch_dns_records_response_result_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_records_response_result_model_json2 = batch_dns_records_response_result_model.to_dict() + assert batch_dns_records_response_result_model_json2 == batch_dns_records_response_result_model_json + + +class TestModel_DeleteDnsrecordRespResult: + """ + Test Class for DeleteDnsrecordRespResult + """ + def test_delete_dnsrecord_resp_result_serialization(self): + """ + Test serialization/deserialization for DeleteDnsrecordRespResult + """ # Construct a json representation of a DeleteDnsrecordRespResult model delete_dnsrecord_resp_result_model_json = {} @@ -544,19 +1036,122 @@ def test_delete_dnsrecord_resp_result_serialization(self): delete_dnsrecord_resp_result_model_json2 = delete_dnsrecord_resp_result_model.to_dict() assert delete_dnsrecord_resp_result_model_json2 == delete_dnsrecord_resp_result_model_json -#----------------------------------------------------------------------------- -# Test Class for DeleteDnsrecordResp -#----------------------------------------------------------------------------- -class TestDeleteDnsrecordResp(): - #-------------------------------------------------------- - # Test serialization/deserialization for DeleteDnsrecordResp - #-------------------------------------------------------- +class TestModel_BatchDnsRecordDetails: + """ + Test Class for BatchDnsRecordDetails + """ + + def test_batch_dns_record_details_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordDetails + """ + + # Construct a json representation of a BatchDnsRecordDetails model + batch_dns_record_details_model_json = {} + batch_dns_record_details_model_json['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' + batch_dns_record_details_model_json['created_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model_json['modified_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model_json['name'] = 'host-1.test-example.com' + batch_dns_record_details_model_json['type'] = 'A' + batch_dns_record_details_model_json['content'] = '1.2.3.4' + batch_dns_record_details_model_json['proxiable'] = False + batch_dns_record_details_model_json['proxied'] = False + batch_dns_record_details_model_json['ttl'] = 120 + batch_dns_record_details_model_json['priority'] = 5 + batch_dns_record_details_model_json['data'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model_json['settings'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model_json['meta'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model_json['comment'] = 'testString' + batch_dns_record_details_model_json['tags'] = ['testString'] + + # Construct a model instance of BatchDnsRecordDetails by calling from_dict on the json representation + batch_dns_record_details_model = BatchDnsRecordDetails.from_dict(batch_dns_record_details_model_json) + assert batch_dns_record_details_model != False + + # Construct a model instance of BatchDnsRecordDetails by calling from_dict on the json representation + batch_dns_record_details_model_dict = BatchDnsRecordDetails.from_dict(batch_dns_record_details_model_json).__dict__ + batch_dns_record_details_model2 = BatchDnsRecordDetails(**batch_dns_record_details_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_record_details_model == batch_dns_record_details_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_record_details_model_json2 = batch_dns_record_details_model.to_dict() + assert batch_dns_record_details_model_json2 == batch_dns_record_details_model_json + + +class TestModel_BatchDnsRecordsResponse: + """ + Test Class for BatchDnsRecordsResponse + """ + + def test_batch_dns_records_response_serialization(self): + """ + Test serialization/deserialization for BatchDnsRecordsResponse + """ + + # Construct dict forms of any model objects needed in order to build this model. + + batch_dns_record_details_model = {} # BatchDnsRecordDetails + batch_dns_record_details_model['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' + batch_dns_record_details_model['created_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model['modified_on'] = '2014-01-01T05:20:00.12345Z' + batch_dns_record_details_model['name'] = 'host-1.test-example.com' + batch_dns_record_details_model['type'] = 'A' + batch_dns_record_details_model['content'] = '1.2.3.4' + batch_dns_record_details_model['proxiable'] = False + batch_dns_record_details_model['proxied'] = False + batch_dns_record_details_model['ttl'] = 120 + batch_dns_record_details_model['priority'] = 5 + batch_dns_record_details_model['data'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['settings'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['meta'] = {'anyKey': 'anyValue'} + batch_dns_record_details_model['comment'] = 'testString' + batch_dns_record_details_model['tags'] = ['testString'] + + batch_dns_records_response_result_model = {} # BatchDnsRecordsResponseResult + batch_dns_records_response_result_model['deletes'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model['patches'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model['posts'] = [batch_dns_record_details_model] + batch_dns_records_response_result_model['puts'] = [batch_dns_record_details_model] + + # Construct a json representation of a BatchDnsRecordsResponse model + batch_dns_records_response_model_json = {} + batch_dns_records_response_model_json['success'] = True + batch_dns_records_response_model_json['errors'] = [['testString']] + batch_dns_records_response_model_json['messages'] = [['testString']] + batch_dns_records_response_model_json['result'] = batch_dns_records_response_result_model + + # Construct a model instance of BatchDnsRecordsResponse by calling from_dict on the json representation + batch_dns_records_response_model = BatchDnsRecordsResponse.from_dict(batch_dns_records_response_model_json) + assert batch_dns_records_response_model != False + + # Construct a model instance of BatchDnsRecordsResponse by calling from_dict on the json representation + batch_dns_records_response_model_dict = BatchDnsRecordsResponse.from_dict(batch_dns_records_response_model_json).__dict__ + batch_dns_records_response_model2 = BatchDnsRecordsResponse(**batch_dns_records_response_model_dict) + + # Verify the model instances are equivalent + assert batch_dns_records_response_model == batch_dns_records_response_model2 + + # Convert model instance back to dict and verify no loss of data + batch_dns_records_response_model_json2 = batch_dns_records_response_model.to_dict() + assert batch_dns_records_response_model_json2 == batch_dns_records_response_model_json + + +class TestModel_DeleteDnsrecordResp: + """ + Test Class for DeleteDnsrecordResp + """ + def test_delete_dnsrecord_resp_serialization(self): + """ + Test serialization/deserialization for DeleteDnsrecordResp + """ # Construct dict forms of any model objects needed in order to build this model. - delete_dnsrecord_resp_result_model = {} # DeleteDnsrecordRespResult + delete_dnsrecord_resp_result_model = {} # DeleteDnsrecordRespResult delete_dnsrecord_resp_result_model['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' # Construct a json representation of a DeleteDnsrecordResp model @@ -581,15 +1176,16 @@ def test_delete_dnsrecord_resp_serialization(self): delete_dnsrecord_resp_model_json2 = delete_dnsrecord_resp_model.to_dict() assert delete_dnsrecord_resp_model_json2 == delete_dnsrecord_resp_model_json -#----------------------------------------------------------------------------- -# Test Class for DnsrecordDetails -#----------------------------------------------------------------------------- -class TestDnsrecordDetails(): - #-------------------------------------------------------- - # Test serialization/deserialization for DnsrecordDetails - #-------------------------------------------------------- +class TestModel_DnsrecordDetails: + """ + Test Class for DnsrecordDetails + """ + def test_dnsrecord_details_serialization(self): + """ + Test serialization/deserialization for DnsrecordDetails + """ # Construct a json representation of a DnsrecordDetails model dnsrecord_details_model_json = {} @@ -605,7 +1201,7 @@ def test_dnsrecord_details_serialization(self): dnsrecord_details_model_json['proxied'] = False dnsrecord_details_model_json['ttl'] = 120 dnsrecord_details_model_json['priority'] = 5 - dnsrecord_details_model_json['data'] = { 'foo': 'bar' } + dnsrecord_details_model_json['data'] = {'anyKey': 'anyValue'} # Construct a model instance of DnsrecordDetails by calling from_dict on the json representation dnsrecord_details_model = DnsrecordDetails.from_dict(dnsrecord_details_model_json) @@ -622,19 +1218,56 @@ def test_dnsrecord_details_serialization(self): dnsrecord_details_model_json2 = dnsrecord_details_model.to_dict() assert dnsrecord_details_model_json2 == dnsrecord_details_model_json -#----------------------------------------------------------------------------- -# Test Class for DnsrecordResp -#----------------------------------------------------------------------------- -class TestDnsrecordResp(): - #-------------------------------------------------------- - # Test serialization/deserialization for DnsrecordResp - #-------------------------------------------------------- +class TestModel_DnsrecordInput: + """ + Test Class for DnsrecordInput + """ + + def test_dnsrecord_input_serialization(self): + """ + Test serialization/deserialization for DnsrecordInput + """ + + # Construct a json representation of a DnsrecordInput model + dnsrecord_input_model_json = {} + dnsrecord_input_model_json['name'] = 'host-1.test-example.com' + dnsrecord_input_model_json['type'] = 'A' + dnsrecord_input_model_json['ttl'] = 120 + dnsrecord_input_model_json['content'] = '1.2.3.4' + dnsrecord_input_model_json['priority'] = 5 + dnsrecord_input_model_json['proxied'] = False + dnsrecord_input_model_json['data'] = {'anyKey': 'anyValue'} + + # Construct a model instance of DnsrecordInput by calling from_dict on the json representation + dnsrecord_input_model = DnsrecordInput.from_dict(dnsrecord_input_model_json) + assert dnsrecord_input_model != False + + # Construct a model instance of DnsrecordInput by calling from_dict on the json representation + dnsrecord_input_model_dict = DnsrecordInput.from_dict(dnsrecord_input_model_json).__dict__ + dnsrecord_input_model2 = DnsrecordInput(**dnsrecord_input_model_dict) + + # Verify the model instances are equivalent + assert dnsrecord_input_model == dnsrecord_input_model2 + + # Convert model instance back to dict and verify no loss of data + dnsrecord_input_model_json2 = dnsrecord_input_model.to_dict() + assert dnsrecord_input_model_json2 == dnsrecord_input_model_json + + +class TestModel_DnsrecordResp: + """ + Test Class for DnsrecordResp + """ + def test_dnsrecord_resp_serialization(self): + """ + Test serialization/deserialization for DnsrecordResp + """ # Construct dict forms of any model objects needed in order to build this model. - dnsrecord_details_model = {} # DnsrecordDetails + dnsrecord_details_model = {} # DnsrecordDetails dnsrecord_details_model['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' dnsrecord_details_model['created_on'] = '2014-01-01T05:20:00.12345Z' dnsrecord_details_model['modified_on'] = '2014-01-01T05:20:00.12345Z' @@ -647,7 +1280,7 @@ def test_dnsrecord_resp_serialization(self): dnsrecord_details_model['proxied'] = False dnsrecord_details_model['ttl'] = 120 dnsrecord_details_model['priority'] = 5 - dnsrecord_details_model['data'] = { 'foo': 'bar' } + dnsrecord_details_model['data'] = {'anyKey': 'anyValue'} # Construct a json representation of a DnsrecordResp model dnsrecord_resp_model_json = {} @@ -671,19 +1304,20 @@ def test_dnsrecord_resp_serialization(self): dnsrecord_resp_model_json2 = dnsrecord_resp_model.to_dict() assert dnsrecord_resp_model_json2 == dnsrecord_resp_model_json -#----------------------------------------------------------------------------- -# Test Class for ListDnsrecordsResp -#----------------------------------------------------------------------------- -class TestListDnsrecordsResp(): - #-------------------------------------------------------- - # Test serialization/deserialization for ListDnsrecordsResp - #-------------------------------------------------------- +class TestModel_ListDnsrecordsResp: + """ + Test Class for ListDnsrecordsResp + """ + def test_list_dnsrecords_resp_serialization(self): + """ + Test serialization/deserialization for ListDnsrecordsResp + """ # Construct dict forms of any model objects needed in order to build this model. - dnsrecord_details_model = {} # DnsrecordDetails + dnsrecord_details_model = {} # DnsrecordDetails dnsrecord_details_model['id'] = 'f1aba936b94213e5b8dca0c0dbf1f9cc' dnsrecord_details_model['created_on'] = '2014-01-01T05:20:00.12345Z' dnsrecord_details_model['modified_on'] = '2014-01-01T05:20:00.12345Z' @@ -696,9 +1330,9 @@ def test_list_dnsrecords_resp_serialization(self): dnsrecord_details_model['proxied'] = False dnsrecord_details_model['ttl'] = 120 dnsrecord_details_model['priority'] = 5 - dnsrecord_details_model['data'] = { 'foo': 'bar' } + dnsrecord_details_model['data'] = {'anyKey': 'anyValue'} - result_info_model = {} # ResultInfo + result_info_model = {} # ResultInfo result_info_model['page'] = 1 result_info_model['per_page'] = 20 result_info_model['count'] = 1 @@ -727,15 +1361,16 @@ def test_list_dnsrecords_resp_serialization(self): list_dnsrecords_resp_model_json2 = list_dnsrecords_resp_model.to_dict() assert list_dnsrecords_resp_model_json2 == list_dnsrecords_resp_model_json -#----------------------------------------------------------------------------- -# Test Class for ResultInfo -#----------------------------------------------------------------------------- -class TestResultInfo(): - #-------------------------------------------------------- - # Test serialization/deserialization for ResultInfo - #-------------------------------------------------------- +class TestModel_ResultInfo: + """ + Test Class for ResultInfo + """ + def test_result_info_serialization(self): + """ + Test serialization/deserialization for ResultInfo + """ # Construct a json representation of a ResultInfo model result_info_model_json = {} From 610fac81a3dd1f7195c6c5abd321da6853d75991 Mon Sep 17 00:00:00 2001 From: Sirija Reddy Date: Mon, 20 Apr 2026 12:46:53 +0530 Subject: [PATCH 2/2] fix unit tests Signed-off-by: Sirija Reddy --- test/unit/test_dns_records_v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_dns_records_v1.py b/test/unit/test_dns_records_v1.py index 3c8f685..0143d05 100644 --- a/test/unit/test_dns_records_v1.py +++ b/test/unit/test_dns_records_v1.py @@ -107,7 +107,7 @@ def test_new_instance_required_param_none(self): """ new_instance_required_param_none() """ - with pytest.raises(ValueError, match='crn must be provided must be provided'): + with pytest.raises(ValueError, match='crn must be provided'): service = DnsRecordsV1.new_instance( crn=None, zone_identifier=None,