diff --git a/.secrets.baseline b/.secrets.baseline index 592fd7f..ec77adb 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "package-lock.json|^.secrets.baseline$", "lines": null }, - "generated_at": "2021-03-09T20:23:57Z", + "generated_at": "2021-06-22T04:29:24Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -25,6 +25,7 @@ "name": "CloudantDetector" }, { + "ghe_instance": "github.ibm.com", "name": "GheDetector" }, { @@ -163,7 +164,7 @@ "hashed_secret": "94851979e1cb78bbd9e48a9e2a01f7485e2dbf37", "is_secret": false, "is_verified": false, - "line_number": 2286, + "line_number": 2365, "type": "Hex High Entropy String", "verified_result": null }, @@ -171,7 +172,7 @@ "hashed_secret": "4c154143659305d3cea695447bc2947935d294d0", "is_secret": false, "is_verified": false, - "line_number": 2623, + "line_number": 2705, "type": "Hex High Entropy String", "verified_result": null }, @@ -179,7 +180,7 @@ "hashed_secret": "d67a00cdeec75b04602db35a89c15bb6ee53c877", "is_secret": false, "is_verified": false, - "line_number": 2858, + "line_number": 2940, "type": "Hex High Entropy String", "verified_result": null } @@ -353,7 +354,7 @@ "hashed_secret": "d67a00cdeec75b04602db35a89c15bb6ee53c877", "is_secret": false, "is_verified": false, - "line_number": 1253, + "line_number": 1632, "type": "Hex High Entropy String", "verified_result": null }, @@ -361,7 +362,7 @@ "hashed_secret": "eb74ff42e2e8dfbaf3e4f64a02cdadc8bedda8c3", "is_secret": false, "is_verified": false, - "line_number": 1343, + "line_number": 1815, "type": "Hex High Entropy String", "verified_result": null } @@ -521,7 +522,7 @@ } ] }, - "version": "0.13.1+ibm.31.dss", + "version": "0.13.1+ibm.38.dss", "word_list": { "file": null, "hash": null diff --git a/.travis.yml b/.travis.yml index 2440ba4..6984b76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,4 +53,4 @@ deploy: skip_cleanup: true on: python: '3.6' - tags: true \ No newline at end of file + tags: true diff --git a/cis.env.enc b/cis.env.enc index 0942b1b..86f87d0 100644 Binary files a/cis.env.enc and b/cis.env.enc differ diff --git a/dns.env.enc b/dns.env.enc index fb2c5cc..5684ea9 100644 Binary files a/dns.env.enc and b/dns.env.enc differ diff --git a/ibm_cloud_networking_services/__init__.py b/ibm_cloud_networking_services/__init__.py index 7d54f99..c2d3e00 100644 --- a/ibm_cloud_networking_services/__init__.py +++ b/ibm_cloud_networking_services/__init__.py @@ -1,5 +1,5 @@ # coding: utf-8 -# Copyright 2020 IBM All Rights Reserved. +# Copyright 2021 IBM All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ from .custom_pages_v1 import CustomPagesV1 from .dns_record_bulk_v1 import DnsRecordBulkV1 from .dns_records_v1 import DnsRecordsV1 +from .filters_v1 import FiltersV1 from .firewall_access_rules_v1 import FirewallAccessRulesV1 from .firewall_api_v1 import FirewallApiV1 from .global_load_balancer_events_v1 import GlobalLoadBalancerEventsV1 diff --git a/ibm_cloud_networking_services/filters_v1.py b/ibm_cloud_networking_services/filters_v1.py new file mode 100644 index 0000000..f16dd14 --- /dev/null +++ b/ibm_cloud_networking_services/filters_v1.py @@ -0,0 +1,1396 @@ +# coding: utf-8 + +# (C) Copyright IBM Corp. 2021. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# IBM OpenAPI SDK Code Generator Version: 3.32.0-4c6a3129-20210514-210323 + +""" +Filters +""" + +from typing import Dict, List +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 + +############################################################################## +# Service +############################################################################## + +class FiltersV1(BaseService): + """The Filters V1 service.""" + + DEFAULT_SERVICE_URL = 'https://api.cis.cloud.ibm.com' + DEFAULT_SERVICE_NAME = 'filters' + + @classmethod + def new_instance(cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'FiltersV1': + """ + Return a new client for the Filters service using the specified parameters + and external configuration. + """ + authenticator = get_authenticator_from_environment(service_name) + service = cls( + authenticator + ) + service.configure_service(service_name) + return service + + def __init__(self, + authenticator: Authenticator = None, + ) -> None: + """ + Construct a new client for the Filters service. + + :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 + about initializing the authenticator of your choice. + """ + BaseService.__init__(self, + service_url=self.DEFAULT_SERVICE_URL, + authenticator=authenticator) + + + ######################### + # Filters + ######################### + + + def list_all_filters(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + List all filters for a zone. + + List all filters for a zone. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full url-encoded cloud resource name (CRN) of resource + instance. + :param str zone_identifier: Zone identifier of the zone for which filters + are listed. + :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 `ListFiltersResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='list_all_filters') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters'.format(**path_param_dict) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def create_filter(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + *, + filter_input: List['FilterInput'] = None, + **kwargs + ) -> DetailedResponse: + """ + Create filters for a zone. + + Create new filters for a given zone under a service instance. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full url-encoded cloud resource name (CRN) of resource + instance. + :param str zone_identifier: Zone identifier of the zone for which filters + are created. + :param List[FilterInput] filter_input: (optional) Json objects which are + used to create filters. + :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 `FiltersResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if filter_input is not None: + filter_input = [convert_model(x) for x in filter_input] + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='create_filter') + headers.update(sdk_headers) + + data = json.dumps(filter_input) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters'.format(**path_param_dict) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def update_filters(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + *, + filter_update_input: List['FilterUpdateInput'] = None, + **kwargs + ) -> DetailedResponse: + """ + Update filters. + + Update existing filters for a given zone under a given service instance. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full crn of the service instance. + :param str zone_identifier: Zone identifier (zone id). + :param List[FilterUpdateInput] filter_update_input: (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 `FiltersResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if filter_update_input is not None: + filter_update_input = [convert_model(x) for x in filter_update_input] + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_filters') + headers.update(sdk_headers) + + data = json.dumps(filter_update_input) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters'.format(**path_param_dict) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def delete_filters(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + id: str, + **kwargs + ) -> DetailedResponse: + """ + Delete filters. + + Delete filters by filter ids. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full crn of the service instance. + :param str zone_identifier: Identifier of zone whose filters are to be + deleted. + :param str id: ids of filters which will be deleted. + :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 `DeleteFiltersResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if id is None: + raise ValueError('id must be provided') + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_filters') + headers.update(sdk_headers) + + params = { + 'id': id + } + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers, + params=params) + + response = self.send(request) + return response + + + def delete_filter(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + filter_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + Delete a filter. + + Delete a filter given its id. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full crn of the service instance. + :param str zone_identifier: Identifier of zone whose filter is to be + deleted. + :param str filter_identifier: Identifier of the filter to be deleted. + :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 `DeleteFilterResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if filter_identifier is None: + raise ValueError('filter_identifier must be provided') + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='delete_filter') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'filter_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, filter_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters/{filter_identifier}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def get_filter(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + filter_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + Get filter details by id. + + Get the details of a filter for a given zone under a given service instance. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full crn of the service instance. + :param str zone_identifier: Zone identifier (zone id). + :param str filter_identifier: Identifier of filter for the given zone. + :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 `FilterResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if filter_identifier is None: + raise ValueError('filter_identifier must be provided') + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='get_filter') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'filter_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, filter_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters/{filter_identifier}'.format(**path_param_dict) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def update_filter(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + filter_identifier: str, + *, + id: str = None, + expression: str = None, + description: str = None, + paused: bool = None, + **kwargs + ) -> DetailedResponse: + """ + Update a filter. + + Update an existing filter for a given zone under a given service instance. + + :param str x_auth_user_token: IBM Cloud user IAM token. + :param str crn: Full crn of the service instance. + :param str zone_identifier: Zone identifier (zone id). + :param str filter_identifier: Identifier of filter. + :param str id: (optional) Identifier of the filter. + :param str expression: (optional) A filter expression. + :param str description: (optional) To briefly describe the filter. + :param bool paused: (optional) Indicates if the filter is active. + :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 `FilterResp` object + """ + + if x_auth_user_token is None: + raise ValueError('x_auth_user_token must be provided') + if crn is None: + raise ValueError('crn must be provided') + if zone_identifier is None: + raise ValueError('zone_identifier must be provided') + if filter_identifier is None: + raise ValueError('filter_identifier must be provided') + headers = { + 'X-Auth-User-Token': x_auth_user_token + } + sdk_headers = get_sdk_headers(service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='update_filter') + headers.update(sdk_headers) + + data = { + 'id': id, + 'expression': expression, + 'description': description, + 'paused': paused + } + data = {k: v for (k, v) in data.items() if v is not None} + data = json.dumps(data) + headers['content-type'] = 'application/json' + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'filter_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, filter_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/filters/{filter_identifier}'.format(**path_param_dict) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + +############################################################################## +# Models +############################################################################## + + +class DeleteFilterRespResult(): + """ + Container for response information. + + :attr str id: Identifier of the filter. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a DeleteFilterRespResult object. + + :param str id: Identifier of the filter. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFilterRespResult': + """Initialize a DeleteFilterRespResult object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in DeleteFilterRespResult JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFilterRespResult 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 + 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 DeleteFilterRespResult object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFilterRespResult') -> 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: 'DeleteFilterRespResult') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFiltersRespResultItem(): + """ + DeleteFiltersRespResultItem. + + :attr str id: Identifier of the filter. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a DeleteFiltersRespResultItem object. + + :param str id: Identifier of the filter. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFiltersRespResultItem': + """Initialize a DeleteFiltersRespResultItem object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in DeleteFiltersRespResultItem JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFiltersRespResultItem 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 + 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 DeleteFiltersRespResultItem object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFiltersRespResultItem') -> 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: 'DeleteFiltersRespResultItem') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListFiltersRespResultInfo(): + """ + Statistics of results. + + :attr int page: Page number. + :attr int per_page: Number of results per page. + :attr int count: Number of results. + :attr int total_count: Total number of results. + """ + + def __init__(self, + page: int, + per_page: int, + count: int, + total_count: int) -> None: + """ + Initialize a ListFiltersRespResultInfo object. + + :param int page: Page number. + :param int per_page: Number of results per page. + :param int count: Number of results. + :param int total_count: Total number of results. + """ + self.page = page + self.per_page = per_page + self.count = count + self.total_count = total_count + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListFiltersRespResultInfo': + """Initialize a ListFiltersRespResultInfo object from a json dictionary.""" + args = {} + if 'page' in _dict: + args['page'] = _dict.get('page') + else: + raise ValueError('Required property \'page\' not present in ListFiltersRespResultInfo JSON') + if 'per_page' in _dict: + args['per_page'] = _dict.get('per_page') + else: + raise ValueError('Required property \'per_page\' not present in ListFiltersRespResultInfo JSON') + if 'count' in _dict: + args['count'] = _dict.get('count') + else: + raise ValueError('Required property \'count\' not present in ListFiltersRespResultInfo JSON') + if 'total_count' in _dict: + args['total_count'] = _dict.get('total_count') + else: + raise ValueError('Required property \'total_count\' not present in ListFiltersRespResultInfo JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListFiltersRespResultInfo 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, 'page') and self.page is not None: + _dict['page'] = self.page + if hasattr(self, 'per_page') and self.per_page is not None: + _dict['per_page'] = self.per_page + if hasattr(self, 'count') and self.count is not None: + _dict['count'] = self.count + if hasattr(self, 'total_count') and self.total_count is not None: + _dict['total_count'] = self.total_count + 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 ListFiltersRespResultInfo object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListFiltersRespResultInfo') -> 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: 'ListFiltersRespResultInfo') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFilterResp(): + """ + DeleteFilterResp. + + :attr bool success: Operation success flag. + :attr List[List[str]] errors: Array of errors encountered. + :attr List[List[str]] messages: Array of messages returned. + :attr DeleteFilterRespResult result: Container for response information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'DeleteFilterRespResult') -> None: + """ + Initialize a DeleteFilterResp object. + + :param bool success: Operation success flag. + :param List[List[str]] errors: Array of errors encountered. + :param List[List[str]] messages: Array of messages returned. + :param DeleteFilterRespResult result: Container for response information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFilterResp': + """Initialize a DeleteFilterResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in DeleteFilterResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in DeleteFilterResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in DeleteFilterResp JSON') + if 'result' in _dict: + args['result'] = DeleteFilterRespResult.from_dict(_dict.get('result')) + else: + raise ValueError('Required property \'result\' not present in DeleteFilterResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFilterResp 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() + 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 DeleteFilterResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFilterResp') -> 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: 'DeleteFilterResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFiltersResp(): + """ + DeleteFiltersResp. + + :attr bool success: Operation success flag. + :attr List[List[str]] errors: Array of errors encountered. + :attr List[List[str]] messages: Array of messages returned. + :attr List[DeleteFiltersRespResultItem] result: Container for response + information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['DeleteFiltersRespResultItem']) -> None: + """ + Initialize a DeleteFiltersResp object. + + :param bool success: Operation success flag. + :param List[List[str]] errors: Array of errors encountered. + :param List[List[str]] messages: Array of messages returned. + :param List[DeleteFiltersRespResultItem] result: Container for response + information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFiltersResp': + """Initialize a DeleteFiltersResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in DeleteFiltersResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in DeleteFiltersResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in DeleteFiltersResp JSON') + if 'result' in _dict: + args['result'] = [DeleteFiltersRespResultItem.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in DeleteFiltersResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFiltersResp 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] + 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 DeleteFiltersResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFiltersResp') -> 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: 'DeleteFiltersResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FilterInput(): + """ + Json objects which are used to create filters. + + :attr str expression: A filter expression. + :attr bool paused: (optional) Indicates if the filter is active. + :attr str description: (optional) To briefly describe the filter, omitted from + object if empty. + """ + + def __init__(self, + expression: str, + *, + paused: bool = None, + description: str = None) -> None: + """ + Initialize a FilterInput object. + + :param str expression: A filter expression. + :param bool paused: (optional) Indicates if the filter is active. + :param str description: (optional) To briefly describe the filter, omitted + from object if empty. + """ + self.expression = expression + self.paused = paused + self.description = description + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FilterInput': + """Initialize a FilterInput object from a json dictionary.""" + args = {} + if 'expression' in _dict: + args['expression'] = _dict.get('expression') + else: + raise ValueError('Required property \'expression\' not present in FilterInput JSON') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + if 'description' in _dict: + args['description'] = _dict.get('description') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FilterInput 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, 'expression') and self.expression is not None: + _dict['expression'] = self.expression + if hasattr(self, 'paused') and self.paused is not None: + _dict['paused'] = self.paused + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + 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 FilterInput object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FilterInput') -> 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: 'FilterInput') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FilterObject(): + """ + FilterObject. + + :attr str id: Identifier of the filter. + :attr bool paused: Indicates if the filter is active. + :attr str description: To briefly describe the filter, omitted from object if + empty. + :attr str expression: A filter expression. + :attr str created_on: The creation date-time of the filter. + :attr str modified_on: The modification date-time of the filter. + """ + + def __init__(self, + id: str, + paused: bool, + description: str, + expression: str, + created_on: str, + modified_on: str) -> None: + """ + Initialize a FilterObject object. + + :param str id: Identifier of the filter. + :param bool paused: Indicates if the filter is active. + :param str description: To briefly describe the filter, omitted from object + if empty. + :param str expression: A filter expression. + :param str created_on: The creation date-time of the filter. + :param str modified_on: The modification date-time of the filter. + """ + self.id = id + self.paused = paused + self.description = description + self.expression = expression + self.created_on = created_on + self.modified_on = modified_on + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FilterObject': + """Initialize a FilterObject object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FilterObject JSON') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + else: + raise ValueError('Required property \'paused\' not present in FilterObject JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + else: + raise ValueError('Required property \'description\' not present in FilterObject JSON') + if 'expression' in _dict: + args['expression'] = _dict.get('expression') + else: + raise ValueError('Required property \'expression\' not present in FilterObject JSON') + if 'created_on' in _dict: + args['created_on'] = _dict.get('created_on') + else: + raise ValueError('Required property \'created_on\' not present in FilterObject JSON') + if 'modified_on' in _dict: + args['modified_on'] = _dict.get('modified_on') + else: + raise ValueError('Required property \'modified_on\' not present in FilterObject JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FilterObject 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, 'paused') and self.paused is not None: + _dict['paused'] = self.paused + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'expression') and self.expression is not None: + _dict['expression'] = self.expression + 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 + 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 FilterObject object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FilterObject') -> 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: 'FilterObject') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FilterResp(): + """ + FilterResp. + + :attr bool success: Operation success flag. + :attr List[List[str]] errors: Array of errors encountered. + :attr List[List[str]] messages: Array of messages returned. + :attr FilterObject result: + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'FilterObject') -> None: + """ + Initialize a FilterResp object. + + :param bool success: Operation success flag. + :param List[List[str]] errors: Array of errors encountered. + :param List[List[str]] messages: Array of messages returned. + :param FilterObject result: + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FilterResp': + """Initialize a FilterResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in FilterResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in FilterResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in FilterResp JSON') + if 'result' in _dict: + args['result'] = FilterObject.from_dict(_dict.get('result')) + else: + raise ValueError('Required property \'result\' not present in FilterResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FilterResp 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() + 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 FilterResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FilterResp') -> 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: 'FilterResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FilterUpdateInput(): + """ + FilterUpdateInput. + + :attr str id: Identifier of the filter. + :attr str expression: A filter expression. + :attr str description: (optional) To briefly describe the filter. + :attr bool paused: (optional) Indicates if the filter is active. + """ + + def __init__(self, + id: str, + expression: str, + *, + description: str = None, + paused: bool = None) -> None: + """ + Initialize a FilterUpdateInput object. + + :param str id: Identifier of the filter. + :param str expression: A filter expression. + :param str description: (optional) To briefly describe the filter. + :param bool paused: (optional) Indicates if the filter is active. + """ + self.id = id + self.expression = expression + self.description = description + self.paused = paused + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FilterUpdateInput': + """Initialize a FilterUpdateInput object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FilterUpdateInput JSON') + if 'expression' in _dict: + args['expression'] = _dict.get('expression') + else: + raise ValueError('Required property \'expression\' not present in FilterUpdateInput JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FilterUpdateInput 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, 'expression') and self.expression is not None: + _dict['expression'] = self.expression + if hasattr(self, 'description') and self.description is not None: + _dict['description'] = self.description + if hasattr(self, 'paused') and self.paused is not None: + _dict['paused'] = self.paused + 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 FilterUpdateInput object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FilterUpdateInput') -> 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: 'FilterUpdateInput') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FiltersResp(): + """ + FiltersResp. + + :attr bool success: Operation success flag. + :attr List[List[str]] errors: Array of errors encountered. + :attr List[List[str]] messages: Array of messages returned. + :attr List[FilterObject] result: Container for response information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['FilterObject']) -> None: + """ + Initialize a FiltersResp object. + + :param bool success: Operation success flag. + :param List[List[str]] errors: Array of errors encountered. + :param List[List[str]] messages: Array of messages returned. + :param List[FilterObject] result: Container for response information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FiltersResp': + """Initialize a FiltersResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in FiltersResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in FiltersResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in FiltersResp JSON') + if 'result' in _dict: + args['result'] = [FilterObject.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in FiltersResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FiltersResp 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] + 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 FiltersResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FiltersResp') -> 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: 'FiltersResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListFiltersResp(): + """ + ListFiltersResp. + + :attr bool success: Operation success flag. + :attr List[List[str]] errors: Array of errors encountered. + :attr List[List[str]] messages: Array of messages returned. + :attr List[FilterObject] result: Container for response information. + :attr ListFiltersRespResultInfo result_info: Statistics of results. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['FilterObject'], + result_info: 'ListFiltersRespResultInfo') -> None: + """ + Initialize a ListFiltersResp object. + + :param bool success: Operation success flag. + :param List[List[str]] errors: Array of errors encountered. + :param List[List[str]] messages: Array of messages returned. + :param List[FilterObject] result: Container for response information. + :param ListFiltersRespResultInfo result_info: Statistics of results. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + self.result_info = result_info + + @classmethod + def from_dict(cls, _dict: Dict) -> 'ListFiltersResp': + """Initialize a ListFiltersResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in ListFiltersResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in ListFiltersResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in ListFiltersResp JSON') + if 'result' in _dict: + args['result'] = [FilterObject.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in ListFiltersResp JSON') + if 'result_info' in _dict: + args['result_info'] = ListFiltersRespResultInfo.from_dict(_dict.get('result_info')) + else: + raise ValueError('Required property \'result_info\' not present in ListFiltersResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListFiltersResp 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] + if hasattr(self, 'result_info') and self.result_info is not None: + _dict['result_info'] = self.result_info.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 ListFiltersResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListFiltersResp') -> 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: 'ListFiltersResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other diff --git a/test/integration/test_filters_v1.py b/test/integration/test_filters_v1.py new file mode 100644 index 0000000..157304f --- /dev/null +++ b/test/integration/test_filters_v1.py @@ -0,0 +1,250 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2021. + +""" +Integration test code to execute Filters of a Zone +""" + +import os +import unittest +from dotenv import load_dotenv, find_dotenv +from ibm_cloud_networking_services.filters_v1 import FiltersV1 + +configFile = "cis.env" + +# load the .env file containing your environment variables +try: + load_dotenv(find_dotenv(filename="cis.env")) +except: + print('warning: no cis.env file loaded') + +class TestFiltersV1(unittest.TestCase): + """ Test class to call dns record sdk functions """ + def setUp(self): + """ test case setup """ + 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") + self.x_auth_user_token = os.getenv("CIS_SERVICES_APIKEY") + # create dns record class object + self.service = FiltersV1.new_instance( + service_name="cis_services") + self.service.set_service_url(self.endpoint) + self._clean_filters() + + def tearDown(self): + """ tear down """ + # Delete the resources + self._clean_filters() + print("Clean up complete") + + def _clean_filters(self): + response = self.service.list_all_filters( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id + ) + assert response is not None + assert response.status_code == 200 + resp = response.get_result().get("result") + for record in resp: + self.service.delete_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_identifier = record.get("id") + ) + + def _create_filter(self, expression, description, paused=False): + filter_input_model = {} + filter_input_model['expression'] = expression + filter_input_model['paused'] = False + filter_input_model['description'] = description + filter_input = [filter_input_model] + + response = self.service.create_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_input = filter_input + ) + assert response is not None and response.get_status_code() == 200 + filter_id = response.get_result()['result'][0]['id'] + return filter_id + + ################## create Filter ###################### + def test_1_create_filter(self): + """ test for success """ + # Construct a dict representation of a FilterInput model + filter_input_model = {} + filter_input_model['expression'] = 'not http.request.uri.path matches "^/test/.*$"' + filter_input_model['paused'] = False + filter_input_model['description'] = 'not /test' + filter_input = [filter_input_model] + + response = self.service.create_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_input = filter_input + ) + assert response is not None and response.get_status_code() == 200 + self.filter_id = response.get_result()['result'][0]['id'] + + ################## list_all_filters ################### + + def test_2_list_all_filters(self): + """ test for success """ + filter_input_model = {} + filter_input_model['expression'] = 'http.request.uri.path matches "^/list-all/.*$"' + filter_input_model['paused'] = False + filter_input_model['description'] = 'list test' + filter_input = [filter_input_model] + + response = self.service.create_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_input = filter_input + ) + assert response is not None and response.get_status_code() == 200 + + response = self.service.list_all_filters( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id + ) + assert response is not None and response.get_status_code() == 200 + assert len(response.get_result()['result']) >= 1 + + ################## update filters ################### + def test_3_update_filters(self): + filter_input_model = {} + filter_input_model['expression'] = 'http.request.uri.path matches "^/update-one/.*$"' + filter_input_model['paused'] = False + filter_input_model['description'] = 'Update test' + filter_input = [filter_input_model] + + response = self.service.create_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_input = filter_input + ) + assert response is not None and response.get_status_code() == 200 + filter_id = response.get_result()['result'][0]['id'] + # Construct a dict representation of a FilterUpdateInput model + filter_update_input_model = {} + filter_update_input_model['id'] = filter_id + filter_update_input_model['expression'] = '(ip.src eq 13.15.12.24)' + filter_update_input_model['description'] = 'sdk python update lists' + filter_update_input_model['paused'] = False + filter_update_input = [filter_update_input_model] + + response = self.service.update_filters( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_update_input = filter_update_input + ) + assert response is not None and response.get_status_code() == 200 + update_filter_id = response.get_result()['result'][0]['id'] + assert update_filter_id == filter_id + assert response.get_result()['result'][0]['expression'] == filter_update_input_model['expression'] + + + ################## get filter by id ################### + def test_4_get_filter_by_id(self): + expression = 'http.request.uri.path matches "^/get-filter/.*$"' + filter_id = self._create_filter( + expression = expression, + description = 'Update Filter' + ) + response = self.service.get_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_identifier = filter_id + ) + assert response is not None and response.get_status_code() == 200 + get_filter_id = response.get_result()['result']['id'] + assert get_filter_id == filter_id + assert response.get_result()['result']['expression'] == expression + + ################## update filter by id ################### + def test_5_update_filter_by_id(self): + filter_id = self._create_filter( + expression = 'http.request.uri.path matches "^/get-filter/.*$"', + description = 'Update Filter' + ) + + response = self.service.update_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_identifier = filter_id, + id = filter_id, + expression = '(ip.src eq 213.115.12.24)', + description = 'update a single filter test' + ) + assert response is not None and response.get_status_code() == 200 + get_filter_id = response.get_result()['result']['id'] + assert get_filter_id == filter_id + + ################## delete a filter by id ################### + def test_6_delete_filter_by_id(self): + filter_id = self._create_filter( + expression = 'http.request.uri.path matches "^/delete-filter/.*$"', + description = 'Delete Filter' + ) + response = self.service.delete_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_identifier = filter_id + ) + assert response is not None and response.get_status_code() == 200 + get_filter_id = response.get_result()['result']['id'] + assert get_filter_id == filter_id + + ################## delete filters ################### + def test_7_delete_filters(self): + # Create a filter + # Construct a dict representation of a FilterInput model + filter_input_model = {} + filter_input_model['expression'] = 'ip.src eq 193.184.216.0' + filter_input_model['paused'] = False + filter_input_model['description'] = 'not from ip' + filter_input = [filter_input_model] + + response = self.service.create_filter( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + filter_input = filter_input + ) + assert response is not None and response.get_status_code() == 200 + filter_id_to_del = response.get_result()['result'][0]['id'] + + response = self.service.delete_filters( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + id = filter_id_to_del + ) + assert response is not None and response.get_status_code() == 200 + print(response.get_result()) + get_filter_id = response.get_result()['result'][0]['id'] + assert get_filter_id == filter_id_to_del + +if __name__ == '__main__': + unittest.main() + + + + + + diff --git a/test/unit/test_filters_v1.py b/test/unit/test_filters_v1.py new file mode 100644 index 0000000..a23af7b --- /dev/null +++ b/test/unit/test_filters_v1.py @@ -0,0 +1,1152 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2021. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Unit Tests for FiltersV1 +""" + +from ibm_cloud_sdk_core.authenticators.no_auth_authenticator import NoAuthAuthenticator +import inspect +import json +import pytest +import re +import requests +import responses +import urllib +from ibm_cloud_networking_services.filters_v1 import * + + +_service = FiltersV1( + authenticator=NoAuthAuthenticator() + ) + +_base_url = 'https://api.cis.cloud.ibm.com' +_service.set_service_url(_base_url) + +############################################################################## +# Start of Service: Filters +############################################################################## +# region + +class TestListAllFilters(): + """ + Test Class for list_all_filters + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_list_all_filters_all_params(self): + """ + list_all_filters() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}], "result_info": {"page": 1, "per_page": 2, "count": 1, "total_count": 200}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Invoke method + response = _service.list_all_filters( + x_auth_user_token, + crn, + zone_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_list_all_filters_value_error(self): + """ + test_list_all_filters_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}], "result_info": {"page": 1, "per_page": 2, "count": 1, "total_count": 200}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_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()} + with pytest.raises(ValueError): + _service.list_all_filters(**req_copy) + + + +class TestCreateFilter(): + """ + Test Class for create_filter + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_create_filter_all_params(self): + """ + create_filter() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a FilterInput model + filter_input_model = {} + filter_input_model['expression'] = 'not http.request.uri.path matches "^/api/.*$"' + filter_input_model['paused'] = False + filter_input_model['description'] = 'not /api' + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_input = [filter_input_model] + + # Invoke method + response = _service.create_filter( + x_auth_user_token, + crn, + zone_identifier, + filter_input=filter_input, + 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 == filter_input + + + @responses.activate + def test_create_filter_required_params(self): + """ + test_create_filter_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Invoke method + response = _service.create_filter( + x_auth_user_token, + crn, + zone_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_create_filter_value_error(self): + """ + test_create_filter_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_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()} + with pytest.raises(ValueError): + _service.create_filter(**req_copy) + + + +class TestUpdateFilters(): + """ + Test Class for update_filters + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_update_filters_all_params(self): + """ + update_filters() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Construct a dict representation of a FilterUpdateInput model + filter_update_input_model = {} + filter_update_input_model['id'] = 'f2a64520581a4209aab12187a0081364' + filter_update_input_model['expression'] = 'not http.request.uri.path matches "^/api/.*$"' + filter_update_input_model['description'] = 'not /api' + filter_update_input_model['paused'] = False + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_update_input = [filter_update_input_model] + + # Invoke method + response = _service.update_filters( + x_auth_user_token, + crn, + zone_identifier, + filter_update_input=filter_update_input, + 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 == filter_update_input + + + @responses.activate + def test_update_filters_required_params(self): + """ + test_update_filters_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Invoke method + response = _service.update_filters( + x_auth_user_token, + crn, + zone_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_filters_value_error(self): + """ + test_update_filters_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}]}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_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()} + with pytest.raises(ValueError): + _service.update_filters(**req_copy) + + + +class TestDeleteFilters(): + """ + Test Class for delete_filters + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_delete_filters_all_params(self): + """ + delete_filters() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "b7ff25282d394be7b945e23c7106ce8a"}]}' + responses.add(responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + id = 'b7ff25282d394be7b945e23c7106ce8a' + + # Invoke method + response = _service.delete_filters( + x_auth_user_token, + crn, + zone_identifier, + id, + 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 = urllib.parse.unquote_plus(query_string) + assert 'id={}'.format(id) in query_string + + + @responses.activate + def test_delete_filters_value_error(self): + """ + test_delete_filters_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "b7ff25282d394be7b945e23c7106ce8a"}]}' + responses.add(responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + id = 'b7ff25282d394be7b945e23c7106ce8a' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_identifier, + "id": id, + } + 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.delete_filters(**req_copy) + + + +class TestDeleteFilter(): + """ + Test Class for delete_filter + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_delete_filter_all_params(self): + """ + delete_filter() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "b7ff25282d394be7b945e23c7106ce8a"}}' + responses.add(responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Invoke method + response = _service.delete_filter( + x_auth_user_token, + crn, + zone_identifier, + filter_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_delete_filter_value_error(self): + """ + test_delete_filter_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "b7ff25282d394be7b945e23c7106ce8a"}}' + responses.add(responses.DELETE, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_identifier, + "filter_identifier": filter_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()} + with pytest.raises(ValueError): + _service.delete_filter(**req_copy) + + + +class TestGetFilter(): + """ + Test Class for get_filter + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_get_filter_all_params(self): + """ + get_filter() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Invoke method + response = _service.get_filter( + x_auth_user_token, + crn, + zone_identifier, + filter_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_filter_value_error(self): + """ + test_get_filter_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}}' + responses.add(responses.GET, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_identifier, + "filter_identifier": filter_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()} + with pytest.raises(ValueError): + _service.get_filter(**req_copy) + + + +class TestUpdateFilter(): + """ + Test Class for update_filter + """ + + def preprocess_url(self, request_url: str): + """ + Preprocess the request URL to ensure the mock response will be found. + """ + if re.fullmatch('.*/+', request_url) is None: + return request_url + else: + return re.compile(request_url.rstrip('/') + '/+') + + @responses.activate + def test_update_filter_all_params(self): + """ + update_filter() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + id = 'f2a64520581a4209aab12187a0081364' + expression = 'not http.request.uri.path matches "^/api/.*$"' + description = 'not /api' + paused = False + + # Invoke method + response = _service.update_filter( + x_auth_user_token, + crn, + zone_identifier, + filter_identifier, + id=id, + expression=expression, + description=description, + paused=paused, + 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['id'] == 'f2a64520581a4209aab12187a0081364' + assert req_body['expression'] == 'not http.request.uri.path matches "^/api/.*$"' + assert req_body['description'] == 'not /api' + assert req_body['paused'] == False + + + @responses.activate + def test_update_filter_required_params(self): + """ + test_update_filter_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Invoke method + response = _service.update_filter( + x_auth_user_token, + crn, + zone_identifier, + filter_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_filter_value_error(self): + """ + test_update_filter_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/filters/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "6f58318e7fa2477a23112e8118c66f61", "paused": true, "description": "Login from office", "expression": "ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")", "created_on": "2018-01-01T05:20:00.123Z", "modified_on": "2018-01-01T05:20:00.123Z"}}' + responses.add(responses.PUT, + url, + body=mock_response, + content_type='application/json', + status=200) + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + filter_identifier = 'testString' + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "x_auth_user_token": x_auth_user_token, + "crn": crn, + "zone_identifier": zone_identifier, + "filter_identifier": filter_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()} + with pytest.raises(ValueError): + _service.update_filter(**req_copy) + + + +# endregion +############################################################################## +# End of Service: Filters +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region +class TestDeleteFilterRespResult(): + """ + Test Class for DeleteFilterRespResult + """ + + def test_delete_filter_resp_result_serialization(self): + """ + Test serialization/deserialization for DeleteFilterRespResult + """ + + # Construct a json representation of a DeleteFilterRespResult model + delete_filter_resp_result_model_json = {} + delete_filter_resp_result_model_json['id'] = 'b7ff25282d394be7b945e23c7106ce8a' + + # Construct a model instance of DeleteFilterRespResult by calling from_dict on the json representation + delete_filter_resp_result_model = DeleteFilterRespResult.from_dict(delete_filter_resp_result_model_json) + assert delete_filter_resp_result_model != False + + # Construct a model instance of DeleteFilterRespResult by calling from_dict on the json representation + delete_filter_resp_result_model_dict = DeleteFilterRespResult.from_dict(delete_filter_resp_result_model_json).__dict__ + delete_filter_resp_result_model2 = DeleteFilterRespResult(**delete_filter_resp_result_model_dict) + + # Verify the model instances are equivalent + assert delete_filter_resp_result_model == delete_filter_resp_result_model2 + + # Convert model instance back to dict and verify no loss of data + delete_filter_resp_result_model_json2 = delete_filter_resp_result_model.to_dict() + assert delete_filter_resp_result_model_json2 == delete_filter_resp_result_model_json + +class TestDeleteFiltersRespResultItem(): + """ + Test Class for DeleteFiltersRespResultItem + """ + + def test_delete_filters_resp_result_item_serialization(self): + """ + Test serialization/deserialization for DeleteFiltersRespResultItem + """ + + # Construct a json representation of a DeleteFiltersRespResultItem model + delete_filters_resp_result_item_model_json = {} + delete_filters_resp_result_item_model_json['id'] = 'b7ff25282d394be7b945e23c7106ce8a' + + # Construct a model instance of DeleteFiltersRespResultItem by calling from_dict on the json representation + delete_filters_resp_result_item_model = DeleteFiltersRespResultItem.from_dict(delete_filters_resp_result_item_model_json) + assert delete_filters_resp_result_item_model != False + + # Construct a model instance of DeleteFiltersRespResultItem by calling from_dict on the json representation + delete_filters_resp_result_item_model_dict = DeleteFiltersRespResultItem.from_dict(delete_filters_resp_result_item_model_json).__dict__ + delete_filters_resp_result_item_model2 = DeleteFiltersRespResultItem(**delete_filters_resp_result_item_model_dict) + + # Verify the model instances are equivalent + assert delete_filters_resp_result_item_model == delete_filters_resp_result_item_model2 + + # Convert model instance back to dict and verify no loss of data + delete_filters_resp_result_item_model_json2 = delete_filters_resp_result_item_model.to_dict() + assert delete_filters_resp_result_item_model_json2 == delete_filters_resp_result_item_model_json + +class TestListFiltersRespResultInfo(): + """ + Test Class for ListFiltersRespResultInfo + """ + + def test_list_filters_resp_result_info_serialization(self): + """ + Test serialization/deserialization for ListFiltersRespResultInfo + """ + + # Construct a json representation of a ListFiltersRespResultInfo model + list_filters_resp_result_info_model_json = {} + list_filters_resp_result_info_model_json['page'] = 1 + list_filters_resp_result_info_model_json['per_page'] = 2 + list_filters_resp_result_info_model_json['count'] = 1 + list_filters_resp_result_info_model_json['total_count'] = 200 + + # Construct a model instance of ListFiltersRespResultInfo by calling from_dict on the json representation + list_filters_resp_result_info_model = ListFiltersRespResultInfo.from_dict(list_filters_resp_result_info_model_json) + assert list_filters_resp_result_info_model != False + + # Construct a model instance of ListFiltersRespResultInfo by calling from_dict on the json representation + list_filters_resp_result_info_model_dict = ListFiltersRespResultInfo.from_dict(list_filters_resp_result_info_model_json).__dict__ + list_filters_resp_result_info_model2 = ListFiltersRespResultInfo(**list_filters_resp_result_info_model_dict) + + # Verify the model instances are equivalent + assert list_filters_resp_result_info_model == list_filters_resp_result_info_model2 + + # Convert model instance back to dict and verify no loss of data + list_filters_resp_result_info_model_json2 = list_filters_resp_result_info_model.to_dict() + assert list_filters_resp_result_info_model_json2 == list_filters_resp_result_info_model_json + +class TestDeleteFilterResp(): + """ + Test Class for DeleteFilterResp + """ + + def test_delete_filter_resp_serialization(self): + """ + Test serialization/deserialization for DeleteFilterResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + delete_filter_resp_result_model = {} # DeleteFilterRespResult + delete_filter_resp_result_model['id'] = 'b7ff25282d394be7b945e23c7106ce8a' + + # Construct a json representation of a DeleteFilterResp model + delete_filter_resp_model_json = {} + delete_filter_resp_model_json['success'] = True + delete_filter_resp_model_json['errors'] = [['testString']] + delete_filter_resp_model_json['messages'] = [['testString']] + delete_filter_resp_model_json['result'] = delete_filter_resp_result_model + + # Construct a model instance of DeleteFilterResp by calling from_dict on the json representation + delete_filter_resp_model = DeleteFilterResp.from_dict(delete_filter_resp_model_json) + assert delete_filter_resp_model != False + + # Construct a model instance of DeleteFilterResp by calling from_dict on the json representation + delete_filter_resp_model_dict = DeleteFilterResp.from_dict(delete_filter_resp_model_json).__dict__ + delete_filter_resp_model2 = DeleteFilterResp(**delete_filter_resp_model_dict) + + # Verify the model instances are equivalent + assert delete_filter_resp_model == delete_filter_resp_model2 + + # Convert model instance back to dict and verify no loss of data + delete_filter_resp_model_json2 = delete_filter_resp_model.to_dict() + assert delete_filter_resp_model_json2 == delete_filter_resp_model_json + +class TestDeleteFiltersResp(): + """ + Test Class for DeleteFiltersResp + """ + + def test_delete_filters_resp_serialization(self): + """ + Test serialization/deserialization for DeleteFiltersResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + delete_filters_resp_result_item_model = {} # DeleteFiltersRespResultItem + delete_filters_resp_result_item_model['id'] = 'b7ff25282d394be7b945e23c7106ce8a' + + # Construct a json representation of a DeleteFiltersResp model + delete_filters_resp_model_json = {} + delete_filters_resp_model_json['success'] = True + delete_filters_resp_model_json['errors'] = [['testString']] + delete_filters_resp_model_json['messages'] = [['testString']] + delete_filters_resp_model_json['result'] = [delete_filters_resp_result_item_model] + + # Construct a model instance of DeleteFiltersResp by calling from_dict on the json representation + delete_filters_resp_model = DeleteFiltersResp.from_dict(delete_filters_resp_model_json) + assert delete_filters_resp_model != False + + # Construct a model instance of DeleteFiltersResp by calling from_dict on the json representation + delete_filters_resp_model_dict = DeleteFiltersResp.from_dict(delete_filters_resp_model_json).__dict__ + delete_filters_resp_model2 = DeleteFiltersResp(**delete_filters_resp_model_dict) + + # Verify the model instances are equivalent + assert delete_filters_resp_model == delete_filters_resp_model2 + + # Convert model instance back to dict and verify no loss of data + delete_filters_resp_model_json2 = delete_filters_resp_model.to_dict() + assert delete_filters_resp_model_json2 == delete_filters_resp_model_json + +class TestFilterInput(): + """ + Test Class for FilterInput + """ + + def test_filter_input_serialization(self): + """ + Test serialization/deserialization for FilterInput + """ + + # Construct a json representation of a FilterInput model + filter_input_model_json = {} + filter_input_model_json['expression'] = 'not http.request.uri.path matches "^/api/.*$"' + filter_input_model_json['paused'] = False + filter_input_model_json['description'] = 'not /api' + + # Construct a model instance of FilterInput by calling from_dict on the json representation + filter_input_model = FilterInput.from_dict(filter_input_model_json) + assert filter_input_model != False + + # Construct a model instance of FilterInput by calling from_dict on the json representation + filter_input_model_dict = FilterInput.from_dict(filter_input_model_json).__dict__ + filter_input_model2 = FilterInput(**filter_input_model_dict) + + # Verify the model instances are equivalent + assert filter_input_model == filter_input_model2 + + # Convert model instance back to dict and verify no loss of data + filter_input_model_json2 = filter_input_model.to_dict() + assert filter_input_model_json2 == filter_input_model_json + +class TestFilterObject(): + """ + Test Class for FilterObject + """ + + def test_filter_object_serialization(self): + """ + Test serialization/deserialization for FilterObject + """ + + # Construct a json representation of a FilterObject model + filter_object_model_json = {} + filter_object_model_json['id'] = '6f58318e7fa2477a23112e8118c66f61' + filter_object_model_json['paused'] = True + filter_object_model_json['description'] = 'Login from office' + filter_object_model_json['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + filter_object_model_json['created_on'] = '2018-01-01T05:20:00.123Z' + filter_object_model_json['modified_on'] = '2018-01-01T05:20:00.123Z' + + # Construct a model instance of FilterObject by calling from_dict on the json representation + filter_object_model = FilterObject.from_dict(filter_object_model_json) + assert filter_object_model != False + + # Construct a model instance of FilterObject by calling from_dict on the json representation + filter_object_model_dict = FilterObject.from_dict(filter_object_model_json).__dict__ + filter_object_model2 = FilterObject(**filter_object_model_dict) + + # Verify the model instances are equivalent + assert filter_object_model == filter_object_model2 + + # Convert model instance back to dict and verify no loss of data + filter_object_model_json2 = filter_object_model.to_dict() + assert filter_object_model_json2 == filter_object_model_json + +class TestFilterResp(): + """ + Test Class for FilterResp + """ + + def test_filter_resp_serialization(self): + """ + Test serialization/deserialization for FilterResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + filter_object_model = {} # FilterObject + filter_object_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + filter_object_model['paused'] = True + filter_object_model['description'] = 'Login from office' + filter_object_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + filter_object_model['created_on'] = '2018-01-01T05:20:00.123Z' + filter_object_model['modified_on'] = '2018-01-01T05:20:00.123Z' + + # Construct a json representation of a FilterResp model + filter_resp_model_json = {} + filter_resp_model_json['success'] = True + filter_resp_model_json['errors'] = [['testString']] + filter_resp_model_json['messages'] = [['testString']] + filter_resp_model_json['result'] = filter_object_model + + # Construct a model instance of FilterResp by calling from_dict on the json representation + filter_resp_model = FilterResp.from_dict(filter_resp_model_json) + assert filter_resp_model != False + + # Construct a model instance of FilterResp by calling from_dict on the json representation + filter_resp_model_dict = FilterResp.from_dict(filter_resp_model_json).__dict__ + filter_resp_model2 = FilterResp(**filter_resp_model_dict) + + # Verify the model instances are equivalent + assert filter_resp_model == filter_resp_model2 + + # Convert model instance back to dict and verify no loss of data + filter_resp_model_json2 = filter_resp_model.to_dict() + assert filter_resp_model_json2 == filter_resp_model_json + +class TestFilterUpdateInput(): + """ + Test Class for FilterUpdateInput + """ + + def test_filter_update_input_serialization(self): + """ + Test serialization/deserialization for FilterUpdateInput + """ + + # Construct a json representation of a FilterUpdateInput model + filter_update_input_model_json = {} + filter_update_input_model_json['id'] = 'f2a64520581a4209aab12187a0081364' + filter_update_input_model_json['expression'] = 'not http.request.uri.path matches "^/api/.*$"' + filter_update_input_model_json['description'] = 'not /api' + filter_update_input_model_json['paused'] = False + + # Construct a model instance of FilterUpdateInput by calling from_dict on the json representation + filter_update_input_model = FilterUpdateInput.from_dict(filter_update_input_model_json) + assert filter_update_input_model != False + + # Construct a model instance of FilterUpdateInput by calling from_dict on the json representation + filter_update_input_model_dict = FilterUpdateInput.from_dict(filter_update_input_model_json).__dict__ + filter_update_input_model2 = FilterUpdateInput(**filter_update_input_model_dict) + + # Verify the model instances are equivalent + assert filter_update_input_model == filter_update_input_model2 + + # Convert model instance back to dict and verify no loss of data + filter_update_input_model_json2 = filter_update_input_model.to_dict() + assert filter_update_input_model_json2 == filter_update_input_model_json + +class TestFiltersResp(): + """ + Test Class for FiltersResp + """ + + def test_filters_resp_serialization(self): + """ + Test serialization/deserialization for FiltersResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + filter_object_model = {} # FilterObject + filter_object_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + filter_object_model['paused'] = True + filter_object_model['description'] = 'Login from office' + filter_object_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + filter_object_model['created_on'] = '2018-01-01T05:20:00.123Z' + filter_object_model['modified_on'] = '2018-01-01T05:20:00.123Z' + + # Construct a json representation of a FiltersResp model + filters_resp_model_json = {} + filters_resp_model_json['success'] = True + filters_resp_model_json['errors'] = [['testString']] + filters_resp_model_json['messages'] = [['testString']] + filters_resp_model_json['result'] = [filter_object_model] + + # Construct a model instance of FiltersResp by calling from_dict on the json representation + filters_resp_model = FiltersResp.from_dict(filters_resp_model_json) + assert filters_resp_model != False + + # Construct a model instance of FiltersResp by calling from_dict on the json representation + filters_resp_model_dict = FiltersResp.from_dict(filters_resp_model_json).__dict__ + filters_resp_model2 = FiltersResp(**filters_resp_model_dict) + + # Verify the model instances are equivalent + assert filters_resp_model == filters_resp_model2 + + # Convert model instance back to dict and verify no loss of data + filters_resp_model_json2 = filters_resp_model.to_dict() + assert filters_resp_model_json2 == filters_resp_model_json + +class TestListFiltersResp(): + """ + Test Class for ListFiltersResp + """ + + def test_list_filters_resp_serialization(self): + """ + Test serialization/deserialization for ListFiltersResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + filter_object_model = {} # FilterObject + filter_object_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + filter_object_model['paused'] = True + filter_object_model['description'] = 'Login from office' + filter_object_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + filter_object_model['created_on'] = '2018-01-01T05:20:00.123Z' + filter_object_model['modified_on'] = '2018-01-01T05:20:00.123Z' + + list_filters_resp_result_info_model = {} # ListFiltersRespResultInfo + list_filters_resp_result_info_model['page'] = 1 + list_filters_resp_result_info_model['per_page'] = 2 + list_filters_resp_result_info_model['count'] = 1 + list_filters_resp_result_info_model['total_count'] = 200 + + # Construct a json representation of a ListFiltersResp model + list_filters_resp_model_json = {} + list_filters_resp_model_json['success'] = True + list_filters_resp_model_json['errors'] = [['testString']] + list_filters_resp_model_json['messages'] = [['testString']] + list_filters_resp_model_json['result'] = [filter_object_model] + list_filters_resp_model_json['result_info'] = list_filters_resp_result_info_model + + # Construct a model instance of ListFiltersResp by calling from_dict on the json representation + list_filters_resp_model = ListFiltersResp.from_dict(list_filters_resp_model_json) + assert list_filters_resp_model != False + + # Construct a model instance of ListFiltersResp by calling from_dict on the json representation + list_filters_resp_model_dict = ListFiltersResp.from_dict(list_filters_resp_model_json).__dict__ + list_filters_resp_model2 = ListFiltersResp(**list_filters_resp_model_dict) + + # Verify the model instances are equivalent + assert list_filters_resp_model == list_filters_resp_model2 + + # Convert model instance back to dict and verify no loss of data + list_filters_resp_model_json2 = list_filters_resp_model.to_dict() + assert list_filters_resp_model_json2 == list_filters_resp_model_json + + +# endregion +############################################################################## +# End of Model Tests +##############################################################################