Skip to content

Commit ed7e02f

Browse files
Remove old AWS client fixtures (#8070)
1 parent 1d97ce9 commit ed7e02f

22 files changed

+318
-525
lines changed

localstack/testing/pytest/fixtures.py

Lines changed: 184 additions & 343 deletions
Large diffs are not rendered by default.

tests/integration/apigateway/conftest.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@
5858

5959
@pytest.fixture
6060
def create_rest_api_with_integration(
61-
create_rest_apigw,
62-
apigateway_client,
63-
wait_for_stream_ready,
64-
create_iam_role_with_policy,
61+
create_rest_apigw, wait_for_stream_ready, create_iam_role_with_policy, aws_client
6562
):
6663
def _factory(
6764
integration_uri,
@@ -76,11 +73,11 @@ def _factory(
7673
)
7774

7875
resource_id, _ = create_rest_resource(
79-
apigateway_client, restApiId=api_id, parentId=root_id, pathPart="test"
76+
aws_client.apigateway, restApiId=api_id, parentId=root_id, pathPart="test"
8077
)
8178

8279
method, _ = create_rest_resource_method(
83-
apigateway_client,
80+
aws_client.apigateway,
8481
restApiId=api_id,
8582
resourceId=resource_id,
8683
httpMethod="POST",
@@ -103,7 +100,7 @@ def _factory(
103100
)
104101

105102
create_rest_api_integration(
106-
apigateway_client,
103+
aws_client.apigateway,
107104
restApiId=api_id,
108105
resourceId=resource_id,
109106
httpMethod=method,
@@ -115,7 +112,7 @@ def _factory(
115112
)
116113

117114
create_rest_api_method_response(
118-
apigateway_client,
115+
aws_client.apigateway,
119116
restApiId=api_id,
120117
resourceId=resource_id,
121118
httpMethod="POST",
@@ -124,17 +121,17 @@ def _factory(
124121

125122
res_templates = res_templates or {APPLICATION_JSON: "$input.json('$')"}
126123
create_rest_api_integration_response(
127-
apigateway_client,
124+
aws_client.apigateway,
128125
restApiId=api_id,
129126
resourceId=resource_id,
130127
httpMethod="POST",
131128
statusCode="200",
132129
responseTemplates=res_templates,
133130
)
134131

135-
deployment_id, _ = create_rest_api_deployment(apigateway_client, restApiId=api_id)
132+
deployment_id, _ = create_rest_api_deployment(aws_client.apigateway, restApiId=api_id)
136133
create_rest_api_stage(
137-
apigateway_client, restApiId=api_id, stageName=stage, deploymentId=deployment_id
134+
aws_client.apigateway, restApiId=api_id, stageName=stage, deploymentId=deployment_id
138135
)
139136

140137
return api_id
@@ -143,11 +140,11 @@ def _factory(
143140

144141

145142
@pytest.fixture
146-
def apigw_redeploy_api(apigateway_client):
143+
def apigw_redeploy_api(aws_client):
147144
def _factory(rest_api_id: str, stage_name: str):
148-
deployment_id = apigateway_client.create_deployment(restApiId=rest_api_id)["id"]
145+
deployment_id = aws_client.apigateway.create_deployment(restApiId=rest_api_id)["id"]
149146

150-
apigateway_client.update_stage(
147+
aws_client.apigateway.update_stage(
151148
restApiId=rest_api_id,
152149
stageName=stage_name,
153150
patchOperations=[{"op": "replace", "path": "/deploymentId", "value": deployment_id}],

tests/integration/apigateway/test_apigateway_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def apigw_snapshot_transformer(snapshot):
2727

2828

2929
@pytest.fixture(scope="class", autouse=True)
30-
def apigw_cleanup_before_run(apigateway_client):
30+
def apigw_cleanup_before_run(aws_client):
3131
# TODO: remove this once all tests are properly cleaning up and using fixtures
32-
rest_apis = apigateway_client.get_rest_apis()
32+
rest_apis = aws_client.apigateway.get_rest_apis()
3333
for rest_api in rest_apis["items"]:
34-
delete_rest_api_retry(apigateway_client, rest_api["id"])
34+
delete_rest_api_retry(aws_client.apigateway, rest_api["id"])
3535

3636

3737
def delete_rest_api_retry(client, rest_api_id: str):
@@ -59,21 +59,21 @@ def delete_rest_api_retry(client, rest_api_id: str):
5959

6060

6161
@pytest.fixture
62-
def apigw_create_rest_api(apigateway_client):
62+
def apigw_create_rest_api(aws_client):
6363
rest_apis = []
6464

6565
def _factory(*args, **kwargs):
6666
if "name" not in kwargs:
6767
kwargs["name"] = f"test-api-{short_uid()}"
68-
response = apigateway_client.create_rest_api(*args, **kwargs)
68+
response = aws_client.apigateway.create_rest_api(*args, **kwargs)
6969
rest_apis.append(response["id"])
7070
return response
7171

7272
yield _factory
7373

7474
# TODO: might clean up even more resources as we learn? integrations and such?
7575
for rest_api_id in rest_apis:
76-
delete_rest_api_retry(apigateway_client, rest_api_id)
76+
delete_rest_api_retry(aws_client.apigateway, rest_api_id)
7777

7878

7979
@pytest.mark.aws_validated

tests/integration/apigateway/test_apigateway_integrations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,29 +401,29 @@ def test_put_integration_validation(aws_client):
401401

402402

403403
@pytest.fixture
404-
def default_vpc(ec2_client):
405-
vpcs = ec2_client.describe_vpcs()
404+
def default_vpc(aws_client):
405+
vpcs = aws_client.ec2.describe_vpcs()
406406
for vpc in vpcs["Vpcs"]:
407407
if vpc.get("IsDefault"):
408408
return vpc
409409
raise Exception("Default VPC not found")
410410

411411

412412
@pytest.fixture
413-
def create_vpc_endpoint(ec2_client, default_vpc):
413+
def create_vpc_endpoint(default_vpc, aws_client):
414414
endpoints = []
415415

416416
def _create(**kwargs):
417417
kwargs.setdefault("VpcId", default_vpc["VpcId"])
418-
result = ec2_client.create_vpc_endpoint(**kwargs)
418+
result = aws_client.ec2.create_vpc_endpoint(**kwargs)
419419
endpoints.append(result["VpcEndpoint"]["VpcEndpointId"])
420420
return result["VpcEndpoint"]
421421

422422
yield _create
423423

424424
for endpoint in endpoints:
425425
with contextlib.suppress(Exception):
426-
ec2_client.delete_vpc_endpoints(VpcEndpointIds=[endpoint])
426+
aws_client.ec2.delete_vpc_endpoints(VpcEndpointIds=[endpoint])
427427

428428

429429
@pytest.mark.skip_snapshot_verify(

tests/integration/apigateway/test_apigateway_lambda.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@
9292
]
9393
)
9494
def test_lambda_aws_proxy_integration(
95-
apigateway_client,
96-
create_rest_apigw,
97-
create_lambda_function,
98-
create_role_with_policy,
99-
snapshot,
95+
create_rest_apigw, create_lambda_function, create_role_with_policy, snapshot, aws_client
10096
):
10197
function_name = f"test-function-{short_uid()}"
10298
stage_name = "test"
@@ -120,27 +116,27 @@ def test_lambda_aws_proxy_integration(
120116
name=f"test-api-{short_uid()}",
121117
description="Integration test API",
122118
)
123-
resource_id = apigateway_client.create_resource(
119+
resource_id = aws_client.apigateway.create_resource(
124120
restApiId=api_id, parentId=root, pathPart="{proxy+}"
125121
)["id"]
126-
apigateway_client.put_method(
122+
aws_client.apigateway.put_method(
127123
restApiId=api_id,
128124
resourceId=resource_id,
129125
httpMethod="ANY",
130126
authorizationType="NONE",
131127
)
132128

133129
# Lambda AWS_PROXY integration
134-
apigateway_client.put_integration(
130+
aws_client.apigateway.put_integration(
135131
restApiId=api_id,
136132
resourceId=resource_id,
137133
httpMethod="ANY",
138134
type="AWS_PROXY",
139135
integrationHttpMethod="POST",
140-
uri=f"arn:aws:apigateway:{apigateway_client.meta.region_name}:lambda:path/2015-03-31/functions/{lambda_arn}/invocations",
136+
uri=f"arn:aws:apigateway:{aws_client.apigateway.meta.region_name}:lambda:path/2015-03-31/functions/{lambda_arn}/invocations",
141137
credentials=role_arn,
142138
)
143-
apigateway_client.create_deployment(restApiId=api_id, stageName=stage_name)
139+
aws_client.apigateway.create_deployment(restApiId=api_id, stageName=stage_name)
144140

145141
# invoke rest api
146142
invocation_url = api_invoke_url(
@@ -242,7 +238,7 @@ def invoke_api_with_multi_value_header(url):
242238

243239
@pytest.mark.aws_validated
244240
def test_lambda_aws_integration(
245-
apigateway_client, create_rest_apigw, create_lambda_function, create_role_with_policy, snapshot
241+
create_rest_apigw, create_lambda_function, create_role_with_policy, snapshot, aws_client
246242
):
247243
function_name = f"test-{short_uid()}"
248244
stage_name = "api"
@@ -260,40 +256,40 @@ def test_lambda_aws_integration(
260256

261257
api_id, _, root = create_rest_apigw(name=f"test-api-{short_uid()}")
262258
resource_id, _ = create_rest_resource(
263-
apigateway_client, restApiId=api_id, parentId=root, pathPart="test"
259+
aws_client.apigateway, restApiId=api_id, parentId=root, pathPart="test"
264260
)
265261
create_rest_resource_method(
266-
apigateway_client,
262+
aws_client.apigateway,
267263
restApiId=api_id,
268264
resourceId=resource_id,
269265
httpMethod="POST",
270266
authorizationType="NONE",
271267
)
272268
create_rest_api_integration(
273-
apigateway_client,
269+
aws_client.apigateway,
274270
restApiId=api_id,
275271
resourceId=resource_id,
276272
httpMethod="POST",
277273
type="AWS",
278274
integrationHttpMethod="POST",
279-
uri=f"arn:aws:apigateway:{apigateway_client.meta.region_name}:lambda:path/2015-03-31/functions/{lambda_arn}/invocations",
275+
uri=f"arn:aws:apigateway:{aws_client.apigateway.meta.region_name}:lambda:path/2015-03-31/functions/{lambda_arn}/invocations",
280276
credentials=role_arn,
281277
)
282278
create_rest_api_integration_response(
283-
apigateway_client,
279+
aws_client.apigateway,
284280
restApiId=api_id,
285281
resourceId=resource_id,
286282
httpMethod="POST",
287283
statusCode="200",
288284
)
289285
create_rest_api_method_response(
290-
apigateway_client,
286+
aws_client.apigateway,
291287
restApiId=api_id,
292288
resourceId=resource_id,
293289
httpMethod="POST",
294290
statusCode="200",
295291
)
296-
apigateway_client.create_deployment(restApiId=api_id, stageName=stage_name)
292+
aws_client.apigateway.create_deployment(restApiId=api_id, stageName=stage_name)
297293
invocation_url = api_invoke_url(api_id=api_id, stage=stage_name, path="/test")
298294

299295
def invoke_api(url):

tests/integration/awslambda/test_lambda_api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,10 @@ def test_list_functions(self, create_lambda_function, lambda_su_role, snapshot,
577577
@pytest.mark.skipif(is_old_provider(), reason="focusing on new provider")
578578
class TestLambdaImages:
579579
@pytest.fixture(scope="class")
580-
def login_docker_client(self, ecr_client):
580+
def login_docker_client(self, aws_client):
581581
if not is_aws_cloud():
582582
return
583-
auth_data = ecr_client.get_authorization_token()
583+
auth_data = aws_client.ecr.get_authorization_token()
584584
# if check is necessary since registry login data is not available at LS before min. 1 repository is created
585585
if auth_data["authorizationData"]:
586586
auth_data = auth_data["authorizationData"][0]
@@ -1583,7 +1583,7 @@ def test_function_revisions_permissions(self, create_lambda_function, snapshot,
15831583
@pytest.mark.skipif(is_old_provider(), reason="focusing on new provider")
15841584
class TestLambdaTag:
15851585
@pytest.fixture(scope="function")
1586-
def fn_arn(self, create_lambda_function, lambda_client):
1586+
def fn_arn(self, create_lambda_function, aws_client):
15871587
"""simple reusable setup to test tagging operations against"""
15881588
function_name = f"fn-{short_uid()}"
15891589
create_lambda_function(
@@ -1592,7 +1592,9 @@ def fn_arn(self, create_lambda_function, lambda_client):
15921592
runtime=Runtime.python3_9,
15931593
)
15941594

1595-
yield lambda_client.get_function(FunctionName=function_name)["Configuration"]["FunctionArn"]
1595+
yield aws_client.awslambda.get_function(FunctionName=function_name)["Configuration"][
1596+
"FunctionArn"
1597+
]
15961598

15971599
@pytest.mark.aws_validated
15981600
def test_create_tag_on_fn_create(self, create_lambda_function, snapshot, aws_client):

tests/integration/awslambda/test_lambda_integration_dynamodbstreams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def _snapshot_transformers(snapshot):
4343

4444

4545
@pytest.fixture
46-
def wait_for_dynamodb_stream_enabled(dynamodbstreams_client):
46+
def wait_for_dynamodb_stream_enabled(aws_client):
4747
def _wait_for_stream_enabled(latest_stream_arn: str):
4848
def _is_stream_enabled():
4949
return (
50-
dynamodbstreams_client.describe_stream(StreamArn=latest_stream_arn)[
50+
aws_client.dynamodbstreams.describe_stream(StreamArn=latest_stream_arn)[
5151
"StreamDescription"
5252
]["StreamStatus"]
5353
== "ENABLED"
@@ -59,10 +59,10 @@ def _is_stream_enabled():
5959

6060

6161
@pytest.fixture
62-
def get_lambda_logs_event(logs_client):
62+
def get_lambda_logs_event(aws_client):
6363
def _get_lambda_logs_event(function_name, expected_num_events, retries=30):
6464
return _get_lambda_invocation_events(
65-
logs_client=logs_client,
65+
logs_client=aws_client.logs,
6666
function_name=function_name,
6767
expected_num_events=expected_num_events,
6868
retries=retries,

tests/integration/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,18 @@ def localstack_runtime():
181181

182182

183183
@pytest.fixture
184-
def import_apigw(apigateway_client):
184+
def import_apigw(aws_client):
185185
rest_api_ids = []
186186

187187
def _import_apigateway_function(*args, **kwargs):
188-
response, root_id = import_rest_api(apigateway_client, **kwargs)
188+
response, root_id = import_rest_api(aws_client.apigateway, **kwargs)
189189
rest_api_ids.append(response.get("id"))
190190
return response, root_id
191191

192192
yield _import_apigateway_function
193193

194194
for rest_api_id in rest_api_ids:
195-
delete_rest_api(apigateway_client, restApiId=rest_api_id)
195+
delete_rest_api(aws_client.apigateway, restApiId=rest_api_id)
196196

197197

198198
@pytest.fixture(scope="session")

tests/integration/s3/test_s3.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ def factory(s3_client, **kwargs) -> str:
144144

145145

146146
@pytest.fixture
147-
def s3_multipart_upload(s3_client):
147+
def s3_multipart_upload(aws_client):
148148
def perform_multipart_upload(
149149
bucket, key, data=None, zipped=False, acl=None, parts: int = 1, **kwargs
150150
):
151151
# beware, the last part can be under 5 MiB, but previous parts needs to be between 5MiB and 5GiB
152152
if acl:
153153
kwargs["ACL"] = acl
154-
multipart_upload_dict = s3_client.create_multipart_upload(Bucket=bucket, Key=key, **kwargs)
154+
multipart_upload_dict = aws_client.s3.create_multipart_upload(
155+
Bucket=bucket, Key=key, **kwargs
156+
)
155157
upload_id = multipart_upload_dict["UploadId"]
156158
data = data or (5 * short_uid())
157159
multipart_upload_parts = []
@@ -172,7 +174,7 @@ def perform_multipart_upload(
172174
with gzip.GzipFile(fileobj=upload_file_object, mode="w") as filestream:
173175
filestream.write(part_data)
174176

175-
response = s3_client.upload_part(
177+
response = aws_client.s3.upload_part(
176178
Bucket=bucket,
177179
Key=key,
178180
Body=upload_file_object,
@@ -185,7 +187,7 @@ def perform_multipart_upload(
185187
if zipped:
186188
break
187189

188-
return s3_client.complete_multipart_upload(
190+
return aws_client.s3.complete_multipart_upload(
189191
Bucket=bucket,
190192
Key=key,
191193
MultipartUpload={"Parts": multipart_upload_parts},
@@ -5077,17 +5079,14 @@ def test_presigned_url_v4_signed_headers_in_qs(
50775079
reason="Not implemented in legacy provider",
50785080
)
50795081
def test_pre_signed_url_forward_slash_bucket(
5080-
self,
5081-
s3_client,
5082-
s3_bucket,
5083-
patch_s3_skip_signature_validation_false,
5082+
self, s3_bucket, patch_s3_skip_signature_validation_false, aws_client
50845083
):
50855084
# PHP SDK accepts a bucket name with a forward slash when generating a pre-signed URL
50865085
# however the signature will not match afterwards (in AWS or with LocalStack)
50875086
# the error message was misleading, because by default we remove the double slash from the path, and we did not
50885087
# calculate the same signature as AWS
50895088
object_key = "temp.txt"
5090-
s3_client.put_object(Key=object_key, Bucket=s3_bucket, Body="123")
5089+
aws_client.s3.put_object(Key=object_key, Bucket=s3_bucket, Body="123")
50915090

50925091
s3_endpoint_path_style = _endpoint_url()
50935092
client = _s3_client_custom_config(

0 commit comments

Comments
 (0)