Skip to content

Commit

Permalink
Pylint - Enable more rules on source and tests-directory (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Mar 11, 2022
1 parent e03ec43 commit eed32a5
Show file tree
Hide file tree
Showing 176 changed files with 795 additions and 1,228 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ init:

lint:
@echo "Running flake8..."
flake8 moto
flake8 moto tests
@echo "Running black... "
@echo "(Make sure you have black-22.1.0 installed, as other versions will produce different results)"
black --check moto/ tests/
Expand Down
4 changes: 3 additions & 1 deletion moto/acm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,13 @@ def delete_certificate(self, arn):
def request_certificate(
self,
domain_name,
domain_validation_options,
idempotency_token,
subject_alt_names,
tags=None,
):
"""
The parameter DomainValidationOptions has not yet been implemented
"""
if idempotency_token is not None:
arn = self._get_arn_from_idempotency_token(idempotency_token)
if arn and self._certificates[arn].tags.equals(tags):
Expand Down
8 changes: 2 additions & 6 deletions moto/acm/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def request_params(self):
except ValueError:
return {}

def _get_param(self, param, default=None):
return self.request_params.get(param, default)
def _get_param(self, param_name, if_none=None):
return self.request_params.get(param_name, if_none)

def add_tags_to_certificate(self):
arn = self._get_param("CertificateArn")
Expand Down Expand Up @@ -205,9 +205,6 @@ def remove_tags_from_certificate(self):

def request_certificate(self):
domain_name = self._get_param("DomainName")
domain_validation_options = self._get_param(
"DomainValidationOptions"
) # is ignored atm
idempotency_token = self._get_param("IdempotencyToken")
subject_alt_names = self._get_param("SubjectAlternativeNames")
tags = self._get_param("Tags") # Optional
Expand All @@ -225,7 +222,6 @@ def request_certificate(self):
try:
arn = self.acm_backend.request_certificate(
domain_name,
domain_validation_options,
idempotency_token,
subject_alt_names,
tags,
Expand Down
2 changes: 1 addition & 1 deletion moto/apigateway/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self):
class NoIntegrationResponseDefined(NotFoundException):
code = 404

def __init__(self, code=None):
def __init__(self):
super().__init__("Invalid Response status code specified")


Expand Down
7 changes: 7 additions & 0 deletions moto/apigateway/integration_parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import abc


class IntegrationParser:
@abc.abstractmethod
def invoke(self, request, integration):
pass
4 changes: 3 additions & 1 deletion moto/apigateway/integration_parsers/aws_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests

from . import IntegrationParser

class TypeAwsParser:

class TypeAwsParser(IntegrationParser):
def invoke(self, request, integration):
# integration.uri = arn:aws:apigateway:{region}:{subdomain.service|service}:path|action/{service_api}
# example value = 'arn:aws:apigateway:us-west-2:dynamodb:action/PutItem'
Expand Down
4 changes: 3 additions & 1 deletion moto/apigateway/integration_parsers/http_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests

from . import IntegrationParser

class TypeHttpParser:

class TypeHttpParser(IntegrationParser):
"""
Parse invocations to a APIGateway resource with integration type HTTP
"""
Expand Down
5 changes: 4 additions & 1 deletion moto/apigateway/integration_parsers/unknown_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class TypeUnknownParser:
from . import IntegrationParser


class TypeUnknownParser(IntegrationParser):
"""
Parse invocations to a APIGateway resource with an unknown integration type
"""
Expand Down
14 changes: 6 additions & 8 deletions moto/apigateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def create_integration_response(
def get_integration_response(self, status_code):
result = self.get("integrationResponses", {}).get(status_code)
if not result:
raise NoIntegrationResponseDefined(status_code)
raise NoIntegrationResponseDefined()
return result

def delete_integration_response(self, status_code):
Expand Down Expand Up @@ -597,18 +597,16 @@ def __init__(
name=None,
description=None,
enabled=False,
generateDistinctId=False,
generateDistinctId=False, # pylint: disable=unused-argument
value=None,
stageKeys=None,
tags=None,
customerId=None,
):
super().__init__()
self["id"] = create_id()
self["value"] = (
value
if value
else "".join(random.sample(string.ascii_letters + string.digits, 40))
self["value"] = value or "".join(
random.sample(string.ascii_letters + string.digits, 40)
)
self["name"] = name
self["customerId"] = customerId
Expand Down Expand Up @@ -846,8 +844,8 @@ def to_path(prop):
self.description = ""

@classmethod
def has_cfn_attr(cls, attribute):
return attribute in ["RootResourceId"]
def has_cfn_attr(cls, attr):
return attr in ["RootResourceId"]

def get_cfn_attribute(self, attribute_name):
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
Expand Down
3 changes: 0 additions & 3 deletions moto/apigatewayv2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,16 +996,13 @@ def create_api(
self,
api_key_selection_expression,
cors_configuration,
credentials_arn,
description,
disable_schema_validation,
disable_execute_api_endpoint,
name,
protocol_type,
route_key,
route_selection_expression,
tags,
target,
version,
):
"""
Expand Down
6 changes: 0 additions & 6 deletions moto/apigatewayv2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,13 @@ def create_api(self):

api_key_selection_expression = params.get("apiKeySelectionExpression")
cors_configuration = params.get("corsConfiguration")
credentials_arn = params.get("credentialsArn")
description = params.get("description")
disable_schema_validation = params.get("disableSchemaValidation")
disable_execute_api_endpoint = params.get("disableExecuteApiEndpoint")
name = params.get("name")
protocol_type = params.get("protocolType")
route_key = params.get("routeKey")
route_selection_expression = params.get("routeSelectionExpression")
tags = params.get("tags")
target = params.get("target")
version = params.get("version")

if protocol_type not in ["HTTP", "WEBSOCKET"]:
Expand All @@ -224,16 +221,13 @@ def create_api(self):
api = self.apigatewayv2_backend.create_api(
api_key_selection_expression=api_key_selection_expression,
cors_configuration=cors_configuration,
credentials_arn=credentials_arn,
description=description,
disable_schema_validation=disable_schema_validation,
disable_execute_api_endpoint=disable_execute_api_endpoint,
name=name,
protocol_type=protocol_type,
route_key=route_key,
route_selection_expression=route_selection_expression,
tags=tags,
target=target,
version=version,
)
return 200, {}, json.dumps(api.to_json())
Expand Down
19 changes: 7 additions & 12 deletions moto/autoscaling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,8 @@ def update(
launch_config_name,
launch_template,
vpc_zone_identifier,
default_cooldown,
health_check_period,
health_check_type,
placement_group,
termination_policies,
new_instances_protected_from_scale_in=None,
):
self._set_azs_and_vpcs(availability_zones, vpc_zone_identifier, update=True)
Expand Down Expand Up @@ -808,13 +805,13 @@ def update_auto_scaling_group(
launch_config_name,
launch_template,
vpc_zone_identifier,
default_cooldown,
health_check_period,
health_check_type,
placement_group,
termination_policies,
new_instances_protected_from_scale_in=None,
):
"""
The parameter DefaultCooldown, PlacementGroup, TerminationPolicies are not yet implemented
"""
# TODO: Add MixedInstancesPolicy once implemented.
# Verify only a single launch config-like parameter is provided.
if launch_config_name and launch_template:
Expand All @@ -832,11 +829,8 @@ def update_auto_scaling_group(
launch_config_name=launch_config_name,
launch_template=launch_template,
vpc_zone_identifier=vpc_zone_identifier,
default_cooldown=default_cooldown,
health_check_period=health_check_period,
health_check_type=health_check_type,
placement_group=placement_group,
termination_policies=termination_policies,
new_instances_protected_from_scale_in=new_instances_protected_from_scale_in,
)
return group
Expand Down Expand Up @@ -888,9 +882,10 @@ def attach_instances(self, group_name, instance_ids):
self.update_attached_elbs(group.name)
self.update_attached_target_groups(group.name)

def set_instance_health(
self, instance_id, health_status, should_respect_grace_period
):
def set_instance_health(self, instance_id, health_status):
"""
The ShouldRespectGracePeriod-parameter is not yet implemented
"""
instance = self.ec2_backend.get_instance(instance_id)
instance_state = next(
instance_state
Expand Down
8 changes: 1 addition & 7 deletions moto/autoscaling/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ def set_instance_health(self):
health_status = self._get_param("HealthStatus")
if health_status not in ["Healthy", "Unhealthy"]:
raise ValueError("Valid instance health states are: [Healthy, Unhealthy]")
should_respect_grace_period = self._get_param("ShouldRespectGracePeriod")
self.autoscaling_backend.set_instance_health(
instance_id, health_status, should_respect_grace_period
)
self.autoscaling_backend.set_instance_health(instance_id, health_status)
template = self.response_template(SET_INSTANCE_HEALTH_TEMPLATE)
return template.render()

Expand Down Expand Up @@ -200,11 +197,8 @@ def update_auto_scaling_group(self):
launch_config_name=self._get_param("LaunchConfigurationName"),
launch_template=self._get_dict_param("LaunchTemplate."),
vpc_zone_identifier=self._get_param("VPCZoneIdentifier"),
default_cooldown=self._get_int_param("DefaultCooldown"),
health_check_period=self._get_int_param("HealthCheckGracePeriod"),
health_check_type=self._get_param("HealthCheckType"),
placement_group=self._get_param("PlacementGroup"),
termination_policies=self._get_multi_param("TerminationPolicies.member"),
new_instances_protected_from_scale_in=self._get_bool_param(
"NewInstancesProtectedFromScaleIn", None
),
Expand Down
18 changes: 8 additions & 10 deletions moto/awslambda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def to_dict(self):


class LambdaFunction(CloudFormationModel, DockerModel):
def __init__(self, spec, region, validate_s3=True, version=1):
def __init__(self, spec, region, version=1):
DockerModel.__init__(self)
# required
self.region = region
Expand Down Expand Up @@ -547,14 +547,12 @@ def convert(s):
except Exception:
return s

def _invoke_lambda(self, code, event=None, context=None):
def _invoke_lambda(self, event=None):
# Create the LogGroup if necessary, to write the result to
self.logs_backend.ensure_log_group(self.logs_group_name, [])
# TODO: context not yet implemented
if event is None:
event = dict()
if context is None:
context = {}
output = None

try:
Expand Down Expand Up @@ -670,7 +668,7 @@ def save_logs(self, output):
for line in output.splitlines()
]
self.logs_backend.put_log_events(
self.logs_group_name, log_stream_name, log_events, None
self.logs_group_name, log_stream_name, log_events
)

def invoke(self, body, request_headers, response_headers):
Expand All @@ -681,7 +679,7 @@ def invoke(self, body, request_headers, response_headers):
body = "{}"

# Get the invocation type:
res, errored, logs = self._invoke_lambda(code=self.code, event=body)
res, errored, logs = self._invoke_lambda(event=body)
inv_type = request_headers.get("x-amz-invocation-type", "RequestResponse")
if inv_type == "RequestResponse":
encoded = base64.b64encode(logs.encode("utf-8"))
Expand Down Expand Up @@ -746,8 +744,8 @@ def create_from_cloudformation_json(
return fn

@classmethod
def has_cfn_attr(cls, attribute):
return attribute in ["Arn"]
def has_cfn_attr(cls, attr):
return attr in ["Arn"]

def get_cfn_attribute(self, attribute_name):
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
Expand All @@ -758,7 +756,7 @@ def get_cfn_attribute(self, attribute_name):

@classmethod
def update_from_cloudformation_json(
cls, new_resource_name, cloudformation_json, original_resource, region_name
cls, original_resource, new_resource_name, cloudformation_json, region_name
):
updated_props = cloudformation_json["Properties"]
original_resource.update_configuration(updated_props)
Expand Down Expand Up @@ -879,7 +877,7 @@ def create_from_cloudformation_json(

@classmethod
def update_from_cloudformation_json(
cls, new_resource_name, cloudformation_json, original_resource, region_name
cls, original_resource, new_resource_name, cloudformation_json, region_name
):
properties = cloudformation_json["Properties"]
event_source_uuid = original_resource.uuid
Expand Down
Loading

0 comments on commit eed32a5

Please sign in to comment.