Skip to content

Commit

Permalink
Fixup failing tests and formatting
Browse files Browse the repository at this point in the history
Changes needed after rebasing from the latest
on master.
  • Loading branch information
jamesls committed Jul 27, 2020
1 parent 347dd0c commit cdece0a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 150 deletions.
93 changes: 40 additions & 53 deletions chalice/awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,29 @@
this class to get improved type checking across chalice.
"""
import json
# pylint: disable=too-many-lines
import os
import re
import shutil
import tempfile
import time
import uuid
import tempfile
from datetime import datetime
import zipfile
import shutil
import json
import re
import uuid
from collections import OrderedDict
from datetime import datetime
from typing import Any, Optional, Dict, Callable, List, Iterator, Iterable, \
IO, Union # noqa
Sequence, IO # noqa

import botocore.session # noqa
from botocore.exceptions import ClientError
from botocore.loaders import create_loader
from botocore.exceptions import ClientError
from botocore.utils import datetime2timestamp
from botocore.vendored.requests import ConnectionError as \
RequestsConnectionError
from botocore.vendored.requests.exceptions import ReadTimeout as \
RequestsReadTimeout
from mypy_extensions import TypedDict
from typing import ( # noqa
Any,
Sequence,
Optional,
Dict,
Callable,
List,
Iterable,
Iterator,
IO
)

from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import MAX_LAMBDA_DEPLOYMENT_SIZE
Expand Down Expand Up @@ -107,9 +97,9 @@ class DeploymentPackageTooLargeError(LambdaClientError):

class LambdaErrorContext(object):
def __init__(self,
function_name, # type: str
function_name, # type: str
client_method_name, # type: str
deployment_size, # type: int
deployment_size, # type: int
):
# type: (...) -> None
self.function_name = function_name
Expand All @@ -128,15 +118,12 @@ def __init__(self, session, sleep=time.sleep):
self._session = session
self._sleep = sleep
self._client_cache = {} # type: Dict[str, Any]

# establish the endpoint resolver using the botocore loader api
# in order to determine partition and endpoint information
loader = create_loader('data_loader')
endpoints = loader.load_data('endpoints')
self._endpoint_resolver = EndpointResolver(endpoints)

def resolve_endpoint(self, service, region):
# type: (str, str) -> Union[OrderedDict[str, Any], None]
# type: (str, str) -> Optional[OrderedDict[str, Any]]
"""Find details of an endpoint based on the service and region.
This utilizes the botocore EndpointResolver in order to find details on
Expand All @@ -146,7 +133,7 @@ def resolve_endpoint(self, service, region):
return self._endpoint_resolver.construct_endpoint(service, region)

def endpoint_from_arn(self, arn):
# type: (str) -> Union[OrderedDict[str, Any], None]
# type: (str) -> Optional[OrderedDict[str, Any]]
"""Find details for the endpoint associated with a resource ARN.
This allows the an endpoint to be discerned based on an ARN. This
Expand Down Expand Up @@ -333,18 +320,18 @@ def _create_vpc_config(self, security_group_ids, subnet_ids):
return vpc_config

def create_function(self,
function_name, # type: str
role_arn, # type: str
zip_contents, # type: str
runtime, # type: str
handler, # type: str
function_name, # type: str
role_arn, # type: str
zip_contents, # type: str
runtime, # type: str
handler, # type: str
environment_variables=None, # type: StrMap
tags=None, # type: StrMap
timeout=None, # type: OptInt
memory_size=None, # type: OptInt
security_group_ids=None, # type: OptStrList
subnet_ids=None, # type: OptStrList
layers=None, # type: OptStrList
tags=None, # type: StrMap
timeout=None, # type: OptInt
memory_size=None, # type: OptInt
security_group_ids=None, # type: OptStrList
subnet_ids=None, # type: OptStrList
layers=None, # type: OptStrList
):
# type: (...) -> str
kwargs = {
Expand Down Expand Up @@ -603,11 +590,11 @@ def delete_function(self, function_name):

def get_custom_domain_params_v2(
self,
domain_name, # type: str
endpoint_type, # type: str
certificate_arn, # type: str
security_policy=None, # type: Optional[str]
tags=None, # type: StrMap
domain_name, # type: str
endpoint_type, # type: str
certificate_arn, # type: str
security_policy=None, # type: Optional[str]
tags=None, # type: StrMap
):
# type: (...) -> Dict[str, Any]
kwargs = {
Expand Down Expand Up @@ -806,17 +793,17 @@ def delete_api_mapping(self, domain_name, path_key):
client.delete_base_path_mapping(**params)

def update_function(self,
function_name, # type: str
zip_contents, # type: str
function_name, # type: str
zip_contents, # type: str
environment_variables=None, # type: StrMap
runtime=None, # type: OptStr
tags=None, # type: StrMap
timeout=None, # type: OptInt
memory_size=None, # type: OptInt
role_arn=None, # type: OptStr
subnet_ids=None, # type: OptStrList
security_group_ids=None, # type: OptStrList
layers=None, # type: OptStrList
runtime=None, # type: OptStr
tags=None, # type: StrMap
timeout=None, # type: OptInt
memory_size=None, # type: OptInt
role_arn=None, # type: OptStr
subnet_ids=None, # type: OptStrList
security_group_ids=None, # type: OptStrList
layers=None, # type: OptStrList
):
# type: (...) -> Dict[str, Any]
"""Update a Lambda function's code and configuration.
Expand Down Expand Up @@ -1266,7 +1253,7 @@ def _convert_to_datetime(self, integer_timestamp):
return datetime.utcfromtimestamp(integer_timestamp / 1000.0)

def filter_log_events(self,
log_group_name, # type: str
log_group_name, # type: str
start_time=None, # type: Optional[datetime]
next_token=None, # type: Optional[str]
):
Expand Down
32 changes: 17 additions & 15 deletions chalice/cli/factory.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import functools
import importlib
import sys
import os
import json
import importlib
import logging
import os
import sys
from typing import Any, Optional, Dict, MutableMapping, cast # noqa
import functools

import click
from botocore.config import Config as BotocoreConfig
from botocore.session import Session
from typing import Any, Optional, Dict, MutableMapping, cast # noqa

from chalice import __version__ as chalice_version
from chalice import local
from chalice.app import Chalice # noqa
from chalice.awsclient import TypedAWSClient
from chalice.app import Chalice # noqa
from chalice.config import Config
from chalice.config import DeployedResources # noqa
from chalice.package import create_app_packager
from chalice.package import AppPackager # noqa
from chalice.package import PackageOptions
from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import DEFAULT_APIGATEWAY_STAGE_NAME
from chalice.constants import DEFAULT_ENDPOINT_TYPE
from chalice.constants import DEFAULT_STAGE_NAME
from chalice.logs import LogRetriever, LogEventGenerator
from chalice.logs import FollowLogEventGenerator
from chalice.logs import BaseLogEventGenerator
from chalice import local
from chalice.utils import UI # noqa
from chalice.utils import PipeReader # noqa
from chalice.deploy import deployer # noqa
from chalice.deploy import validate
from chalice.invoke import LambdaInvokeHandler
from chalice.invoke import LambdaInvoker
from chalice.invoke import LambdaResponseFormatter
from chalice.logs import BaseLogEventGenerator
from chalice.logs import FollowLogEventGenerator
from chalice.logs import LogRetriever, LogEventGenerator
from chalice.package import AppPackager # noqa
from chalice.package import create_app_packager, PackageOptions
from chalice.utils import PipeReader # noqa
from chalice.utils import UI # noqa


OptStr = Optional[str]
OptInt = Optional[int]
Expand Down
4 changes: 2 additions & 2 deletions chalice/deploy/executor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pprint
import re
from typing import Dict, List, Any # noqa
import pprint

import jmespath
from attr import asdict
from typing import Dict, List, Any # noqa

from chalice.deploy import models # noqa
from chalice.awsclient import TypedAWSClient # noqa
Expand Down
12 changes: 7 additions & 5 deletions chalice/deploy/planner.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# pylint: disable=too-many-lines
import json
import re
import json
from collections import OrderedDict

from typing import List, Dict, Any, Optional, Union, Tuple, Set, cast # noqa
from typing import Sequence # noqa

from chalice.awsclient import TypedAWSClient, ResourceDoesNotExistError # noqa
from chalice.config import Config, DeployedResources # noqa
from chalice.deploy import models
from chalice.utils import OSUtils # noqa
from chalice.deploy import models
from chalice.awsclient import TypedAWSClient, ResourceDoesNotExistError # noqa


InstructionMsg = Union[models.Instruction, Tuple[models.Instruction, str]]
MarkedResource = Dict[str, List[models.RecordResource]]
Expand Down Expand Up @@ -166,8 +168,8 @@ def execute(self, resources):
return models.Plan(plan, messages)

def _add_result_to_plan(self,
result, # type: Sequence[InstructionMsg]
plan, # type: List[models.Instruction]
result, # type: Sequence[InstructionMsg]
plan, # type: List[models.Instruction]
messages, # type: Dict[int, str]
):
# type: (...) -> None
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/deploy/test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def test_can_create_domain_name(self, lambda_function):
)
]
# create domain name
self.assert_apicall_equals(plan[11], expected[0])
self.assert_apicall_equals(plan[13], expected[0])
msg = 'Creating custom domain name: example.com\n'
assert list(self.last_plan.messages.values())[-2] == msg

Expand Down
18 changes: 11 additions & 7 deletions tests/unit/deploy/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ def foo():
'authorizerCredentials': 'arn:role',
'authorizerResultTtlInSeconds': 10,
'authorizerUri': ('arn:aws:apigateway:us-west-2:lambda:path'
'/2015-03-31/functions/auth_arn/invocations'),
'/2015-03-31/functions/arn:aws:lambda:'
'mars-west-1:123456789:function:auth_arn'
'/invocations'),
}
}

Expand All @@ -676,11 +678,13 @@ def test_builtin_auth_with_scopes(sample_app):
swagger_gen = SwaggerGenerator(
region='us-west-2',
deployed_resources={
'api_handler_arn': 'lambda_arn',
'api_handler_arn': 'arn:aws:lambda:mars-west-1:123456789'
':function:lambda_arn',
'api_handler_name': 'api-dev',
'lambda_functions': {
'api-dev-myauth': {
'arn': 'auth_arn',
'arn': 'arn:aws:lambda:mars-west-1:123456789'
':function:auth_arn',
'type': 'authorizer',
}
}
Expand Down Expand Up @@ -715,10 +719,10 @@ def foo():
'type': 'token',
'authorizerCredentials': 'arn:role',
'authorizerResultTtlInSeconds': 10,
'authorizerUri': ('arn:aws:apigateway:us-west-2:lambda:path'
'/2015-03-31/functions/'
'arn:aws:lambda:mars-west-1:123456789:function'
':auth_arn/invocations'),
'authorizerUri': ('arn:aws:apigateway:us-west-2:'
'lambda:path/2015-03-31/functions'
'/arn:aws:lambda:mars-west-1:123456789:'
'function:auth_arn/invocations'),
}
}

Expand Down
Loading

0 comments on commit cdece0a

Please sign in to comment.