'Test that symlinks are preserved when unpacking generated zips.'

def testZipFileWithSymlink(self):

    compressions = [zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED]
    for compression in compressions:
        outfd = StringIO.StringIO()
        infd1 = StringIO.StringIO('this    is    a    test    string')
        infd2 = StringIO.StringIO('this    is    another    test    string')
        with utils.StreamingZipWriter(outfd, compression=compression) as writer:
            writer.WriteFromFD(infd1, 'test1.txt')
            writer.WriteFromFD(infd2, 'subdir/test2.txt')
            writer.WriteSymlink('test1.txt', 'test1.txt.link')
            writer.WriteSymlink('subdir/test2.txt', 'test2.txt.link')
        with utils.TempDirectory() as temp_dir:
            zip_path = os.path.join(temp_dir, 'archive.zip')
            with open(zip_path, 'wb') as fd:
                fd.write(outfd.getvalue())
            zip_fd = zipfile.ZipFile(outfd, 'r')
            link_info = zip_fd.getinfo('test1.txt.link')
            self.assertEqual(link_info.external_attr, ((420 | 40960) << 16))
            self.assertEqual(link_info.create_system, 3)
            link_contents = zip_fd.read('test1.txt.link')
            self.assertEqual(link_contents, 'test1.txt')
            link_info = zip_fd.getinfo('test2.txt.link')
            self.assertEqual(link_info.external_attr, ((420 | 40960) << 16))
            self.assertEqual(link_info.create_system, 3)
            link_contents = zip_fd.read('test2.txt.link')
            self.assertEqual(link_contents, 'subdir/test2.txt')
