Example #1
0
    def test_new_content_types_text(self):
        xml_base = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n' \
                   '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\r\n' \
                   '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>\r\n' \
                   '<Default Extension="xml" ContentType="application/xml"/>\r\n' \
                   '<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>\r\n' \
                   '{many_tag_sheets}\r\n' \
                   '{tag_sharedStrings}\r\n' \
                   '<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>\r\n' \
                   '<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>\r\n' \
                   '</Types>'

        xml_tag_sheet = '<Override PartName="/xl/worksheets/sheet{sheet_id}.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>\r\n'

        xml_tag_sharedStrings = '<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>\r\n'

        many_tag_sheets = xml_tag_sheet.format(sheet_id=1) + \
                          xml_tag_sheet.format(sheet_id=2) + \
                          xml_tag_sheet.format(sheet_id=3) + \
                          xml_tag_sheet.format(sheet_id=4) + \
                          xml_tag_sheet.format(sheet_id=5) + \
                          xml_tag_sheet.format(sheet_id=6) + \
                          xml_tag_sheet.format(sheet_id=7) + \
                          xml_tag_sheet.format(sheet_id=8) + \
                          xml_tag_sheet.format(sheet_id=9) + \
                          xml_tag_sheet.format(sheet_id=10)

        db = Database()
        db.add_ws('Sheet1', {})
        db.add_ws('Sheet2', {})
        db.add_ws('Sheet3', {})
        db.add_ws('Sheet4', {})
        db.add_ws('Sheet5', {})
        db.add_ws('Sheet6', {})
        db.add_ws('Sheet7', {})
        db.add_ws('Sheet8', {})
        db.add_ws('Sheet9', {})
        db.add_ws('Sheet10', {})

        # test without and sharedStrings in db
        self.assertEqual(
            new_content_types_text(db),
            xml_base.format(many_tag_sheets=many_tag_sheets,
                            tag_sharedStrings=''))

        # test with and sharedStrings in db
        db._sharedStrings = ['text']
        self.assertEqual(
            new_content_types_text(db),
            xml_base.format(many_tag_sheets=many_tag_sheets,
                            tag_sharedStrings=xml_tag_sharedStrings))
Example #2
0
    def test_workbookrels_text(self):
        xml_base = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n' \
                   '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\r\n' \
                   '{many_tag_sheets}\r\n' \
                   '{tag_sharedStrings}\r\n' \
                   '</Relationships>'
        xml_tag_sheet = '<Relationship Target="worksheets/sheet{sheet_num}.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Id="rId{sheet_num}"/>\r\n'
        tag_sharedStrings = '<Relationship Target="sharedStrings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Id="rId11"/>\r\n'

        many_tag_sheets = xml_tag_sheet.format(sheet_num=1) + \
                          xml_tag_sheet.format(sheet_num=2) + \
                          xml_tag_sheet.format(sheet_num=3) + \
                          xml_tag_sheet.format(sheet_num=4) + \
                          xml_tag_sheet.format(sheet_num=5) + \
                          xml_tag_sheet.format(sheet_num=6) + \
                          xml_tag_sheet.format(sheet_num=7) + \
                          xml_tag_sheet.format(sheet_num=8) + \
                          xml_tag_sheet.format(sheet_num=9) + \
                          xml_tag_sheet.format(sheet_num=10)

        db = Database()
        db.add_ws('Sheet1', {})
        db.add_ws('Sheet2', {})
        db.add_ws('Sheet3', {})
        db.add_ws('Sheet4', {})
        db.add_ws('Sheet5', {})
        db.add_ws('Sheet6', {})
        db.add_ws('Sheet7', {})
        db.add_ws('Sheet8', {})
        db.add_ws('Sheet9', {})
        db.add_ws('Sheet10', {})
        # test without sharedStrings
        self.assertEqual(
            new_workbookrels_text(db),
            xml_base.format(many_tag_sheets=many_tag_sheets,
                            tag_sharedStrings=''))
        # test with sharedStrings in db
        db._sharedStrings = ['text']
        self.assertEqual(
            new_workbookrels_text(db),
            xml_base.format(many_tag_sheets=many_tag_sheets,
                            tag_sharedStrings=tag_sharedStrings))