Пример #1
0
    def testLocalFileSystemLinkCDM(self):
        d = HTTPDelivery()
        rootDir = TemporaryDirectory()
        d.serverURI = 'http://localhost/content/'
        d.repositoryPath = rootDir.name
        d.repositoryPath = '/var/www/repository'
#        ioc.Initializer.initialize(d)
        cdm = LocalFileSystemLinkCDM()
        cdm.delivery = d

        try:
            exceptionRaised = False
            cdm.publishFromFile('a/../../b', 'somefile.txt')
        except PathNotFound:
            exceptionRaised = True
        self.assertTrue(exceptionRaised, 'No exception was raised on out of repository path')

        # test publish from a file from the file system
        try:
            srcTmpFile = NamedTemporaryFile()
            dstFile = join('testdir7', 'tempfile.txt')
            cdm.publishFromFile(dstFile, srcTmpFile.name)
            dstLinkPath = join(d.getRepositoryPath(), dstFile + cdm._linkExt)
            self.assertTrue(isfile(dstLinkPath))
            with open(dstLinkPath) as f:
                links = json.load(f)
                self.assertIsInstance(links, list)
                self.assertEqual(links[0][0], 'FS')
                self.assertEqual(srcTmpFile.name, links[0][1])
                self.assertEqual(stat(srcTmpFile.name).st_mtime,
                                 cdm.getTimestamp('testdir7/tempfile.txt'))
        finally:
            rmtree(dirname(dstLinkPath))

        # test publish from a file from a zip archive
        try:
            dstFile = join('testdir8', 'tempfile2.txt')
            inFileName = join('dir1', 'subdir2', 'file1.txt')
            srcFilePath = join(dirname(__file__), 'test.zip', inFileName)
            cdm.publishFromFile(dstFile, srcFilePath)
            dstLinkPath = join(d.getRepositoryPath(), dstFile + cdm._linkExt)
            self.assertTrue(isfile(dstLinkPath))
            with open(dstLinkPath) as f:
                links = json.load(f)
                self.assertEqual(links[0][0], 'ZIP')
                zipPath = links[0][1]
                inPath = normOSPath(links[0][2], True)
                linkPath = join(zipPath, inPath)
                self.assertEqual(normpath(linkPath), normpath(srcFilePath))
                self.assertEqual(stat(join(dirname(__file__), 'test.zip')).st_mtime,
                                 cdm.getTimestamp('testdir8/tempfile2.txt'))
        finally:
            rmtree(dirname(dstLinkPath))

        # test publish from a directory from the file system
        srcTmpDir = TemporaryDirectory()
        dirs = (join(srcTmpDir.name, 'test1/subdir1'), join(srcTmpDir.name, 'test2/subdir1'))
        for dir in dirs:
            makedirs(dir)
            with open(join(dir, 'text.html'), 'w+') as _f: pass
        try:
            cdm.publishFromDir('testlink1', srcTmpDir.name)
            dstLinkPath = join(d.getRepositoryPath(), 'testlink1' + cdm._linkExt)
            self.assertTrue(isfile(dstLinkPath))
            with open(dstLinkPath) as f:
                links = json.load(f)
                self.assertEqual(links[0][0], 'FS')
                self.assertEqual(srcTmpDir.name, links[0][1])
                self.assertEqual(stat(join(srcTmpDir.name, 'test1/subdir1/text.html')).st_mtime,
                                 cdm.getTimestamp('testlink1/test1/subdir1/text.html'))
            # test path remove
            delPath1 = 'testlink1/test1/subdir1/text.html'
            cdm.removePath(delPath1)
            self.assertTrue(isfile(join(d.getRepositoryPath(), delPath1 + '.deleted')))
            delPath2 = 'testlink1/test1'
            cdm.removePath(delPath2)
            self.assertTrue(isfile(join(d.getRepositoryPath(), delPath2 + '.deleted')))
        finally:
            rmtree(join(d.getRepositoryPath(), 'testlink1'))
            remove(dstLinkPath)

        # test publish from a file from a zip archive
        try:
            srcFilePath = join(dirname(__file__), 'test.zip', 'dir1') + sep
            cdm.publishFromFile('testlink2', srcFilePath)
            dstLinkPath = join(d.getRepositoryPath(), 'testlink2' + cdm._linkExt)
            self.assertTrue(isfile(dstLinkPath))
            with open(dstLinkPath) as f:
                links = json.load(f)
                self.assertEqual(links[0][0], 'ZIP')
                zipPath = links[0][1]
                inPath = normOSPath(links[0][2], True)
                link = join(zipPath, inPath)
                self.assertEqual(link, srcFilePath)
                self.assertEqual(stat(join(dirname(__file__), 'test.zip')).st_mtime,
                                 cdm.getTimestamp('testlink2/subdir1/file1.txt'))
            # test path remove
            delPath1 = 'testlink2/subdir1/file1.txt'
            cdm.removePath(delPath1)
            self.assertTrue(isfile(join(d.getRepositoryPath(), delPath1 + '.deleted')))
            delPath2 = 'testlink2/subdir1/'
            self.assertTrue(isdir(join(d.getRepositoryPath(), delPath2)))
            cdm.removePath(delPath2)
            self.assertTrue(isfile(join(d.getRepositoryPath(), delPath2.rstrip('/') + '.deleted')))
            self.assertFalse(isdir(join(d.getRepositoryPath(), delPath2)))
            self.assertFalse(isfile(join(d.getRepositoryPath(), delPath1 + '.deleted')))
        finally:
            rmtree(join(d.getRepositoryPath(), 'testlink2'))
            remove(dstLinkPath)
Пример #2
0
def contentDeliveryManager() -> ICDM:
    cdm = LocalFileSystemLinkCDM() if use_linked_cdm() else LocalFileSystemCDM()
    cdm.delivery = delivery()
    return cdm
Пример #3
0
def contentDeliveryManager() -> ICDM:
    cdm = LocalFileSystemLinkCDM();
    cdm.delivery = delivery()
    return cdm