Path: blob/develop/tests/functional/cloudformation/test_package.py
1567 views
#!/usr/bin/env python1# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# http://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.1314import shutil15import tempfile16import os17import zipfile1819from unittest import TestCase20from awscli.customizations.cloudformation.artifact_exporter import make_zip21from awscli.testutils import skip_if_windows222324class TestPackageZipFiles(TestCase):2526def setUp(self):27self.rootdir = tempfile.mkdtemp()28self.ziproot = os.path.join(self.rootdir, "zipcontents")2930os.mkdir(self.ziproot)3132def tearDown(self):33shutil.rmtree(self.rootdir)3435@skip_if_windows(36"Symlinks are not supported on Python 2.x + Windows, and require "37"administrator privleges on Python 3.x + Windows."38)39def test_must_follow_symlinks(self):40data = "hello world"41data_file = os.path.join(self.rootdir, "data.txt")4243with open(data_file, "w") as fp:44fp.write(data)4546# Create symlink within the zip root47link_name = os.path.join(self.ziproot, "data-link.txt")48os.symlink(data_file, link_name)4950# Zip up the contents of folder `ziproot` which contains the symlink51zipfile_path = make_zip(os.path.join(self.rootdir, "archive"), self.ziproot)5253# Now verify that the zipfile includes contents of the data file we created54myzip = zipfile.ZipFile(zipfile_path)55# Data file should be the only file within the zip56self.assertEqual(["data-link.txt"], myzip.namelist())57myfile = myzip.open("data-link.txt", "r")5859# Its content should be equal the value we wrote.60self.assertEqual(data.encode("utf-8"), myfile.read())616263