MCPcopy
hub / github.com/pyodide/pyodide / test_deploy_to_s3_overwrite

Function test_deploy_to_s3_overwrite

tools/tests/test_deploy_s3.py:29–102  ·  view source on GitHub ↗
(tmp_path, capsys)

Source from the content-addressed store, hash-verified

27
28@mock_aws
29def test_deploy_to_s3_overwrite(tmp_path, capsys):
30 (tmp_path / "a.whl").write_text("a")
31 (tmp_path / "b.tar").write_text("b")
32 (tmp_path / "c.zip").write_text("c")
33
34 bucket_name = "mybucket"
35 s3_client = boto3.client("s3", region_name="us-east-1")
36 s3_client.create_bucket(Bucket=bucket_name)
37
38 deploy_to_s3_main(
39 tmp_path,
40 remote_prefix=PurePosixPath("dev/full/"),
41 bucket=bucket_name,
42 cache_control="max-age=30758400",
43 pretend=False,
44 overwrite=False,
45 rm_remote_prefix=False,
46 access_key_env="AWS_ACCESS_KEY_ID",
47 secret_key_env="AWS_SECRET_ACCESS_KEY",
48 )
49
50 def get_object_list():
51 response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix="dev/full/")
52 return {obj["Key"] for obj in response["Contents"]}
53
54 assert get_object_list() == {"dev/full/a.whl", "dev/full/b.tar", "dev/full/c.zip"}
55
56 # Writing a second time to the same prefix with overwrite=False should fail
57 with pytest.raises(Exception): # noqa: B017
58 deploy_to_s3_main(
59 tmp_path,
60 remote_prefix=PurePosixPath("dev/full/"),
61 bucket=bucket_name,
62 cache_control="max-age=30758400",
63 pretend=False,
64 overwrite=False,
65 rm_remote_prefix=False,
66 access_key_env="AWS_ACCESS_KEY_ID",
67 secret_key_env="AWS_SECRET_ACCESS_KEY",
68 )
69 msg = "Cannot upload .* because it already exists"
70 captured = capsys.readouterr()
71 # Check for error message in last two lines of output
72 assert re.search(msg, "\n".join(captured.out.splitlines()[-2:]))
73
74 # Setting overwrite=True should overwrite the files
75 deploy_to_s3_main(
76 tmp_path,
77 remote_prefix=PurePosixPath("dev/full/"),
78 bucket=bucket_name,
79 cache_control="max-age=30758400",
80 pretend=False,
81 overwrite=True,
82 rm_remote_prefix=False,
83 access_key_env="AWS_ACCESS_KEY_ID",
84 secret_key_env="AWS_SECRET_ACCESS_KEY",
85 )
86 assert get_object_list() == {"dev/full/a.whl", "dev/full/b.tar", "dev/full/c.zip"}

Callers

nothing calls this directly

Calls 4

deploy_to_s3_mainFunction · 0.90
get_object_listFunction · 0.85
write_textMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…