def test_to_zip_manifest(self): fm = ByteStreamManager() fm.register('addfirst', 'SilentHill') fm.register('addsecond', 'SinCity') fm.register('mimetype', 'MaxPayne') zippo = ZipMock() fm._tozip(zippo) self.assertEqual(zippo.writtenfiles[0], 'mimetype', "file 'mimetype' SHOULD be the first written file")
def test_tobytes_result_content(self): def get_filelist(buffer): z = zipfile.ZipFile(io.BytesIO(buffer), 'r') files = z.namelist() z.close() return files data = self.get_empty_odt() fm = ByteStreamManager(data) mimetype = fm.get_bytes('mimetype') fm.register('mimetype', mimetype) result = fm.tobytes() self.assertEqual(mimetype, result[38:77]) expected_files = get_filelist(data) result_files = get_filelist(result) self.assertSetEqual(set(expected_files), set(result_files))
def test_tobytes_result_type(self): fm = ByteStreamManager() fm.register('addfirst', 'SilentHill') fm.register('addsecond', 'SinCity') fm.register('mimetype', 'MaxPayne') resultbuffer = fm.tobytes() self.assertTrue(is_zipfile(BytesIO(resultbuffer)))
def test_tobytes_result_type(self): fm = ByteStreamManager() fm.register('addfirst', 'SilentHill') fm.register('addsecond', 'SinCity') fm.register('mimetype', 'MaxPayne') resultbuffer = fm.tobytes() self.assertTrue(zipfile.is_zipfile(io.BytesIO(resultbuffer)))
def test_tobytes_result_content(self): def get_filelist(buffer): z = zipfile.ZipFile(BytesIO(buffer), 'r') files = z.namelist() z.close() return files data = self.get_empty_odt() fm = ByteStreamManager(data) mimetype = fm.get_bytes('mimetype') fm.register('mimetype', mimetype) result = fm.tobytes() self.assertEqual(mimetype, result[38:77]) expected_files = get_filelist(data) result_files = get_filelist(result) self.assertSetEqual(set(expected_files), set(result_files))
def test_constructor(self): data = self.get_empty_odt() fm = ByteStreamManager(data) self.assertTrue(fm.has_zip())