Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/cloudformation/test_package.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
15
import shutil
16
import tempfile
17
import os
18
import zipfile
19
20
from unittest import TestCase
21
from awscli.customizations.cloudformation.artifact_exporter import make_zip
22
from awscli.testutils import skip_if_windows
23
24
25
class TestPackageZipFiles(TestCase):
26
27
def setUp(self):
28
self.rootdir = tempfile.mkdtemp()
29
self.ziproot = os.path.join(self.rootdir, "zipcontents")
30
31
os.mkdir(self.ziproot)
32
33
def tearDown(self):
34
shutil.rmtree(self.rootdir)
35
36
@skip_if_windows(
37
"Symlinks are not supported on Python 2.x + Windows, and require "
38
"administrator privleges on Python 3.x + Windows."
39
)
40
def test_must_follow_symlinks(self):
41
data = "hello world"
42
data_file = os.path.join(self.rootdir, "data.txt")
43
44
with open(data_file, "w") as fp:
45
fp.write(data)
46
47
# Create symlink within the zip root
48
link_name = os.path.join(self.ziproot, "data-link.txt")
49
os.symlink(data_file, link_name)
50
51
# Zip up the contents of folder `ziproot` which contains the symlink
52
zipfile_path = make_zip(os.path.join(self.rootdir, "archive"), self.ziproot)
53
54
# Now verify that the zipfile includes contents of the data file we created
55
myzip = zipfile.ZipFile(zipfile_path)
56
# Data file should be the only file within the zip
57
self.assertEqual(["data-link.txt"], myzip.namelist())
58
myfile = myzip.open("data-link.txt", "r")
59
60
# Its content should be equal the value we wrote.
61
self.assertEqual(data.encode("utf-8"), myfile.read())
62
63