Skip to content

Commit

Permalink
Reformat files with black round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-whitestone committed Jun 13, 2021
1 parent 5b695e7 commit 16d0ed6
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 58 deletions.
30 changes: 23 additions & 7 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def test_wsgi_script_name_on_aws_url(self):
"resource": "/{proxy+}",
"requestContext": {},
"queryStringParameters": {},
"headers": {"Host": "1234567890.execute-api.us-east-1.amazonaws.com",},
"headers": {
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
},
"pathParameters": {"proxy": "return/request/url"},
"httpMethod": "GET",
"stageVariables": {},
Expand All @@ -108,7 +110,9 @@ def test_wsgi_script_name_on_domain_url(self):
"resource": "/{proxy+}",
"requestContext": {},
"queryStringParameters": {},
"headers": {"Host": "example.com",},
"headers": {
"Host": "example.com",
},
"pathParameters": {"proxy": "return/request/url"},
"httpMethod": "GET",
"stageVariables": {},
Expand All @@ -131,7 +135,9 @@ def test_wsgi_script_name_with_multi_value_header(self):
"resource": "/{proxy+}",
"requestContext": {},
"queryStringParameters": {},
"multiValueHeaders": {"Host": ["example.com"],},
"multiValueHeaders": {
"Host": ["example.com"],
},
"pathParameters": {"proxy": "return/request/url"},
"httpMethod": "GET",
"stageVariables": {},
Expand All @@ -152,7 +158,9 @@ def test_wsgi_script_name_with_multi_value_querystring(self):
"resource": "/{proxy+}",
"requestContext": {},
"multiValueQueryStringParameters": {"multi": ["value", "qs"]},
"multiValueHeaders": {"Host": ["example.com"],},
"multiValueHeaders": {
"Host": ["example.com"],
},
"pathParameters": {"proxy": "return/request/url"},
"httpMethod": "GET",
"stageVariables": {},
Expand Down Expand Up @@ -200,7 +208,9 @@ def test_exception_handler_on_web_request(self):
"resource": "/{proxy+}",
"requestContext": {},
"queryStringParameters": {},
"headers": {"Host": "1234567890.execute-api.us-east-1.amazonaws.com",},
"headers": {
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
},
"pathParameters": {"proxy": "return/request/url"},
"httpMethod": "GET",
"stageVariables": {},
Expand Down Expand Up @@ -254,7 +264,10 @@ def test_bot_triggered_event(self):
"messageVersion": "1.0",
"invocationSource": "DialogCodeHook",
"userId": "user-id specified in the POST request to Amazon Lex.",
"sessionAttributes": {"key1": "value1", "key2": "value2",},
"sessionAttributes": {
"key1": "value1",
"key2": "value2",
},
"bot": {"name": "bot-name", "alias": "bot-alias", "version": "bot-version"},
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"currentIntent": {
Expand Down Expand Up @@ -282,7 +295,10 @@ def test_exception_in_bot_triggered_event(self):
"messageVersion": "1.0",
"invocationSource": "DialogCodeHook",
"userId": "user-id specified in the POST request to Amazon Lex.",
"sessionAttributes": {"key1": "value1", "key2": "value2",},
"sessionAttributes": {
"key1": "value1",
"key2": "value2",
},
"bot": {"name": "bot-name", "alias": "bot-alias", "version": "bot-version"},
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"currentIntent": {
Expand Down
112 changes: 86 additions & 26 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def test_getting_installed_packages_mixed_case_location(self, *args):
z.get_installed_packages(
"/venv/Site-packages", "/venv/site-packages64"
),
{"superpackage": "0.1", "superpackage64": "0.1",},
{
"superpackage": "0.1",
"superpackage64": "0.1",
},
)

def test_getting_installed_packages_mixed_case(self, *args):
Expand Down Expand Up @@ -1787,7 +1790,9 @@ def get_domain_name(domain, *_args, **_kwargs):

# Test creating domain without Route53
zappa_cli.zappa_settings["stage"].update(
{"route53_enabled": False,}
{
"route53_enabled": False,
}
)
zappa_cli.zappa.reset_mock()
zappa_cli.zappa.domain_names["test.example.com"] = ""
Expand Down Expand Up @@ -1881,7 +1886,10 @@ def test_get_all_zones_two_pages(self, client):

zones = zappa_core.get_all_zones()
zappa_core.route53.list_hosted_zones.assert_has_calls(
[mock.call(MaxItems="100"), mock.call(MaxItems="100", Marker="101"),]
[
mock.call(MaxItems="100"),
mock.call(MaxItems="100", Marker="101"),
]
)
self.assertListEqual(zones["HostedZones"], [{"Id": "zone1"}, {"Id": "zone2"}])

Expand Down Expand Up @@ -2376,7 +2384,9 @@ def test_zappa_core_deploy_lambda_alb(self):
)
elbv2_stubber.add_response(
"describe_load_balancers",
expected_params={"LoadBalancerArns": [loadbalancer_arn],},
expected_params={
"LoadBalancerArns": [loadbalancer_arn],
},
service_response={
"LoadBalancers": [
{"LoadBalancerArn": loadbalancer_arn, "State": {"Code": "active"}}
Expand All @@ -2400,8 +2410,17 @@ def test_zappa_core_deploy_lambda_alb(self):

elbv2_stubber.add_response(
"create_target_group",
expected_params={"Name": kwargs["lambda_name"], "TargetType": "lambda",},
service_response={"TargetGroups": [{"TargetGroupArn": targetgroup_arn,}]},
expected_params={
"Name": kwargs["lambda_name"],
"TargetType": "lambda",
},
service_response={
"TargetGroups": [
{
"TargetGroupArn": targetgroup_arn,
}
]
},
)
elbv2_stubber.add_response(
"modify_target_group_attributes",
Expand Down Expand Up @@ -2443,10 +2462,15 @@ def test_zappa_core_deploy_lambda_alb(self):
"create_listener",
expected_params={
"Certificates": [
{"CertificateArn": kwargs["alb_vpc_config"]["CertificateArn"],}
{
"CertificateArn": kwargs["alb_vpc_config"]["CertificateArn"],
}
],
"DefaultActions": [
{"Type": "forward", "TargetGroupArn": targetgroup_arn,}
{
"Type": "forward",
"TargetGroupArn": targetgroup_arn,
}
],
"LoadBalancerArn": loadbalancer_arn,
"Protocol": "HTTPS",
Expand Down Expand Up @@ -2491,48 +2515,77 @@ def test_zappa_core_undeploy_lambda_alb(self):
)
elbv2_stubber.add_response(
"describe_load_balancers",
expected_params={"Names": [kwargs["lambda_name"]],},
expected_params={
"Names": [kwargs["lambda_name"]],
},
service_response={
"LoadBalancers": [{"LoadBalancerArn": loadbalancer_arn,}]
"LoadBalancers": [
{
"LoadBalancerArn": loadbalancer_arn,
}
]
},
)
elbv2_stubber.add_response(
"describe_listeners",
expected_params={"LoadBalancerArn": loadbalancer_arn,},
service_response={"Listeners": [{"ListenerArn": listener_arn,}]},
expected_params={
"LoadBalancerArn": loadbalancer_arn,
},
service_response={
"Listeners": [
{
"ListenerArn": listener_arn,
}
]
},
)
elbv2_stubber.add_response(
"delete_listener",
expected_params={"ListenerArn": listener_arn,},
expected_params={
"ListenerArn": listener_arn,
},
service_response={},
)
elbv2_stubber.add_response(
"delete_load_balancer",
expected_params={"LoadBalancerArn": loadbalancer_arn,},
expected_params={
"LoadBalancerArn": loadbalancer_arn,
},
service_response={},
)
elbv2_stubber.add_client_error(
"describe_load_balancers", service_error_code="LoadBalancerNotFound",
"describe_load_balancers",
service_error_code="LoadBalancerNotFound",
)
lambda_stubber.add_response(
"get_function",
expected_params={"FunctionName": kwargs["lambda_name"],},
expected_params={
"FunctionName": kwargs["lambda_name"],
},
service_response={"Configuration": {"FunctionArn": function_arn}},
)
elbv2_stubber.add_response(
"describe_target_groups",
expected_params={"Names": [kwargs["lambda_name"]],},
service_response={"TargetGroups": [{"TargetGroupArn": targetgroup_arn}],},
expected_params={
"Names": [kwargs["lambda_name"]],
},
service_response={
"TargetGroups": [{"TargetGroupArn": targetgroup_arn}],
},
)
elbv2_stubber.add_response(
"deregister_targets", service_response={},
"deregister_targets",
service_response={},
)
elbv2_stubber.add_client_error(
"describe_target_health", service_error_code="InvalidTarget",
"describe_target_health",
service_error_code="InvalidTarget",
)
elbv2_stubber.add_response(
"delete_target_group",
expected_params={"TargetGroupArn": targetgroup_arn,},
expected_params={
"TargetGroupArn": targetgroup_arn,
},
service_response={},
)
lambda_stubber.activate()
Expand All @@ -2552,9 +2605,12 @@ def test_set_lambda_concurrency(self, client):
"FunctionArn": "abc",
"Version": 1,
}
access_logging_patch = zappa_core.create_lambda_function(concurrency=5,)
access_logging_patch = zappa_core.create_lambda_function(
concurrency=5,
)
boto_mock.client().put_function_concurrency.assert_called_with(
FunctionName="abc", ReservedConcurrentExecutions=5,
FunctionName="abc",
ReservedConcurrentExecutions=5,
)

@mock.patch("botocore.client")
Expand All @@ -2571,10 +2627,13 @@ def test_update_lambda_concurrency(self, client):
"Version": 1,
}
access_logging_patch = zappa_core.update_lambda_function(
bucket="test", function_name="abc", concurrency=5,
bucket="test",
function_name="abc",
concurrency=5,
)
boto_mock.client().put_function_concurrency.assert_called_with(
FunctionName="abc", ReservedConcurrentExecutions=5,
FunctionName="abc",
ReservedConcurrentExecutions=5,
)
boto_mock.client().delete_function_concurrency.assert_not_called()

Expand All @@ -2592,7 +2651,8 @@ def test_delete_lambda_concurrency(self, client):
"Version": 1,
}
access_logging_patch = zappa_core.update_lambda_function(
bucket="test", function_name="abc",
bucket="test",
function_name="abc",
)
boto_mock.client().put_function_concurrency.assert_not_called()
boto_mock.client().delete_function_concurrency.assert_called_with(
Expand Down
4 changes: 3 additions & 1 deletion tests/tests_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def test_wsgi_map_context_headers_handling(self):
"body": {},
"headers": {"Content-Type": "application/json"},
"pathParameters": {"proxy": "v1/runs"},
"requestContext": {"authorizer": {"principalId": "user1"},},
"requestContext": {
"authorizer": {"principalId": "user1"},
},
"query": {},
}

Expand Down
15 changes: 11 additions & 4 deletions tests/tests_placebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_upload_remove_s3(self, session):

# will throw ClientError with 404 if object doesn't exist
s3.meta.client.head_object(
Bucket=bucket_name, Key=zip_path,
Bucket=bucket_name,
Key=zip_path,
)
res = z.remove_from_s3(zip_path, bucket_name)
self.assertTrue(res)
Expand Down Expand Up @@ -77,7 +78,8 @@ def test_copy_on_s3(self, session):

# will throw ClientError with 404 if object doesn't exist
s3.meta.client.head_object(
Bucket=bucket_name, Key=zip_path,
Bucket=bucket_name,
Key=zip_path,
)
zp = "copy_" + zip_path
res = z.copy_on_s3(zip_path, zp, bucket_name)
Expand All @@ -102,7 +104,9 @@ def test_create_lambda_function_s3(self, session):
)

arn = z.update_lambda_function(
bucket=bucket_name, s3_key=zip_path, function_name="test_lmbda_function55",
bucket=bucket_name,
s3_key=zip_path,
function_name="test_lmbda_function55",
)

@placebo_session
Expand Down Expand Up @@ -223,7 +227,10 @@ def test_handler(self, session):
event = {
"body": {},
"headers": {},
"params": {"parameter_1": "asdf1", "parameter_2": "asdf2",},
"params": {
"parameter_1": "asdf1",
"parameter_2": "asdf2",
},
"method": "GET",
"query": {},
}
Expand Down
18 changes: 13 additions & 5 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ def dispatch_command(self, command, stage):
command = command_tail[0] # ex: zappa manage dev showmigrations admin

self.invoke(
command, command="manage", no_color=self.vargs["no_color"],
command,
command="manage",
no_color=self.vargs["no_color"],
)

elif command == "tail": # pragma: no cover
Expand Down Expand Up @@ -1499,7 +1501,9 @@ def unschedule(self):

print("Unscheduling..")
self.zappa.unschedule_events(
lambda_name=self.lambda_name, lambda_arn=function_arn, events=events,
lambda_name=self.lambda_name,
lambda_arn=function_arn,
events=events,
)

# Remove async task SNS
Expand Down Expand Up @@ -1528,7 +1532,9 @@ def invoke(self, function_name, raw_python=False, command=None, no_color=False):
import json as json

response = self.zappa.invoke_lambda_function(
self.lambda_name, json.dumps(command), invocation_type="RequestResponse",
self.lambda_name,
json.dumps(command),
invocation_type="RequestResponse",
)

if "LogResult" in response:
Expand Down Expand Up @@ -2912,8 +2918,10 @@ def get_zappa_settings_string(self):

# If slim handler, path to project zip
if self.stage_config.get("slim_handler", False):
settings_s += "ARCHIVE_PATH='s3://{0!s}/{1!s}_{2!s}_current_project.tar.gz'\n".format(
self.s3_bucket_name, self.api_stage, self.project_name
settings_s += (
"ARCHIVE_PATH='s3://{0!s}/{1!s}_{2!s}_current_project.tar.gz'\n".format(
self.s3_bucket_name, self.api_stage, self.project_name
)
)

# since includes are for slim handler add the setting here by joining arbitrary list from zappa_settings file
Expand Down
Loading

0 comments on commit 16d0ed6

Please sign in to comment.