From b8db1cf974f370a6e179cda076174500a67689bf Mon Sep 17 00:00:00 2001 From: Santhi Date: Tue, 5 Oct 2021 15:43:04 +0530 Subject: [PATCH] feat(firewall rules):Add Firewall Rules SDK --- ibm_cloud_networking_services/__init__.py | 2 + .../firewall_rules_v1.py | 1728 +++++++++++++++++ test/integration/test_firewall_rules_v1.py | 386 ++++ test/unit/test_firewall_rules_v1.py | 1325 +++++++++++++ 4 files changed, 3441 insertions(+) create mode 100644 ibm_cloud_networking_services/firewall_rules_v1.py create mode 100644 test/integration/test_firewall_rules_v1.py create mode 100644 test/unit/test_firewall_rules_v1.py diff --git a/ibm_cloud_networking_services/__init__.py b/ibm_cloud_networking_services/__init__.py index 7d54f99..fb0be53 100644 --- a/ibm_cloud_networking_services/__init__.py +++ b/ibm_cloud_networking_services/__init__.py @@ -27,7 +27,9 @@ from .dns_record_bulk_v1 import DnsRecordBulkV1 from .dns_records_v1 import DnsRecordsV1 from .firewall_access_rules_v1 import FirewallAccessRulesV1 +from .filters_v1 import FiltersV1 from .firewall_api_v1 import FirewallApiV1 +from .firewall_rules_v1 import FirewallRulesV1 from .global_load_balancer_events_v1 import GlobalLoadBalancerEventsV1 from .global_load_balancer_monitor_v1 import GlobalLoadBalancerMonitorV1 from .global_load_balancer_pools_v0 import GlobalLoadBalancerPoolsV0 diff --git a/ibm_cloud_networking_services/firewall_rules_v1.py b/ibm_cloud_networking_services/firewall_rules_v1.py new file mode 100644 index 0000000..e533c5d --- /dev/null +++ b/ibm_cloud_networking_services/firewall_rules_v1.py @@ -0,0 +1,1728 @@ +# 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 + +""" +Firewall rules +""" + +from enum import Enum +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 FirewallRulesV1(BaseService): + """The Firewall rules V1 service.""" + + DEFAULT_SERVICE_URL = 'https://api.cis.cloud.ibm.com' + DEFAULT_SERVICE_NAME = 'firewall_rules' + + @classmethod + def new_instance(cls, + service_name: str = DEFAULT_SERVICE_NAME, + ) -> 'FirewallRulesV1': + """ + Return a new client for the Firewall rules 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 Firewall rules 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) + + + ######################### + # Firewall rules + ######################### + + + def list_all_firewall_rules(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + List all firewall rules for a zone. + + List all firewall rules 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 firewall + rules 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 `ListFirewallRulesResp` 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_firewall_rules') + 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}/firewall/rules'.format(**path_param_dict) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def create_firewall_rules(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + *, + firewall_rule_input_with_filter_id: List['FirewallRuleInputWithFilterId'] = None, + **kwargs + ) -> DetailedResponse: + """ + Create firewall rules for a zone. + + Create new firewall rules 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 firewall + rules are created. + :param List[FirewallRuleInputWithFilterId] + firewall_rule_input_with_filter_id: (optional) Json objects which are used + to create firewall rules. + :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 `FirewallRulesResp` 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 firewall_rule_input_with_filter_id is not None: + firewall_rule_input_with_filter_id = [convert_model(x) for x in firewall_rule_input_with_filter_id] + 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_firewall_rules') + headers.update(sdk_headers) + + data = json.dumps(firewall_rule_input_with_filter_id) + 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}/firewall/rules'.format(**path_param_dict) + request = self.prepare_request(method='POST', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def update_firewll_rules(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + *, + firewall_rules_update_input_item: List['FirewallRulesUpdateInputItem'] = None, + **kwargs + ) -> DetailedResponse: + """ + Update firewall rules. + + Update existing firewall rules 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[FirewallRulesUpdateInputItem] firewall_rules_update_input_item: + (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 `FirewallRulesResp` 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 firewall_rules_update_input_item is not None: + firewall_rules_update_input_item = [convert_model(x) for x in firewall_rules_update_input_item] + 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_firewll_rules') + headers.update(sdk_headers) + + data = json.dumps(firewall_rules_update_input_item) + 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}/firewall/rules'.format(**path_param_dict) + request = self.prepare_request(method='PUT', + url=url, + headers=headers, + data=data) + + response = self.send(request) + return response + + + def delete_firewall_rules(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + id: str, + **kwargs + ) -> DetailedResponse: + """ + Delete firewall rules. + + Delete firewall rules 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 firewall rules are to + be deleted. + :param str id: ids of firewall rules 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 `DeleteFirewallRulesResp` 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_firewall_rules') + 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}/firewall/rules'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers, + params=params) + + response = self.send(request) + return response + + + def delete_firewall_rule(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + firewall_rule_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + Delete a firewall rule. + + Delete a firewall rule 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 firewall rule is to be + deleted. + :param str firewall_rule_identifier: Identifier of the firewall rule 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 `DeleteFirewallRuleResp` 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 firewall_rule_identifier is None: + raise ValueError('firewall_rule_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_firewall_rule') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'firewall_rule_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, firewall_rule_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/firewall/rules/{firewall_rule_identifier}'.format(**path_param_dict) + request = self.prepare_request(method='DELETE', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def get_firewall_rule(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + firewall_rule_identifier: str, + **kwargs + ) -> DetailedResponse: + """ + Get firewall rule details by id. + + Get the details of a firewall rule 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 firewall_rule_identifier: Identifier of firewall rule 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 `FirewallRuleResp` 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 firewall_rule_identifier is None: + raise ValueError('firewall_rule_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_firewall_rule') + headers.update(sdk_headers) + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + headers['Accept'] = 'application/json' + + path_param_keys = ['crn', 'zone_identifier', 'firewall_rule_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, firewall_rule_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/firewall/rules/{firewall_rule_identifier}'.format(**path_param_dict) + request = self.prepare_request(method='GET', + url=url, + headers=headers) + + response = self.send(request) + return response + + + def update_firewall_rule(self, + x_auth_user_token: str, + crn: str, + zone_identifier: str, + firewall_rule_identifier: str, + *, + action: str = None, + paused: bool = None, + description: str = None, + filter: 'FirewallRuleUpdateInputFilter' = None, + **kwargs + ) -> DetailedResponse: + """ + Update a firewall rule. + + Update an existing firewall rule 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 firewall_rule_identifier: Identifier of firewall rule. + :param str action: (optional) The firewall action to perform, "log" action + is only available for enterprise plan instances. + :param bool paused: (optional) Indicates if the firewall rule is active. + :param str description: (optional) To briefly describe the firewall rule, + omitted from object if empty. + :param FirewallRuleUpdateInputFilter filter: (optional) An existing filter. + :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 `FirewallRuleResp` 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 firewall_rule_identifier is None: + raise ValueError('firewall_rule_identifier must be provided') + if filter is not None: + filter = convert_model(filter) + 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_firewall_rule') + headers.update(sdk_headers) + + data = { + 'action': action, + 'paused': paused, + 'description': description, + 'filter': filter + } + 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', 'firewall_rule_identifier'] + path_param_values = self.encode_path_vars(crn, zone_identifier, firewall_rule_identifier) + path_param_dict = dict(zip(path_param_keys, path_param_values)) + url = '/v1/{crn}/zones/{zone_identifier}/firewall/rules/{firewall_rule_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 DeleteFirewallRuleRespResult(): + """ + Container for response information. + + :attr str id: Identifier of the firewall rule. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a DeleteFirewallRuleRespResult object. + + :param str id: Identifier of the firewall rule. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFirewallRuleRespResult': + """Initialize a DeleteFirewallRuleRespResult object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in DeleteFirewallRuleRespResult JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFirewallRuleRespResult 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 DeleteFirewallRuleRespResult object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFirewallRuleRespResult') -> 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: 'DeleteFirewallRuleRespResult') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFirewallRulesRespResultItem(): + """ + DeleteFirewallRulesRespResultItem. + + :attr str id: Identifier of firewall rules. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a DeleteFirewallRulesRespResultItem object. + + :param str id: Identifier of firewall rules. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFirewallRulesRespResultItem': + """Initialize a DeleteFirewallRulesRespResultItem object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in DeleteFirewallRulesRespResultItem JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFirewallRulesRespResultItem 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 DeleteFirewallRulesRespResultItem object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFirewallRulesRespResultItem') -> 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: 'DeleteFirewallRulesRespResultItem') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRuleInputWithFilterIdFilter(): + """ + An existing filter. + + :attr str id: Identifier of the filter. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a FirewallRuleInputWithFilterIdFilter object. + + :param str id: Identifier of the filter. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleInputWithFilterIdFilter': + """Initialize a FirewallRuleInputWithFilterIdFilter object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRuleInputWithFilterIdFilter JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleInputWithFilterIdFilter 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 FirewallRuleInputWithFilterIdFilter object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleInputWithFilterIdFilter') -> 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: 'FirewallRuleInputWithFilterIdFilter') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRuleObjectFilter(): + """ + An existing filter. + + :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. + """ + + def __init__(self, + id: str, + paused: bool, + description: str, + expression: str) -> None: + """ + Initialize a FirewallRuleObjectFilter 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. + """ + self.id = id + self.paused = paused + self.description = description + self.expression = expression + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleObjectFilter': + """Initialize a FirewallRuleObjectFilter object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRuleObjectFilter JSON') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + else: + raise ValueError('Required property \'paused\' not present in FirewallRuleObjectFilter JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + else: + raise ValueError('Required property \'description\' not present in FirewallRuleObjectFilter JSON') + if 'expression' in _dict: + args['expression'] = _dict.get('expression') + else: + raise ValueError('Required property \'expression\' not present in FirewallRuleObjectFilter JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleObjectFilter 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 + 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 FirewallRuleObjectFilter object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleObjectFilter') -> 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: 'FirewallRuleObjectFilter') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRuleUpdateInputFilter(): + """ + An existing filter. + + :attr str id: Identifier of the filter. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a FirewallRuleUpdateInputFilter object. + + :param str id: Identifier of the filter. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleUpdateInputFilter': + """Initialize a FirewallRuleUpdateInputFilter object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRuleUpdateInputFilter JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleUpdateInputFilter 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 FirewallRuleUpdateInputFilter object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleUpdateInputFilter') -> 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: 'FirewallRuleUpdateInputFilter') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRulesUpdateInputItem(): + """ + FirewallRulesUpdateInputItem. + + :attr str id: Identifier of the firewall rule. + :attr str action: The firewall action to perform, "log" action is only available + for enterprise plan instances. + :attr bool paused: (optional) Indicates if the firewall rule is active. + :attr str description: (optional) To briefly describe the firewall rule, omitted + from object if empty. + :attr FirewallRulesUpdateInputItemFilter filter: (optional) An existing filter. + """ + + def __init__(self, + id: str, + action: str, + *, + paused: bool = None, + description: str = None, + filter: 'FirewallRulesUpdateInputItemFilter' = None) -> None: + """ + Initialize a FirewallRulesUpdateInputItem object. + + :param str id: Identifier of the firewall rule. + :param str action: The firewall action to perform, "log" action is only + available for enterprise plan instances. + :param bool paused: (optional) Indicates if the firewall rule is active. + :param str description: (optional) To briefly describe the firewall rule, + omitted from object if empty. + :param FirewallRulesUpdateInputItemFilter filter: (optional) An existing + filter. + """ + self.id = id + self.action = action + self.paused = paused + self.description = description + self.filter = filter + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRulesUpdateInputItem': + """Initialize a FirewallRulesUpdateInputItem object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRulesUpdateInputItem JSON') + if 'action' in _dict: + args['action'] = _dict.get('action') + else: + raise ValueError('Required property \'action\' not present in FirewallRulesUpdateInputItem JSON') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + if 'description' in _dict: + args['description'] = _dict.get('description') + if 'filter' in _dict: + args['filter'] = FirewallRulesUpdateInputItemFilter.from_dict(_dict.get('filter')) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRulesUpdateInputItem 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, 'action') and self.action is not None: + _dict['action'] = self.action + 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, 'filter') and self.filter is not None: + _dict['filter'] = self.filter.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 FirewallRulesUpdateInputItem object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRulesUpdateInputItem') -> 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: 'FirewallRulesUpdateInputItem') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ActionEnum(str, Enum): + """ + The firewall action to perform, "log" action is only available for enterprise plan + instances. + """ + LOG = 'log' + ALLOW = 'allow' + CHALLENGE = 'challenge' + JS_CHALLENGE = 'js_challenge' + BLOCK = 'block' + + +class FirewallRulesUpdateInputItemFilter(): + """ + An existing filter. + + :attr str id: Identifier of the filter. + """ + + def __init__(self, + id: str) -> None: + """ + Initialize a FirewallRulesUpdateInputItemFilter object. + + :param str id: Identifier of the filter. + """ + self.id = id + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRulesUpdateInputItemFilter': + """Initialize a FirewallRulesUpdateInputItemFilter object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRulesUpdateInputItemFilter JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRulesUpdateInputItemFilter 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 FirewallRulesUpdateInputItemFilter object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRulesUpdateInputItemFilter') -> 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: 'FirewallRulesUpdateInputItemFilter') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListFirewallRulesRespResultInfo(): + """ + 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 ListFirewallRulesRespResultInfo 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) -> 'ListFirewallRulesRespResultInfo': + """Initialize a ListFirewallRulesRespResultInfo object from a json dictionary.""" + args = {} + if 'page' in _dict: + args['page'] = _dict.get('page') + else: + raise ValueError('Required property \'page\' not present in ListFirewallRulesRespResultInfo JSON') + if 'per_page' in _dict: + args['per_page'] = _dict.get('per_page') + else: + raise ValueError('Required property \'per_page\' not present in ListFirewallRulesRespResultInfo JSON') + if 'count' in _dict: + args['count'] = _dict.get('count') + else: + raise ValueError('Required property \'count\' not present in ListFirewallRulesRespResultInfo JSON') + if 'total_count' in _dict: + args['total_count'] = _dict.get('total_count') + else: + raise ValueError('Required property \'total_count\' not present in ListFirewallRulesRespResultInfo JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListFirewallRulesRespResultInfo 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 ListFirewallRulesRespResultInfo object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListFirewallRulesRespResultInfo') -> 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: 'ListFirewallRulesRespResultInfo') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFirewallRuleResp(): + """ + DeleteFirewallRuleResp. + + :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 DeleteFirewallRuleRespResult result: Container for response information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'DeleteFirewallRuleRespResult') -> None: + """ + Initialize a DeleteFirewallRuleResp 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 DeleteFirewallRuleRespResult result: Container for response + information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFirewallRuleResp': + """Initialize a DeleteFirewallRuleResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in DeleteFirewallRuleResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in DeleteFirewallRuleResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in DeleteFirewallRuleResp JSON') + if 'result' in _dict: + args['result'] = DeleteFirewallRuleRespResult.from_dict(_dict.get('result')) + else: + raise ValueError('Required property \'result\' not present in DeleteFirewallRuleResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFirewallRuleResp 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 DeleteFirewallRuleResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFirewallRuleResp') -> 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: 'DeleteFirewallRuleResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class DeleteFirewallRulesResp(): + """ + DeleteFirewallRulesResp. + + :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[DeleteFirewallRulesRespResultItem] result: Container for response + information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['DeleteFirewallRulesRespResultItem']) -> None: + """ + Initialize a DeleteFirewallRulesResp 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[DeleteFirewallRulesRespResultItem] result: Container for + response information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DeleteFirewallRulesResp': + """Initialize a DeleteFirewallRulesResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in DeleteFirewallRulesResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in DeleteFirewallRulesResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in DeleteFirewallRulesResp JSON') + if 'result' in _dict: + args['result'] = [DeleteFirewallRulesRespResultItem.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in DeleteFirewallRulesResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DeleteFirewallRulesResp 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 DeleteFirewallRulesResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DeleteFirewallRulesResp') -> 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: 'DeleteFirewallRulesResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRuleInputWithFilterId(): + """ + Json objects which are used to create firewall rule. + + :attr FirewallRuleInputWithFilterIdFilter filter: An existing filter. + :attr str action: The firewall action to perform, "log" action is only available + for enterprise plan instances. + :attr str description: (optional) To briefly describe the firewall rule, omitted + from object if empty. + """ + + def __init__(self, + filter: 'FirewallRuleInputWithFilterIdFilter', + action: str, + *, + description: str = None) -> None: + """ + Initialize a FirewallRuleInputWithFilterId object. + + :param FirewallRuleInputWithFilterIdFilter filter: An existing filter. + :param str action: The firewall action to perform, "log" action is only + available for enterprise plan instances. + :param str description: (optional) To briefly describe the firewall rule, + omitted from object if empty. + """ + self.filter = filter + self.action = action + self.description = description + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleInputWithFilterId': + """Initialize a FirewallRuleInputWithFilterId object from a json dictionary.""" + args = {} + if 'filter' in _dict: + args['filter'] = FirewallRuleInputWithFilterIdFilter.from_dict(_dict.get('filter')) + else: + raise ValueError('Required property \'filter\' not present in FirewallRuleInputWithFilterId JSON') + if 'action' in _dict: + args['action'] = _dict.get('action') + else: + raise ValueError('Required property \'action\' not present in FirewallRuleInputWithFilterId JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleInputWithFilterId 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, 'filter') and self.filter is not None: + _dict['filter'] = self.filter.to_dict() + if hasattr(self, 'action') and self.action is not None: + _dict['action'] = self.action + 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 FirewallRuleInputWithFilterId object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleInputWithFilterId') -> 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: 'FirewallRuleInputWithFilterId') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ActionEnum(str, Enum): + """ + The firewall action to perform, "log" action is only available for enterprise plan + instances. + """ + LOG = 'log' + ALLOW = 'allow' + CHALLENGE = 'challenge' + JS_CHALLENGE = 'js_challenge' + BLOCK = 'block' + + +class FirewallRuleObject(): + """ + FirewallRuleObject. + + :attr str id: Identifier of the firewall rule. + :attr bool paused: Indicates if the firewall rule is active. + :attr str description: To briefly describe the firewall rule, omitted from + object if empty. + :attr str action: The firewall action to perform, "log" action is only available + for enterprise plan instances. + :attr FirewallRuleObjectFilter filter: An existing filter. + :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, + action: str, + filter: 'FirewallRuleObjectFilter', + created_on: str, + modified_on: str) -> None: + """ + Initialize a FirewallRuleObject object. + + :param str id: Identifier of the firewall rule. + :param bool paused: Indicates if the firewall rule is active. + :param str description: To briefly describe the firewall rule, omitted from + object if empty. + :param str action: The firewall action to perform, "log" action is only + available for enterprise plan instances. + :param FirewallRuleObjectFilter filter: An existing filter. + :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.action = action + self.filter = filter + self.created_on = created_on + self.modified_on = modified_on + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleObject': + """Initialize a FirewallRuleObject object from a json dictionary.""" + args = {} + if 'id' in _dict: + args['id'] = _dict.get('id') + else: + raise ValueError('Required property \'id\' not present in FirewallRuleObject JSON') + if 'paused' in _dict: + args['paused'] = _dict.get('paused') + else: + raise ValueError('Required property \'paused\' not present in FirewallRuleObject JSON') + if 'description' in _dict: + args['description'] = _dict.get('description') + else: + raise ValueError('Required property \'description\' not present in FirewallRuleObject JSON') + if 'action' in _dict: + args['action'] = _dict.get('action') + else: + raise ValueError('Required property \'action\' not present in FirewallRuleObject JSON') + if 'filter' in _dict: + args['filter'] = FirewallRuleObjectFilter.from_dict(_dict.get('filter')) + else: + raise ValueError('Required property \'filter\' not present in FirewallRuleObject JSON') + if 'created_on' in _dict: + args['created_on'] = _dict.get('created_on') + else: + raise ValueError('Required property \'created_on\' not present in FirewallRuleObject JSON') + if 'modified_on' in _dict: + args['modified_on'] = _dict.get('modified_on') + else: + raise ValueError('Required property \'modified_on\' not present in FirewallRuleObject JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleObject 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, 'action') and self.action is not None: + _dict['action'] = self.action + if hasattr(self, 'filter') and self.filter is not None: + _dict['filter'] = self.filter.to_dict() + 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 FirewallRuleObject object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleObject') -> 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: 'FirewallRuleObject') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class ActionEnum(str, Enum): + """ + The firewall action to perform, "log" action is only available for enterprise plan + instances. + """ + LOG = 'log' + ALLOW = 'allow' + CHALLENGE = 'challenge' + JS_CHALLENGE = 'js_challenge' + BLOCK = 'block' + + +class FirewallRuleResp(): + """ + FirewallRuleResp. + + :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 FirewallRuleObject result: + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: 'FirewallRuleObject') -> None: + """ + Initialize a FirewallRuleResp 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 FirewallRuleObject result: + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRuleResp': + """Initialize a FirewallRuleResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in FirewallRuleResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in FirewallRuleResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in FirewallRuleResp JSON') + if 'result' in _dict: + args['result'] = FirewallRuleObject.from_dict(_dict.get('result')) + else: + raise ValueError('Required property \'result\' not present in FirewallRuleResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRuleResp 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 FirewallRuleResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRuleResp') -> 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: 'FirewallRuleResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class FirewallRulesResp(): + """ + FirewallRulesResp. + + :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[FirewallRuleObject] result: Container for response information. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['FirewallRuleObject']) -> None: + """ + Initialize a FirewallRulesResp 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[FirewallRuleObject] result: Container for response information. + """ + self.success = success + self.errors = errors + self.messages = messages + self.result = result + + @classmethod + def from_dict(cls, _dict: Dict) -> 'FirewallRulesResp': + """Initialize a FirewallRulesResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in FirewallRulesResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in FirewallRulesResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in FirewallRulesResp JSON') + if 'result' in _dict: + args['result'] = [FirewallRuleObject.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in FirewallRulesResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a FirewallRulesResp 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 FirewallRulesResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'FirewallRulesResp') -> 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: 'FirewallRulesResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + +class ListFirewallRulesResp(): + """ + ListFirewallRulesResp. + + :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[FirewallRuleObject] result: Container for response information. + :attr ListFirewallRulesRespResultInfo result_info: Statistics of results. + """ + + def __init__(self, + success: bool, + errors: List[List[str]], + messages: List[List[str]], + result: List['FirewallRuleObject'], + result_info: 'ListFirewallRulesRespResultInfo') -> None: + """ + Initialize a ListFirewallRulesResp 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[FirewallRuleObject] result: Container for response information. + :param ListFirewallRulesRespResultInfo 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) -> 'ListFirewallRulesResp': + """Initialize a ListFirewallRulesResp object from a json dictionary.""" + args = {} + if 'success' in _dict: + args['success'] = _dict.get('success') + else: + raise ValueError('Required property \'success\' not present in ListFirewallRulesResp JSON') + if 'errors' in _dict: + args['errors'] = _dict.get('errors') + else: + raise ValueError('Required property \'errors\' not present in ListFirewallRulesResp JSON') + if 'messages' in _dict: + args['messages'] = _dict.get('messages') + else: + raise ValueError('Required property \'messages\' not present in ListFirewallRulesResp JSON') + if 'result' in _dict: + args['result'] = [FirewallRuleObject.from_dict(x) for x in _dict.get('result')] + else: + raise ValueError('Required property \'result\' not present in ListFirewallRulesResp JSON') + if 'result_info' in _dict: + args['result_info'] = ListFirewallRulesRespResultInfo.from_dict(_dict.get('result_info')) + else: + raise ValueError('Required property \'result_info\' not present in ListFirewallRulesResp JSON') + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a ListFirewallRulesResp 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 ListFirewallRulesResp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'ListFirewallRulesResp') -> 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: 'ListFirewallRulesResp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other diff --git a/test/integration/test_firewall_rules_v1.py b/test/integration/test_firewall_rules_v1.py new file mode 100644 index 0000000..c95e22e --- /dev/null +++ b/test/integration/test_firewall_rules_v1.py @@ -0,0 +1,386 @@ +# -*- coding: utf-8 -*- +# (C) Copyright IBM Corp. 2020. + +""" +Integration test code to execute firewall access rules api +""" + +import os +import unittest +from dotenv import load_dotenv, find_dotenv +from ibm_cloud_networking_services import FirewallRulesV1 +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 TestFirewallRules(unittest.TestCase): + """ Test class to call Firewall Access Rules API functions """ + + def setUp(self): + 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") + self.rule = FirewallRulesV1.new_instance(service_name='cis_services') + self.service = FiltersV1.new_instance( + service_name="cis_services") + self.service.set_service_url(self.endpoint) + self.rule.set_service_url(self.endpoint) + self._clean_firewall_rules() + self._clean_filters() + + def tearDown(self): + """ tear down """ + # Delete the resources + print("Clean up complete") + + def _clean_firewall_rules(self): + # list all rules + resp = self.rule.list_all_firewall_rules(x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id) + assert resp is not None + assert resp.status_code == 200 + # rules = {} + resp = resp.get_result().get("result"); + for record in resp: + # delete rule + self.rule.delete_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + id=record.get("id") + ) + 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): + 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 + + def test_1_create_firewall_rule_mode_action(self): + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token = self.x_auth_user_token, + crn = self.crn, + zone_identifier = self.zone_id, + firewall_rule_input_with_filter_id = firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + def test_1_list_firewall_rules_mode_action(self): + + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + resp = self.rule.list_all_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + def test_1_update_firewall_rules_mode_action(self): + + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + filter_id = resp.get_result()['result'][0]['filter']['id'] + firewall_id = resp.get_result().get("result")[0]["id"] + + firewall_rule_update_filter_model = {} + firewall_rule_update_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_update = {} + firewall_rule_update["id"] = firewall_id + firewall_rule_update['action'] = 'js_challenge' + firewall_rule_update['paused'] = False + firewall_rule_update['description'] = 'JS challenge site for firewall' + firewall_rule_update["filter"] = firewall_rule_update_filter_model + firewall_rule_update_with_filter_id = [firewall_rule_update] + resp = self.rule.update_firewll_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rules_update_input_item=firewall_rule_update_with_filter_id, + ) + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + assert resp.get_result()['result'][0]['description'] == firewall_rule_update_with_filter_id[0]['description'] + + def test_1_delete_firewall_rules_mode_action(self): + + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + firewall_id = resp.get_result().get("result")[0]["id"] + + resp = self.rule.delete_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + id=firewall_id, + ) + assert resp is not None + assert resp.status_code == 200 + + resp = self.rule.list_all_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + assert resp is not None + assert resp.status_code == 200 + assert len(resp.get_result().get("result")) == 0 + + def test_1_delete_firewall_rule_mode_action(self): + + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + firewall_id = resp.get_result().get("result")[0]["id"] + + resp = self.rule.delete_firewall_rule( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_identifier=firewall_id, + ) + assert resp is not None + assert resp.status_code == 200 + + resp = self.rule.list_all_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + assert resp is not None + assert resp.status_code == 200 + assert len(resp.get_result().get("result")) == 0 + + def test_1_get_firewall_rule_mode_action(self): + + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + + firewall_id = resp.get_result().get("result")[0]["id"] + + resp = self.rule.get_firewall_rule( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_identifier=firewall_id, + ) + assert resp is not None + assert resp.status_code == 200 + get_firewall_id = resp.get_result()['result']['id'] + assert get_firewall_id == firewall_id + assert resp.get_result()['result']['action'] == 'js_challenge' + + def test_1_update_firewall_rule_mode_action(self): + # Construct a dict representation of a FirewallRuleInputWithFilterIdFilter model + filter_id = self._create_filter(expression='not http.request.uri.path matches "^/test/.*$"', + description='not /test') + firewall_rule_input_filter_model = {} + firewall_rule_input_filter_model['id'] = filter_id + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input = {} + firewall_rule_input["filter"] = firewall_rule_input_filter_model + firewall_rule_input['action'] = 'js_challenge' + firewall_rule_input['description'] = 'JS challenge site' + firewall_rule_input_with_filter_id = [firewall_rule_input] + + resp = self.rule.create_firewall_rules( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + ) + + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result().get("result")[0]["id"] is not None + filter_id = resp.get_result()['result'][0]['filter']['id'] + firewall_id = resp.get_result().get("result")[0]["id"] + firewall_rule_update_filter_model = {} + firewall_rule_update_filter_model['id'] = filter_id + resp = self.rule.update_firewall_rule( + x_auth_user_token=self.x_auth_user_token, + crn=self.crn, + zone_identifier=self.zone_id, + firewall_rule_identifier=firewall_id, + action = "js_challenge", + paused = False, + description = "Update firewall rule", + filter = firewall_rule_update_filter_model + ) + assert resp is not None + assert resp.status_code == 200 + assert resp.get_result()['result']['description'] == 'Update firewall rule' + assert resp.get_result()['result']['id'] == firewall_id + +if __name__ == '__main__': + unittest.main() diff --git a/test/unit/test_firewall_rules_v1.py b/test/unit/test_firewall_rules_v1.py new file mode 100644 index 0000000..fa7c311 --- /dev/null +++ b/test/unit/test_firewall_rules_v1.py @@ -0,0 +1,1325 @@ +# -*- 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 FirewallRulesV1 +""" + +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.firewall_rules_v1 import * + + +_service = FirewallRulesV1( + authenticator=NoAuthAuthenticator() + ) + +_base_url = 'https://api.cis.cloud.ibm.com' +_service.set_service_url(_base_url) + +############################################################################## +# Start of Service: FirewallRules +############################################################################## +# region + +class TestListAllFirewallRules(): + """ + Test Class for list_all_firewall_rules + """ + + 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_firewall_rules_all_params(self): + """ + list_all_firewall_rules() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewall_rules( + 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_firewall_rules_value_error(self): + """ + test_list_all_firewall_rules_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewall_rules(**req_copy) + + + +class TestCreateFirewallRules(): + """ + Test Class for create_firewall_rules + """ + + 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_firewall_rules_all_params(self): + """ + create_firewall_rules() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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 FirewallRuleInputWithFilterIdFilter model + firewall_rule_input_with_filter_id_filter_model = {} + firewall_rule_input_with_filter_id_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a dict representation of a FirewallRuleInputWithFilterId model + firewall_rule_input_with_filter_id_model = {} + firewall_rule_input_with_filter_id_model['filter'] = firewall_rule_input_with_filter_id_filter_model + firewall_rule_input_with_filter_id_model['action'] = 'js_challenge' + firewall_rule_input_with_filter_id_model['description'] = 'JS challenge site' + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + firewall_rule_input_with_filter_id = [firewall_rule_input_with_filter_id_model] + + # Invoke method + response = _service.create_firewall_rules( + x_auth_user_token, + crn, + zone_identifier, + firewall_rule_input_with_filter_id=firewall_rule_input_with_filter_id, + 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 == firewall_rule_input_with_filter_id + + + @responses.activate + def test_create_firewall_rules_required_params(self): + """ + test_create_firewall_rules_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewall_rules( + 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_firewall_rules_value_error(self): + """ + test_create_firewall_rules_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewall_rules(**req_copy) + + + +class TestUpdateFirewllRules(): + """ + Test Class for update_firewll_rules + """ + + 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_firewll_rules_all_params(self): + """ + update_firewll_rules() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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 FirewallRulesUpdateInputItemFilter model + firewall_rules_update_input_item_filter_model = {} + firewall_rules_update_input_item_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a dict representation of a FirewallRulesUpdateInputItem model + firewall_rules_update_input_item_model = {} + firewall_rules_update_input_item_model['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rules_update_input_item_model['action'] = 'js_challenge' + firewall_rules_update_input_item_model['paused'] = False + firewall_rules_update_input_item_model['description'] = 'JS challenge site' + firewall_rules_update_input_item_model['filter'] = firewall_rules_update_input_item_filter_model + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + firewall_rules_update_input_item = [firewall_rules_update_input_item_model] + + # Invoke method + response = _service.update_firewll_rules( + x_auth_user_token, + crn, + zone_identifier, + firewall_rules_update_input_item=firewall_rules_update_input_item, + 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 == firewall_rules_update_input_item + + + @responses.activate + def test_update_firewll_rules_required_params(self): + """ + test_update_firewll_rules_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewll_rules( + 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_firewll_rules_value_error(self): + """ + test_update_firewll_rules_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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_firewll_rules(**req_copy) + + + +class TestDeleteFirewallRules(): + """ + Test Class for delete_firewall_rules + """ + + 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_firewall_rules_all_params(self): + """ + delete_firewall_rules() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "f2d427378e7542acb295380d352e2ebd"}]}' + 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 = 'f2d427378e7542acb295380d352e2ebd' + + # Invoke method + response = _service.delete_firewall_rules( + 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_firewall_rules_value_error(self): + """ + test_delete_firewall_rules_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": [{"id": "f2d427378e7542acb295380d352e2ebd"}]}' + 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 = 'f2d427378e7542acb295380d352e2ebd' + + # 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_firewall_rules(**req_copy) + + + +class TestDeleteFirewallRule(): + """ + Test Class for delete_firewall_rule + """ + + 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_firewall_rule_all_params(self): + """ + delete_firewall_rule() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f2d427378e7542acb295380d352e2ebd"}}' + 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' + firewall_rule_identifier = 'testString' + + # Invoke method + response = _service.delete_firewall_rule( + x_auth_user_token, + crn, + zone_identifier, + firewall_rule_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_delete_firewall_rule_value_error(self): + """ + test_delete_firewall_rule_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "f2d427378e7542acb295380d352e2ebd"}}' + 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' + firewall_rule_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, + "firewall_rule_identifier": firewall_rule_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_firewall_rule(**req_copy) + + + +class TestGetFirewallRule(): + """ + Test Class for get_firewall_rule + """ + + 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_firewall_rule_all_params(self): + """ + get_firewall_rule() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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' + firewall_rule_identifier = 'testString' + + # Invoke method + response = _service.get_firewall_rule( + x_auth_user_token, + crn, + zone_identifier, + firewall_rule_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_get_firewall_rule_value_error(self): + """ + test_get_firewall_rule_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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' + firewall_rule_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, + "firewall_rule_identifier": firewall_rule_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_firewall_rule(**req_copy) + + + +class TestUpdateFirewallRule(): + """ + Test Class for update_firewall_rule + """ + + 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_firewall_rule_all_params(self): + """ + update_firewall_rule() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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 FirewallRuleUpdateInputFilter model + firewall_rule_update_input_filter_model = {} + firewall_rule_update_input_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Set up parameter values + x_auth_user_token = 'testString' + crn = 'testString' + zone_identifier = 'testString' + firewall_rule_identifier = 'testString' + action = 'js_challenge' + paused = False + description = 'JS challenge site' + filter = firewall_rule_update_input_filter_model + + # Invoke method + response = _service.update_firewall_rule( + x_auth_user_token, + crn, + zone_identifier, + firewall_rule_identifier, + action=action, + paused=paused, + description=description, + filter=filter, + 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['action'] == 'js_challenge' + assert req_body['paused'] == False + assert req_body['description'] == 'JS challenge site' + assert req_body['filter'] == firewall_rule_update_input_filter_model + + + @responses.activate + def test_update_firewall_rule_required_params(self): + """ + test_update_firewall_rule_required_params() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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' + firewall_rule_identifier = 'testString' + + # Invoke method + response = _service.update_firewall_rule( + x_auth_user_token, + crn, + zone_identifier, + firewall_rule_identifier, + headers={} + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + + + @responses.activate + def test_update_firewall_rule_value_error(self): + """ + test_update_firewall_rule_value_error() + """ + # Set up mock + url = self.preprocess_url(_base_url + '/v1/testString/zones/testString/firewall/rules/testString') + mock_response = '{"success": true, "errors": [["errors"]], "messages": [["messages"]], "result": {"id": "52161eb6af4241bb9d4b32394be72fdf", "paused": false, "description": "JS challenge site", "action": "js_challenge", "filter": {"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": "2019-01-01T05:20:00.123Z", "modified_on": "2019-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' + firewall_rule_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, + "firewall_rule_identifier": firewall_rule_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_firewall_rule(**req_copy) + + + +# endregion +############################################################################## +# End of Service: FirewallRules +############################################################################## + + +############################################################################## +# Start of Model Tests +############################################################################## +# region +class TestDeleteFirewallRuleRespResult(): + """ + Test Class for DeleteFirewallRuleRespResult + """ + + def test_delete_firewall_rule_resp_result_serialization(self): + """ + Test serialization/deserialization for DeleteFirewallRuleRespResult + """ + + # Construct a json representation of a DeleteFirewallRuleRespResult model + delete_firewall_rule_resp_result_model_json = {} + delete_firewall_rule_resp_result_model_json['id'] = 'f2d427378e7542acb295380d352e2ebd' + + # Construct a model instance of DeleteFirewallRuleRespResult by calling from_dict on the json representation + delete_firewall_rule_resp_result_model = DeleteFirewallRuleRespResult.from_dict(delete_firewall_rule_resp_result_model_json) + assert delete_firewall_rule_resp_result_model != False + + # Construct a model instance of DeleteFirewallRuleRespResult by calling from_dict on the json representation + delete_firewall_rule_resp_result_model_dict = DeleteFirewallRuleRespResult.from_dict(delete_firewall_rule_resp_result_model_json).__dict__ + delete_firewall_rule_resp_result_model2 = DeleteFirewallRuleRespResult(**delete_firewall_rule_resp_result_model_dict) + + # Verify the model instances are equivalent + assert delete_firewall_rule_resp_result_model == delete_firewall_rule_resp_result_model2 + + # Convert model instance back to dict and verify no loss of data + delete_firewall_rule_resp_result_model_json2 = delete_firewall_rule_resp_result_model.to_dict() + assert delete_firewall_rule_resp_result_model_json2 == delete_firewall_rule_resp_result_model_json + +class TestDeleteFirewallRulesRespResultItem(): + """ + Test Class for DeleteFirewallRulesRespResultItem + """ + + def test_delete_firewall_rules_resp_result_item_serialization(self): + """ + Test serialization/deserialization for DeleteFirewallRulesRespResultItem + """ + + # Construct a json representation of a DeleteFirewallRulesRespResultItem model + delete_firewall_rules_resp_result_item_model_json = {} + delete_firewall_rules_resp_result_item_model_json['id'] = 'f2d427378e7542acb295380d352e2ebd' + + # Construct a model instance of DeleteFirewallRulesRespResultItem by calling from_dict on the json representation + delete_firewall_rules_resp_result_item_model = DeleteFirewallRulesRespResultItem.from_dict(delete_firewall_rules_resp_result_item_model_json) + assert delete_firewall_rules_resp_result_item_model != False + + # Construct a model instance of DeleteFirewallRulesRespResultItem by calling from_dict on the json representation + delete_firewall_rules_resp_result_item_model_dict = DeleteFirewallRulesRespResultItem.from_dict(delete_firewall_rules_resp_result_item_model_json).__dict__ + delete_firewall_rules_resp_result_item_model2 = DeleteFirewallRulesRespResultItem(**delete_firewall_rules_resp_result_item_model_dict) + + # Verify the model instances are equivalent + assert delete_firewall_rules_resp_result_item_model == delete_firewall_rules_resp_result_item_model2 + + # Convert model instance back to dict and verify no loss of data + delete_firewall_rules_resp_result_item_model_json2 = delete_firewall_rules_resp_result_item_model.to_dict() + assert delete_firewall_rules_resp_result_item_model_json2 == delete_firewall_rules_resp_result_item_model_json + +class TestFirewallRuleInputWithFilterIdFilter(): + """ + Test Class for FirewallRuleInputWithFilterIdFilter + """ + + def test_firewall_rule_input_with_filter_id_filter_serialization(self): + """ + Test serialization/deserialization for FirewallRuleInputWithFilterIdFilter + """ + + # Construct a json representation of a FirewallRuleInputWithFilterIdFilter model + firewall_rule_input_with_filter_id_filter_model_json = {} + firewall_rule_input_with_filter_id_filter_model_json['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a model instance of FirewallRuleInputWithFilterIdFilter by calling from_dict on the json representation + firewall_rule_input_with_filter_id_filter_model = FirewallRuleInputWithFilterIdFilter.from_dict(firewall_rule_input_with_filter_id_filter_model_json) + assert firewall_rule_input_with_filter_id_filter_model != False + + # Construct a model instance of FirewallRuleInputWithFilterIdFilter by calling from_dict on the json representation + firewall_rule_input_with_filter_id_filter_model_dict = FirewallRuleInputWithFilterIdFilter.from_dict(firewall_rule_input_with_filter_id_filter_model_json).__dict__ + firewall_rule_input_with_filter_id_filter_model2 = FirewallRuleInputWithFilterIdFilter(**firewall_rule_input_with_filter_id_filter_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_input_with_filter_id_filter_model == firewall_rule_input_with_filter_id_filter_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_input_with_filter_id_filter_model_json2 = firewall_rule_input_with_filter_id_filter_model.to_dict() + assert firewall_rule_input_with_filter_id_filter_model_json2 == firewall_rule_input_with_filter_id_filter_model_json + +class TestFirewallRuleObjectFilter(): + """ + Test Class for FirewallRuleObjectFilter + """ + + def test_firewall_rule_object_filter_serialization(self): + """ + Test serialization/deserialization for FirewallRuleObjectFilter + """ + + # Construct a json representation of a FirewallRuleObjectFilter model + firewall_rule_object_filter_model_json = {} + firewall_rule_object_filter_model_json['id'] = '6f58318e7fa2477a23112e8118c66f61' + firewall_rule_object_filter_model_json['paused'] = True + firewall_rule_object_filter_model_json['description'] = 'Login from office' + firewall_rule_object_filter_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$\")' + + # Construct a model instance of FirewallRuleObjectFilter by calling from_dict on the json representation + firewall_rule_object_filter_model = FirewallRuleObjectFilter.from_dict(firewall_rule_object_filter_model_json) + assert firewall_rule_object_filter_model != False + + # Construct a model instance of FirewallRuleObjectFilter by calling from_dict on the json representation + firewall_rule_object_filter_model_dict = FirewallRuleObjectFilter.from_dict(firewall_rule_object_filter_model_json).__dict__ + firewall_rule_object_filter_model2 = FirewallRuleObjectFilter(**firewall_rule_object_filter_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_object_filter_model == firewall_rule_object_filter_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_object_filter_model_json2 = firewall_rule_object_filter_model.to_dict() + assert firewall_rule_object_filter_model_json2 == firewall_rule_object_filter_model_json + +class TestFirewallRuleUpdateInputFilter(): + """ + Test Class for FirewallRuleUpdateInputFilter + """ + + def test_firewall_rule_update_input_filter_serialization(self): + """ + Test serialization/deserialization for FirewallRuleUpdateInputFilter + """ + + # Construct a json representation of a FirewallRuleUpdateInputFilter model + firewall_rule_update_input_filter_model_json = {} + firewall_rule_update_input_filter_model_json['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a model instance of FirewallRuleUpdateInputFilter by calling from_dict on the json representation + firewall_rule_update_input_filter_model = FirewallRuleUpdateInputFilter.from_dict(firewall_rule_update_input_filter_model_json) + assert firewall_rule_update_input_filter_model != False + + # Construct a model instance of FirewallRuleUpdateInputFilter by calling from_dict on the json representation + firewall_rule_update_input_filter_model_dict = FirewallRuleUpdateInputFilter.from_dict(firewall_rule_update_input_filter_model_json).__dict__ + firewall_rule_update_input_filter_model2 = FirewallRuleUpdateInputFilter(**firewall_rule_update_input_filter_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_update_input_filter_model == firewall_rule_update_input_filter_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_update_input_filter_model_json2 = firewall_rule_update_input_filter_model.to_dict() + assert firewall_rule_update_input_filter_model_json2 == firewall_rule_update_input_filter_model_json + +class TestFirewallRulesUpdateInputItem(): + """ + Test Class for FirewallRulesUpdateInputItem + """ + + def test_firewall_rules_update_input_item_serialization(self): + """ + Test serialization/deserialization for FirewallRulesUpdateInputItem + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rules_update_input_item_filter_model = {} # FirewallRulesUpdateInputItemFilter + firewall_rules_update_input_item_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a json representation of a FirewallRulesUpdateInputItem model + firewall_rules_update_input_item_model_json = {} + firewall_rules_update_input_item_model_json['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rules_update_input_item_model_json['action'] = 'js_challenge' + firewall_rules_update_input_item_model_json['paused'] = False + firewall_rules_update_input_item_model_json['description'] = 'JS challenge site' + firewall_rules_update_input_item_model_json['filter'] = firewall_rules_update_input_item_filter_model + + # Construct a model instance of FirewallRulesUpdateInputItem by calling from_dict on the json representation + firewall_rules_update_input_item_model = FirewallRulesUpdateInputItem.from_dict(firewall_rules_update_input_item_model_json) + assert firewall_rules_update_input_item_model != False + + # Construct a model instance of FirewallRulesUpdateInputItem by calling from_dict on the json representation + firewall_rules_update_input_item_model_dict = FirewallRulesUpdateInputItem.from_dict(firewall_rules_update_input_item_model_json).__dict__ + firewall_rules_update_input_item_model2 = FirewallRulesUpdateInputItem(**firewall_rules_update_input_item_model_dict) + + # Verify the model instances are equivalent + assert firewall_rules_update_input_item_model == firewall_rules_update_input_item_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rules_update_input_item_model_json2 = firewall_rules_update_input_item_model.to_dict() + assert firewall_rules_update_input_item_model_json2 == firewall_rules_update_input_item_model_json + +class TestFirewallRulesUpdateInputItemFilter(): + """ + Test Class for FirewallRulesUpdateInputItemFilter + """ + + def test_firewall_rules_update_input_item_filter_serialization(self): + """ + Test serialization/deserialization for FirewallRulesUpdateInputItemFilter + """ + + # Construct a json representation of a FirewallRulesUpdateInputItemFilter model + firewall_rules_update_input_item_filter_model_json = {} + firewall_rules_update_input_item_filter_model_json['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a model instance of FirewallRulesUpdateInputItemFilter by calling from_dict on the json representation + firewall_rules_update_input_item_filter_model = FirewallRulesUpdateInputItemFilter.from_dict(firewall_rules_update_input_item_filter_model_json) + assert firewall_rules_update_input_item_filter_model != False + + # Construct a model instance of FirewallRulesUpdateInputItemFilter by calling from_dict on the json representation + firewall_rules_update_input_item_filter_model_dict = FirewallRulesUpdateInputItemFilter.from_dict(firewall_rules_update_input_item_filter_model_json).__dict__ + firewall_rules_update_input_item_filter_model2 = FirewallRulesUpdateInputItemFilter(**firewall_rules_update_input_item_filter_model_dict) + + # Verify the model instances are equivalent + assert firewall_rules_update_input_item_filter_model == firewall_rules_update_input_item_filter_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rules_update_input_item_filter_model_json2 = firewall_rules_update_input_item_filter_model.to_dict() + assert firewall_rules_update_input_item_filter_model_json2 == firewall_rules_update_input_item_filter_model_json + +class TestListFirewallRulesRespResultInfo(): + """ + Test Class for ListFirewallRulesRespResultInfo + """ + + def test_list_firewall_rules_resp_result_info_serialization(self): + """ + Test serialization/deserialization for ListFirewallRulesRespResultInfo + """ + + # Construct a json representation of a ListFirewallRulesRespResultInfo model + list_firewall_rules_resp_result_info_model_json = {} + list_firewall_rules_resp_result_info_model_json['page'] = 1 + list_firewall_rules_resp_result_info_model_json['per_page'] = 2 + list_firewall_rules_resp_result_info_model_json['count'] = 1 + list_firewall_rules_resp_result_info_model_json['total_count'] = 200 + + # Construct a model instance of ListFirewallRulesRespResultInfo by calling from_dict on the json representation + list_firewall_rules_resp_result_info_model = ListFirewallRulesRespResultInfo.from_dict(list_firewall_rules_resp_result_info_model_json) + assert list_firewall_rules_resp_result_info_model != False + + # Construct a model instance of ListFirewallRulesRespResultInfo by calling from_dict on the json representation + list_firewall_rules_resp_result_info_model_dict = ListFirewallRulesRespResultInfo.from_dict(list_firewall_rules_resp_result_info_model_json).__dict__ + list_firewall_rules_resp_result_info_model2 = ListFirewallRulesRespResultInfo(**list_firewall_rules_resp_result_info_model_dict) + + # Verify the model instances are equivalent + assert list_firewall_rules_resp_result_info_model == list_firewall_rules_resp_result_info_model2 + + # Convert model instance back to dict and verify no loss of data + list_firewall_rules_resp_result_info_model_json2 = list_firewall_rules_resp_result_info_model.to_dict() + assert list_firewall_rules_resp_result_info_model_json2 == list_firewall_rules_resp_result_info_model_json + +class TestDeleteFirewallRuleResp(): + """ + Test Class for DeleteFirewallRuleResp + """ + + def test_delete_firewall_rule_resp_serialization(self): + """ + Test serialization/deserialization for DeleteFirewallRuleResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + delete_firewall_rule_resp_result_model = {} # DeleteFirewallRuleRespResult + delete_firewall_rule_resp_result_model['id'] = 'f2d427378e7542acb295380d352e2ebd' + + # Construct a json representation of a DeleteFirewallRuleResp model + delete_firewall_rule_resp_model_json = {} + delete_firewall_rule_resp_model_json['success'] = True + delete_firewall_rule_resp_model_json['errors'] = [['testString']] + delete_firewall_rule_resp_model_json['messages'] = [['testString']] + delete_firewall_rule_resp_model_json['result'] = delete_firewall_rule_resp_result_model + + # Construct a model instance of DeleteFirewallRuleResp by calling from_dict on the json representation + delete_firewall_rule_resp_model = DeleteFirewallRuleResp.from_dict(delete_firewall_rule_resp_model_json) + assert delete_firewall_rule_resp_model != False + + # Construct a model instance of DeleteFirewallRuleResp by calling from_dict on the json representation + delete_firewall_rule_resp_model_dict = DeleteFirewallRuleResp.from_dict(delete_firewall_rule_resp_model_json).__dict__ + delete_firewall_rule_resp_model2 = DeleteFirewallRuleResp(**delete_firewall_rule_resp_model_dict) + + # Verify the model instances are equivalent + assert delete_firewall_rule_resp_model == delete_firewall_rule_resp_model2 + + # Convert model instance back to dict and verify no loss of data + delete_firewall_rule_resp_model_json2 = delete_firewall_rule_resp_model.to_dict() + assert delete_firewall_rule_resp_model_json2 == delete_firewall_rule_resp_model_json + +class TestDeleteFirewallRulesResp(): + """ + Test Class for DeleteFirewallRulesResp + """ + + def test_delete_firewall_rules_resp_serialization(self): + """ + Test serialization/deserialization for DeleteFirewallRulesResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + delete_firewall_rules_resp_result_item_model = {} # DeleteFirewallRulesRespResultItem + delete_firewall_rules_resp_result_item_model['id'] = 'f2d427378e7542acb295380d352e2ebd' + + # Construct a json representation of a DeleteFirewallRulesResp model + delete_firewall_rules_resp_model_json = {} + delete_firewall_rules_resp_model_json['success'] = True + delete_firewall_rules_resp_model_json['errors'] = [['testString']] + delete_firewall_rules_resp_model_json['messages'] = [['testString']] + delete_firewall_rules_resp_model_json['result'] = [delete_firewall_rules_resp_result_item_model] + + # Construct a model instance of DeleteFirewallRulesResp by calling from_dict on the json representation + delete_firewall_rules_resp_model = DeleteFirewallRulesResp.from_dict(delete_firewall_rules_resp_model_json) + assert delete_firewall_rules_resp_model != False + + # Construct a model instance of DeleteFirewallRulesResp by calling from_dict on the json representation + delete_firewall_rules_resp_model_dict = DeleteFirewallRulesResp.from_dict(delete_firewall_rules_resp_model_json).__dict__ + delete_firewall_rules_resp_model2 = DeleteFirewallRulesResp(**delete_firewall_rules_resp_model_dict) + + # Verify the model instances are equivalent + assert delete_firewall_rules_resp_model == delete_firewall_rules_resp_model2 + + # Convert model instance back to dict and verify no loss of data + delete_firewall_rules_resp_model_json2 = delete_firewall_rules_resp_model.to_dict() + assert delete_firewall_rules_resp_model_json2 == delete_firewall_rules_resp_model_json + +class TestFirewallRuleInputWithFilterId(): + """ + Test Class for FirewallRuleInputWithFilterId + """ + + def test_firewall_rule_input_with_filter_id_serialization(self): + """ + Test serialization/deserialization for FirewallRuleInputWithFilterId + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rule_input_with_filter_id_filter_model = {} # FirewallRuleInputWithFilterIdFilter + firewall_rule_input_with_filter_id_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + + # Construct a json representation of a FirewallRuleInputWithFilterId model + firewall_rule_input_with_filter_id_model_json = {} + firewall_rule_input_with_filter_id_model_json['filter'] = firewall_rule_input_with_filter_id_filter_model + firewall_rule_input_with_filter_id_model_json['action'] = 'js_challenge' + firewall_rule_input_with_filter_id_model_json['description'] = 'JS challenge site' + + # Construct a model instance of FirewallRuleInputWithFilterId by calling from_dict on the json representation + firewall_rule_input_with_filter_id_model = FirewallRuleInputWithFilterId.from_dict(firewall_rule_input_with_filter_id_model_json) + assert firewall_rule_input_with_filter_id_model != False + + # Construct a model instance of FirewallRuleInputWithFilterId by calling from_dict on the json representation + firewall_rule_input_with_filter_id_model_dict = FirewallRuleInputWithFilterId.from_dict(firewall_rule_input_with_filter_id_model_json).__dict__ + firewall_rule_input_with_filter_id_model2 = FirewallRuleInputWithFilterId(**firewall_rule_input_with_filter_id_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_input_with_filter_id_model == firewall_rule_input_with_filter_id_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_input_with_filter_id_model_json2 = firewall_rule_input_with_filter_id_model.to_dict() + assert firewall_rule_input_with_filter_id_model_json2 == firewall_rule_input_with_filter_id_model_json + +class TestFirewallRuleObject(): + """ + Test Class for FirewallRuleObject + """ + + def test_firewall_rule_object_serialization(self): + """ + Test serialization/deserialization for FirewallRuleObject + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rule_object_filter_model = {} # FirewallRuleObjectFilter + firewall_rule_object_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + firewall_rule_object_filter_model['paused'] = True + firewall_rule_object_filter_model['description'] = 'Login from office' + firewall_rule_object_filter_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + + # Construct a json representation of a FirewallRuleObject model + firewall_rule_object_model_json = {} + firewall_rule_object_model_json['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rule_object_model_json['paused'] = False + firewall_rule_object_model_json['description'] = 'JS challenge site' + firewall_rule_object_model_json['action'] = 'js_challenge' + firewall_rule_object_model_json['filter'] = firewall_rule_object_filter_model + firewall_rule_object_model_json['created_on'] = '2019-01-01T05:20:00.123Z' + firewall_rule_object_model_json['modified_on'] = '2019-01-01T05:20:00.123Z' + + # Construct a model instance of FirewallRuleObject by calling from_dict on the json representation + firewall_rule_object_model = FirewallRuleObject.from_dict(firewall_rule_object_model_json) + assert firewall_rule_object_model != False + + # Construct a model instance of FirewallRuleObject by calling from_dict on the json representation + firewall_rule_object_model_dict = FirewallRuleObject.from_dict(firewall_rule_object_model_json).__dict__ + firewall_rule_object_model2 = FirewallRuleObject(**firewall_rule_object_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_object_model == firewall_rule_object_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_object_model_json2 = firewall_rule_object_model.to_dict() + assert firewall_rule_object_model_json2 == firewall_rule_object_model_json + +class TestFirewallRuleResp(): + """ + Test Class for FirewallRuleResp + """ + + def test_firewall_rule_resp_serialization(self): + """ + Test serialization/deserialization for FirewallRuleResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rule_object_filter_model = {} # FirewallRuleObjectFilter + firewall_rule_object_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + firewall_rule_object_filter_model['paused'] = True + firewall_rule_object_filter_model['description'] = 'Login from office' + firewall_rule_object_filter_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + + firewall_rule_object_model = {} # FirewallRuleObject + firewall_rule_object_model['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rule_object_model['paused'] = False + firewall_rule_object_model['description'] = 'JS challenge site' + firewall_rule_object_model['action'] = 'js_challenge' + firewall_rule_object_model['filter'] = firewall_rule_object_filter_model + firewall_rule_object_model['created_on'] = '2019-01-01T05:20:00.123Z' + firewall_rule_object_model['modified_on'] = '2019-01-01T05:20:00.123Z' + + # Construct a json representation of a FirewallRuleResp model + firewall_rule_resp_model_json = {} + firewall_rule_resp_model_json['success'] = True + firewall_rule_resp_model_json['errors'] = [['testString']] + firewall_rule_resp_model_json['messages'] = [['testString']] + firewall_rule_resp_model_json['result'] = firewall_rule_object_model + + # Construct a model instance of FirewallRuleResp by calling from_dict on the json representation + firewall_rule_resp_model = FirewallRuleResp.from_dict(firewall_rule_resp_model_json) + assert firewall_rule_resp_model != False + + # Construct a model instance of FirewallRuleResp by calling from_dict on the json representation + firewall_rule_resp_model_dict = FirewallRuleResp.from_dict(firewall_rule_resp_model_json).__dict__ + firewall_rule_resp_model2 = FirewallRuleResp(**firewall_rule_resp_model_dict) + + # Verify the model instances are equivalent + assert firewall_rule_resp_model == firewall_rule_resp_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rule_resp_model_json2 = firewall_rule_resp_model.to_dict() + assert firewall_rule_resp_model_json2 == firewall_rule_resp_model_json + +class TestFirewallRulesResp(): + """ + Test Class for FirewallRulesResp + """ + + def test_firewall_rules_resp_serialization(self): + """ + Test serialization/deserialization for FirewallRulesResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rule_object_filter_model = {} # FirewallRuleObjectFilter + firewall_rule_object_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + firewall_rule_object_filter_model['paused'] = True + firewall_rule_object_filter_model['description'] = 'Login from office' + firewall_rule_object_filter_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + + firewall_rule_object_model = {} # FirewallRuleObject + firewall_rule_object_model['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rule_object_model['paused'] = False + firewall_rule_object_model['description'] = 'JS challenge site' + firewall_rule_object_model['action'] = 'js_challenge' + firewall_rule_object_model['filter'] = firewall_rule_object_filter_model + firewall_rule_object_model['created_on'] = '2019-01-01T05:20:00.123Z' + firewall_rule_object_model['modified_on'] = '2019-01-01T05:20:00.123Z' + + # Construct a json representation of a FirewallRulesResp model + firewall_rules_resp_model_json = {} + firewall_rules_resp_model_json['success'] = True + firewall_rules_resp_model_json['errors'] = [['testString']] + firewall_rules_resp_model_json['messages'] = [['testString']] + firewall_rules_resp_model_json['result'] = [firewall_rule_object_model] + + # Construct a model instance of FirewallRulesResp by calling from_dict on the json representation + firewall_rules_resp_model = FirewallRulesResp.from_dict(firewall_rules_resp_model_json) + assert firewall_rules_resp_model != False + + # Construct a model instance of FirewallRulesResp by calling from_dict on the json representation + firewall_rules_resp_model_dict = FirewallRulesResp.from_dict(firewall_rules_resp_model_json).__dict__ + firewall_rules_resp_model2 = FirewallRulesResp(**firewall_rules_resp_model_dict) + + # Verify the model instances are equivalent + assert firewall_rules_resp_model == firewall_rules_resp_model2 + + # Convert model instance back to dict and verify no loss of data + firewall_rules_resp_model_json2 = firewall_rules_resp_model.to_dict() + assert firewall_rules_resp_model_json2 == firewall_rules_resp_model_json + +class TestListFirewallRulesResp(): + """ + Test Class for ListFirewallRulesResp + """ + + def test_list_firewall_rules_resp_serialization(self): + """ + Test serialization/deserialization for ListFirewallRulesResp + """ + + # Construct dict forms of any model objects needed in order to build this model. + + firewall_rule_object_filter_model = {} # FirewallRuleObjectFilter + firewall_rule_object_filter_model['id'] = '6f58318e7fa2477a23112e8118c66f61' + firewall_rule_object_filter_model['paused'] = True + firewall_rule_object_filter_model['description'] = 'Login from office' + firewall_rule_object_filter_model['expression'] = 'ip.src eq 93.184.216.0 and (http.request.uri.path ~ \"^.*/wp-login.php$\" or http.request.uri.path ~ \"^.*/xmlrpc.php$\")' + + firewall_rule_object_model = {} # FirewallRuleObject + firewall_rule_object_model['id'] = '52161eb6af4241bb9d4b32394be72fdf' + firewall_rule_object_model['paused'] = False + firewall_rule_object_model['description'] = 'JS challenge site' + firewall_rule_object_model['action'] = 'js_challenge' + firewall_rule_object_model['filter'] = firewall_rule_object_filter_model + firewall_rule_object_model['created_on'] = '2019-01-01T05:20:00.123Z' + firewall_rule_object_model['modified_on'] = '2019-01-01T05:20:00.123Z' + + list_firewall_rules_resp_result_info_model = {} # ListFirewallRulesRespResultInfo + list_firewall_rules_resp_result_info_model['page'] = 1 + list_firewall_rules_resp_result_info_model['per_page'] = 2 + list_firewall_rules_resp_result_info_model['count'] = 1 + list_firewall_rules_resp_result_info_model['total_count'] = 200 + + # Construct a json representation of a ListFirewallRulesResp model + list_firewall_rules_resp_model_json = {} + list_firewall_rules_resp_model_json['success'] = True + list_firewall_rules_resp_model_json['errors'] = [['testString']] + list_firewall_rules_resp_model_json['messages'] = [['testString']] + list_firewall_rules_resp_model_json['result'] = [firewall_rule_object_model] + list_firewall_rules_resp_model_json['result_info'] = list_firewall_rules_resp_result_info_model + + # Construct a model instance of ListFirewallRulesResp by calling from_dict on the json representation + list_firewall_rules_resp_model = ListFirewallRulesResp.from_dict(list_firewall_rules_resp_model_json) + assert list_firewall_rules_resp_model != False + + # Construct a model instance of ListFirewallRulesResp by calling from_dict on the json representation + list_firewall_rules_resp_model_dict = ListFirewallRulesResp.from_dict(list_firewall_rules_resp_model_json).__dict__ + list_firewall_rules_resp_model2 = ListFirewallRulesResp(**list_firewall_rules_resp_model_dict) + + # Verify the model instances are equivalent + assert list_firewall_rules_resp_model == list_firewall_rules_resp_model2 + + # Convert model instance back to dict and verify no loss of data + list_firewall_rules_resp_model_json2 = list_firewall_rules_resp_model.to_dict() + assert list_firewall_rules_resp_model_json2 == list_firewall_rules_resp_model_json + + +# endregion +############################################################################## +# End of Model Tests +##############################################################################