Python ZipFileImportContext Example

说明

python zipfileimportcontext示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: ploneappdexteritybrowserimport_types

示例#1

    def testZipFileImportContext(self):
        portal = self.layer["portal"]
        types_tool = getToolByName(portal, "portal_types")

        zname = os.path.join(os.path.dirname(__file__), "import", "dexterity_export.zip")
        f = open(zname, "r")
        icontext = ZipFileImportContext(types_tool, f)

        types_xml = icontext.readDataFile("types.xml")
        self.assertTrue(types_xml, msg="Unable to read types.xml in sample import file")

        self.assertTrue(isinstance(icontext.getLastModified("types.xml"), DateTime))

        self.assertEqual(set(icontext.listDirectory("")), set(["types", "types.xml"]))

        self.assertEqual(set(icontext.listDirectory("types")), set(["test_type_two.xml", "test_type_one.xml"]))

        # test importIsTypesOnly check
        # self.assertTrue(icontext.importIsTypesOnly())

        f.close()

示例#2
文件: test_import.py项目: tkimnguyen/plone.app.dexterity

    def testZipFileImportContext(self):
        portal = self.layer['portal']
        types_tool = getToolByName(portal, 'portal_types')

        zname = os.path.join(
            os.path.dirname(__file__),
            'import',
            'dexterity_export.zip',
        )
        f = open(zname, 'r')
        icontext = ZipFileImportContext(types_tool, f)

        types_xml = icontext.readDataFile('types.xml')
        self.assertTrue(
            types_xml,
            msg='Unable to read types.xml in sample import file',
        )

        self.assertTrue(
            isinstance(
                icontext.getLastModified('types.xml'),
                DateTime
            )
        )

        self.assertEqual(
            set(icontext.listDirectory('')),
            set(['types', 'types.xml'])
        )

        self.assertEqual(
            set(icontext.listDirectory('types')),
            set(['test_type_two.xml', 'test_type_one.xml'])
        )

        # test importIsTypesOnly check
        # self.assertTrue(icontext.importIsTypesOnly())

        f.close()

展开阅读全文