Skip to content

Commit ae772de

Browse files
committed
breaking up tests
1 parent df44aa4 commit ae772de

9 files changed

+857
-317
lines changed

python/example_code/s3/s3_basics/s3_express_getting_started.py

Lines changed: 205 additions & 124 deletions
Large diffs are not rendered by default.

python/example_code/s3/s3_basics/test/test_s3_express_getting_started.py

Lines changed: 0 additions & 192 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Tests for s3_express_getting_started.py.
6+
"""
7+
8+
import pytest
9+
10+
import boto3
11+
from botocore import waiter
12+
import os
13+
import sys
14+
15+
script_dir = os.path.dirname(os.path.abspath(__file__))
16+
17+
# Append directory for s3_express_getting_started.py
18+
sys.path.append(os.path.join(script_dir, ".."))
19+
import s3_express_getting_started
20+
21+
22+
@pytest.mark.integ
23+
@pytest.mark.parametrize(
24+
"error_code, stop_on_index",
25+
[
26+
("TESTERROR-stub_list_objects_directory", 0),
27+
("TESTERROR-stub_delete_objects_directory", 1),
28+
("TESTERROR-stub_delete_bucket_directory", 2),
29+
("TESTERROR-stub_list_objects_regular", 3),
30+
("TESTERROR-stub_delete_objects_regular", 4),
31+
("TESTERROR-stub_delete_bucket_regular", 5),
32+
("TESTERROR-stub_delete_stack", 6),
33+
("TESTERROR-stub_delete_vpc_endpoints", 7),
34+
("TESTERROR-stub_delete_vpc", 8),
35+
(None, 8),
36+
],
37+
)
38+
def test_s3_express_scenario_cleanup(
39+
make_stubber, stub_runner, error_code, stop_on_index, monkeypatch
40+
):
41+
region = "us-east-1"
42+
cloud_formation_resource = boto3.resource("cloudformation")
43+
cloud_formation_stubber = make_stubber(cloud_formation_resource.meta.client)
44+
45+
ec2_client = boto3.client("ec2", region_name=region)
46+
ec2_stubber = make_stubber(ec2_client)
47+
48+
iam_client = boto3.client("iam")
49+
50+
s3_client = boto3.client("s3")
51+
s3_stubber = make_stubber(s3_client)
52+
53+
my_uuid = "0000"
54+
55+
availability_zone_ids = ["use1-az2"]
56+
57+
bucket_name_prefix = "amzn-s3-demo-bucket"
58+
directory_bucket_name = (
59+
f"{bucket_name_prefix}-{my_uuid}--{availability_zone_ids[0]}--x-s3"
60+
)
61+
regular_bucket_name = f"{bucket_name_prefix}-regular-{my_uuid}"
62+
object_name = "basic-text-object"
63+
other_object = f"other/{object_name}"
64+
alt_object = f"alt/{object_name}"
65+
other_alt_object = f"other/alt/{object_name}"
66+
67+
object_keys = [object_name, other_object, alt_object, other_alt_object]
68+
69+
my_uuid = "0000"
70+
71+
stack_name = f"cfn-stack-s3-express-basics--{my_uuid}"
72+
stack = cloud_formation_resource.Stack(stack_name)
73+
vpc_id = "XXXXXXXXXXXXXXXXXXXXX"
74+
vpc_endpoint_id = f"vpce-{vpc_id}"
75+
76+
with stub_runner(error_code, stop_on_index) as runner:
77+
runner.add(s3_stubber.stub_list_objects_v2, directory_bucket_name, object_keys)
78+
runner.add(s3_stubber.stub_delete_objects, directory_bucket_name, object_keys)
79+
runner.add(s3_stubber.stub_delete_bucket, directory_bucket_name)
80+
runner.add(s3_stubber.stub_list_objects_v2, regular_bucket_name, object_keys)
81+
runner.add(s3_stubber.stub_delete_objects, regular_bucket_name, object_keys)
82+
runner.add(s3_stubber.stub_delete_bucket, regular_bucket_name)
83+
runner.add(cloud_formation_stubber.stub_delete_stack, stack_name)
84+
runner.add(ec2_stubber.stub_delete_vpc_endpoints, [vpc_endpoint_id])
85+
runner.add(ec2_stubber.stub_delete_vpc, vpc_id)
86+
87+
scenario = s3_express_getting_started.S3ExpressScenario(
88+
cloud_formation_resource, ec2_client, iam_client
89+
)
90+
91+
def mock_wait(self, **kwargs):
92+
return
93+
94+
# Mock the waiters.
95+
monkeypatch.setattr(waiter.Waiter, "wait", mock_wait)
96+
97+
scenario.s3_express_client = s3_client
98+
scenario.s3_regular_client = s3_client
99+
scenario.directory_bucket_name = directory_bucket_name
100+
if stop_on_index > 2:
101+
scenario.regular_bucket_name = regular_bucket_name
102+
103+
if stop_on_index > 5:
104+
scenario.stack = stack
105+
106+
if stop_on_index > 6:
107+
scenario.vpc_endpoint_id = vpc_endpoint_id
108+
109+
if stop_on_index > 7:
110+
scenario.vpc_id = vpc_id
111+
112+
scenario.cleanup()

0 commit comments

Comments
 (0)