def test_unzip(self):
     """
     L{twisted.python.zipstream.unzip} should extract all files from a zip
     archive
     """
     numfiles = 3
     zpfilename = self.makeZipFile([str(i) for i in range(numfiles)])
     zipstream.unzip(zpfilename, self.unzipdir.path)
     self.assertEqual(
         set(self.unzipdir.listdir()),
         set(map(str, range(numfiles))))
     for i in range(numfiles):
         self.assertEqual(self.unzipdir.child(str(i)).getContent(), str(i))
 def test_unzipDirectory(self):
     """
     The path to which a file is extracted by L{zipstream.unzip} is
     determined by joining the C{directory} argument to C{unzip} with the
     path within the archive of the file being extracted.
     """
     numfiles = 3
     zpfilename = self.makeZipFile([str(i) for i in range(numfiles)], 'foo')
     zipstream.unzip(zpfilename, self.unzipdir.path)
     self.assertEqual(
         set(self.unzipdir.child('foo').listdir()),
         set(map(str, range(numfiles))))
     for i in range(numfiles):
         self.assertEqual(
             self.unzipdir.child('foo').child(str(i)).getContent(), str(i))
    def test_overwrite(self):
        """
        L{twisted.python.zipstream.unzip} and
        L{twisted.python.zipstream.unzipIter} shouldn't overwrite files unless
        the 'overwrite' flag is passed
        """
        testfile = self.unzipdir.child('0')
        zpfilename = self.makeZipFile(['OVERWRITTEN'])

        testfile.setContent('NOT OVERWRITTEN')
        zipstream.unzip(zpfilename, self.unzipdir.path)
        self.assertEquals(testfile.open().read(), 'NOT OVERWRITTEN')
        zipstream.unzip(zpfilename, self.unzipdir.path, overwrite=True)
        self.assertEquals(testfile.open().read(), 'OVERWRITTEN')

        testfile.setContent('NOT OVERWRITTEN')
        uziter = zipstream.unzipIter(zpfilename, self.unzipdir.path)
        uziter.next()
        self.assertEquals(testfile.open().read(), 'NOT OVERWRITTEN')
        uziter = zipstream.unzipIter(zpfilename, self.unzipdir.path,
                                     overwrite=True)
        uziter.next()
        self.assertEquals(testfile.open().read(), 'OVERWRITTEN')