Python ZipFileImportContext Example

Introduction

The python zipfileimportcontext example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Python

Namespace/package name: ploneappdexteritybrowserimport_types

Example#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()

Example#2
File: test_import.pyProject: 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()