Exemplo n.º 1
0
 def test_metadata_writing(self):
     fs = zipstorage.ZipStorage("testtemp.zip", "w")
     fs.set_active_configuration('testing.confml')
     fs.close()
     fs = zipstorage.ZipStorage("testtemp.zip", "r")
     self.assertEquals(fs.get_active_configuration(), 'testing.confml')
     fs.close()
     os.unlink("testtemp.zip")
Exemplo n.º 2
0
 def test_open_a_non_zipfile_fails(self):
     try:
         storage = zipstorage.ZipStorage("data/onefile/test.txt", "r")
         storage.close()
         self.fail("opening a non zipfile for ZipStorage succeeded?")
     except zipstorage.ZipException, e:
         self.assertTrue(True)
Exemplo n.º 3
0
 def test_open_nonexisting_storage_fails(self):
     try:
         storage = zipstorage.ZipStorage("foo.zip", "r")
         storage.close()
         self.fail("opening a non existing ZipStorage succeeded?")
     except zipstorage.ZipException:
         self.assertTrue(True)
Exemplo n.º 4
0
 def test_open_existing_storage_and_close_twice(self):
     storage = zipstorage.ZipStorage(datazip, "r")
     storage.close()
     try:
         storage.close()
         self.fail('closing twice succeeds!')
     except exceptions.StorageException:
         pass
Exemplo n.º 5
0
 def get_temp_zip_storage(self, path, empty=False):
     """
     Get a new zip storage located in the temp/ directory.
     
     @param path: Path of the storage zip file relative to the temp/ directory.
     @param empty: If False, the DATA_ZIP is copied to the location specified
         by 'path' and returned as a read-only storage. If True, a new writable
         empty storage is returned.
     """
     full_path = os.path.join(TEMP_DIR, path)
     if not empty:
         self.create_dir_for_file_path(full_path)
         shutil.copy2(DATA_ZIP, full_path)
         return zipstorage.ZipStorage(full_path, 'r')
     else:
         if os.path.exists(full_path):
             os.remove(full_path)
         return zipstorage.ZipStorage(full_path, 'w')
Exemplo n.º 6
0
 def test_open_resource_new_file(self):
     storage = zipstorage.ZipStorage("testnewfile.zip", "w")
     res = storage.open_resource("data/newfile.txt", "w")
     res.write("test write")
     self.assertTrue(res)
     self.assertTrue(isinstance(res, api.Resource))
     res.close()
     self.assertEquals(storage.list_resources("", recurse=True),
                       ['data/newfile.txt'])
     storage.close()
     os.unlink("testnewfile.zip")
Exemplo n.º 7
0
 def test_list_resources_nonrecurse(self):
     storage = zipstorage.ZipStorage("testnonrecurse.zip", "w")
     res = storage.open_resource("data/morestuff.confml", "w")
     res.close()
     res = storage.open_resource("data/prodX.confml", "w")
     res.close()
     file_array = storage.list_resources("data")
     self.assertEquals(file_array[0], "data/morestuff.confml")
     self.assertEquals(file_array[1], "data/prodX.confml")
     storage.close()
     os.unlink("testnonrecurse.zip")
Exemplo n.º 8
0
 def test_list_resources_recurse(self):
     storage = zipstorage.ZipStorage("testrecurse.zip", "w")
     res = storage.open_resource("data/foo/morestuff.confml", "w")
     res.close()
     res = storage.open_resource("data/prodX.confml", "w")
     res.close()
     res = storage.open_resource("data/ncp11/confml/jallaa.confml", "w")
     res.close()
     file_array = storage.list_resources("data", recurse=True)
     self.assertEquals(file_array, [
         'data/foo/morestuff.confml', 'data/prodX.confml',
         'data/ncp11/confml/jallaa.confml'
     ])
     storage.close()
     os.unlink("testrecurse.zip")
Exemplo n.º 9
0
    def _run_test_list_resources(self, zip_file):
        full_path = os.path.join(ROOT_PATH, 'list_resources_data', zip_file)
        zs = zipstorage.ZipStorage(full_path, 'r')
        res_list = zs.list_resources('/', recurse=True, empty_folders=True)

        expected = [('folder', 'test'), ('folder', 'test/layer'),
                    ('folder', 'test/layer/confml'),
                    ('folder', 'test/layer/content'),
                    ('folder', 'test/layer/content/empty'),
                    ('folder', 'test/layer/content/something'),
                    ('resource', 'test/layer/content/something/x.txt'),
                    ('folder', 'test/layer/doc'),
                    ('folder', 'test/layer/implml'),
                    ('resource', 'test/layer/root.confml'),
                    ('resource', 'test/root.confml')]
        for type, res in expected:
            if type == 'resource':
                self.assertTrue(zs.is_resource(res),
                                "zs.is_resource('%s') returns False" % res)
            elif type == 'folder':
                self.assertTrue(zs.is_folder(res),
                                "zs.is_folder('%s') returns False" % res)
            else:
                raise RuntimeError('Invalid type')
Exemplo n.º 10
0
 def setUp(self):
     shutil.copyfile(datazip, "temptests.zip")
     self.storage = zipstorage.ZipStorage("temptests.zip", "a")
Exemplo n.º 11
0
 def test_open_existing_storage(self):
     storage = zipstorage.ZipStorage(datazip, "r")
     storage.close()
Exemplo n.º 12
0
 def test_create_new_storage(self):
     storage = zipstorage.ZipStorage("new.zip", "w")
     storage.close()
     self.assertTrue(os.path.exists("new.zip"))
     os.unlink("new.zip")