def test_save_zip(self): """TODO: 2 cases 1. from "zip" to "zip" 2. from "flat" to "zip" """ container = Container() container.open(join("samples", "example.odt")) container.save(join("trash", "example.odt")) new_container = Container() new_container.open(join("trash", "example.odt")) mimetype = new_container.get_part("mimetype") self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odt"]))
def test_save_zip(self): """TODO: 2 cases 1. from "zip" to "zip" 2. from "flat" to "zip" """ container = Container() container.open(join('samples', 'example.odt')) container.save(join('trash', 'example.odt')) new_container = Container() new_container.open(join('trash', 'example.odt')) mimetype = new_container.get_part('mimetype') self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt']))
def test_save_folder_to_zip(self): container = Container() container.open(join("samples", "example.odt")) container.save(join("trash", "example.odt"), packaging="folder") path = join("trash", "example.odt" + ".folder", "mimetype") self.assertEqual(isfile(path), True) new_container = Container() new_container.open(join("trash", "example.odt.folder")) new_container.save(join("trash", "example_bis.odt"), packaging="zip") new_container_zip = Container() new_container_zip.open(join("trash", "example_bis.odt")) mimetype = new_container_zip.get_part("mimetype") self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odt"]))
def test_save_folder_to_zip(self): container = Container() container.open(join('samples', 'example.odt')) container.save(join('trash', 'example.odt'), packaging='folder') path = join('trash', 'example.odt' + '.folder', 'mimetype') self.assertEqual(isfile(path), True) new_container = Container() new_container.open(join('trash', 'example.odt.folder')) new_container.save(join('trash', 'example_bis.odt'), packaging='zip') new_container_zip = Container() new_container_zip.open(join('trash', 'example_bis.odt')) mimetype = new_container_zip.get_part('mimetype') self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt']))
def test_del_part(self): container = Container() container.open(join('samples', 'example.odt')) # Not a realistic test path = 'content' container.del_part(path) self.assertRaises(ValueError, container.get_part, path)
def test_set_part(self): container = Container() container.open(join('samples', 'example.odt')) path = join('Pictures', 'a.jpg') data = to_bytes('JFIFIThinéééékImAnImage') container.set_part(path, data) self.assertEqual(container.get_part(path), data)
def test_get_part_mimetype(self): container = Container() container.open(join('samples', 'example.odt')) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt'])) self.assertEqual(umimetype, ODF_EXTENSIONS['odt'])
def test_drawing_template(self): path = join("..", "odfdo", "templates", "drawing.otg") container = Container.new(path) mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odg"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odg"])
def setUp(self): container = Container('samples/example.odt') self.container = container self.content_part = content_part = XmlPart(ODF_CONTENT, container) self.paragraph_element = content_part.get_element('//text:p[1]') self.annotation_element = ( content_part.get_element('//office:annotation[1]'))
def test_spreadsheet_template(self): path = join('..', 'odfdo', 'templates', 'spreadsheet.ots') container = Container.new(path) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['ods'])) self.assertEqual(umimetype, ODF_EXTENSIONS['ods'])
def test_set_part(self): container = Container() container.open(join("samples", "example.odt")) path = join("Pictures", "a.jpg") data = to_bytes("JFIFIThinéééékImAnImage") container.set_part(path, data) self.assertEqual(container.get_part(path), data)
def test_spreadsheet_template(self): path = join("..", "odfdo", "templates", "spreadsheet.ots") container = Container.new(path) mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["ods"])) self.assertEqual(umimetype, ODF_EXTENSIONS["ods"])
def test_get_part_mimetype(self): container = Container() container.open(join("samples", "example.odt")) mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odt"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odt"])
def test_text_template(self): path = '../odfdo/templates/text.ott' container = Container.new(path) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt'])) self.assertEqual(umimetype, ODF_EXTENSIONS['odt'])
def test_presentation_template(self): path = join("..", "odfdo", "templates", "presentation.otp") container = Container.new(path) mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odp"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odp"])
def test_drawing_template(self): path = join('..', 'odfdo', 'templates', 'drawing.otg') container = Container.new(path) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odg'])) self.assertEqual(umimetype, ODF_EXTENSIONS['odg'])
def test_presentation_template(self): path = join('..', 'odfdo', 'templates', 'presentation.otp') container = Container.new(path) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odp'])) self.assertEqual(umimetype, ODF_EXTENSIONS['odp'])
def test_del_part(self): container = Container() container.open(join("samples", "example.odt")) # Not a realistic test path = "content" container.del_part(path) self.assertRaises(ValueError, container.get_part, path)
def test_filesystem(self): path = join('samples', 'example.odt') container = Container() container.open(path) mimetype = container.get_part('mimetype') umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt'])) self.assertEqual(umimetype, ODF_EXTENSIONS['odt'])
def test_filesystem(self): path = join("samples", "example.odt") container = Container() container.open(path) mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odt"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odt"])
def test_load_folder(self): container = Container() container.open(join('samples', 'example.odt')) container.save(join('trash', 'example_f.odt'), packaging='folder') new_container = Container() new_container.open(join('trash', 'example_f.odt.folder')) content = new_container.get_part(ODF_CONTENT) self.assertIn(b'<office:document-content', content) mimetype = new_container.get_part('mimetype') self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS['odt'])) path = join('Pictures', 'a.jpg') data = to_bytes('JFIFIThiééénkImA §ççànImage') new_container.set_part(path, data) self.assertEqual(new_container.get_part(path), to_bytes(data)) # Not a realistic test path = 'content' new_container.del_part(path) self.assertRaises(ValueError, new_container.get_part, path)
def test_load_folder(self): container = Container() container.open(join("samples", "example.odt")) container.save(join("trash", "example_f.odt"), packaging="folder") new_container = Container() new_container.open(join("trash", "example_f.odt.folder")) content = new_container.get_part(ODF_CONTENT) self.assertIn(b"<office:document-content", content) mimetype = new_container.get_part("mimetype") self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odt"])) path = join("Pictures", "a.jpg") data = to_bytes("JFIFIThiééénkImA §ççànImage") new_container.set_part(path, data) self.assertEqual(new_container.get_part(path), to_bytes(data)) # Not a realistic test path = "content" new_container.del_part(path) self.assertRaises(ValueError, new_container.get_part, path)
def test_save_folder(self): container = Container() container.open(join("samples", "example.odt")) container.save(join("trash", "example.odt"), packaging="folder") path = join("trash", "example.odt" + ".folder", "mimetype") self.assertEqual(isfile(path), True) path = join("trash", "example.odt" + ".folder", "content.xml") self.assertEqual(isfile(path), True) path = join("trash", "example.odt" + ".folder", "meta.xml") self.assertEqual(isfile(path), True) path = join("trash", "example.odt" + ".folder", "styles.xml") self.assertEqual(isfile(path), True) path = join("trash", "example.odt" + ".folder", "settings.xml") self.assertEqual(isfile(path), True)
def test_save_folder(self): container = Container() container.open(join('samples', 'example.odt')) container.save(join('trash', 'example.odt'), packaging='folder') path = join('trash', 'example.odt' + '.folder', 'mimetype') self.assertEqual(isfile(path), True) path = join('trash', 'example.odt' + '.folder', 'content.xml') self.assertEqual(isfile(path), True) path = join('trash', 'example.odt' + '.folder', 'meta.xml') self.assertEqual(isfile(path), True) path = join('trash', 'example.odt' + '.folder', 'styles.xml') self.assertEqual(isfile(path), True) path = join('trash', 'example.odt' + '.folder', 'settings.xml') self.assertEqual(isfile(path), True)
def test_mimetype_setter(self): container = Container() container.open(join("samples", "example.odt")) container.mimetype = ODF_EXTENSIONS["odt"] self.assertEqual(container.mimetype, ODF_EXTENSIONS["odt"])
def test_drawing_type(self): container = Container.new("drawing") mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odg"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odg"])
def test_spreadsheet_type(self): container = Container.new("spreadsheet") mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["ods"])) self.assertEqual(umimetype, ODF_EXTENSIONS["ods"])
def test_get_part_xml(self): container = Container() container.open(join("samples", "example.odt")) content = container.get_part(ODF_CONTENT) self.assertIn(b"<office:document-content", content)
def test_presentation_type(self): container = Container.new("presentation") mimetype = container.get_part("mimetype") umimetype = container.mimetype self.assertEqual(mimetype, to_bytes(ODF_EXTENSIONS["odp"])) self.assertEqual(umimetype, ODF_EXTENSIONS["odp"])
def test_clone(self): container = Container.new("text") clone = container.clone self.assertEqual(clone.path, None)