コード例 #1
0
ファイル: local_filesystem.py プロジェクト: vivienney/Ally-Py
    def testLocalFilesystemCDM(self):
        d = HTTPDelivery()
        rootDir = TemporaryDirectory()
        d.serverURI = 'http://localhost/content/'
        d.repositoryPath = rootDir.name
        #        d.repositoryPath = '/var/www/repository'
        #        ioc.Initializer.initialize(d)
        cdm = LocalFileSystemCDM()
        cdm.delivery = d

        # test publish from a file from the file system
        try:
            srcTmpFile = NamedTemporaryFile(delete=False)
            srcTmpFile.close()
            dstPath = 'testdir1/tempfile.txt'
            cdm.publishFromFile(dstPath, srcTmpFile.name)
            dstFilePath = join(d.getRepositoryPath(), normOSPath(dstPath))
            self.assertTrue(isfile(dstFilePath))
            self.assertEqual(
                datetime.fromtimestamp(stat(dstFilePath).st_mtime),
                cdm.getTimestamp(dstPath))
        finally:
            rmtree(dirname(dstFilePath))
            remove(srcTmpFile.name)

        # test publish from a file from a zip archive
        try:
            inFileName = join('dir1', 'subdir2', 'file1.txt')
            dstPath = join('testdir2', 'tempfile2.txt')
            cdm.publishFromFile(
                dstPath, join(dirname(__file__), 'test.zip', inFileName))
            dstFilePath = join(d.getRepositoryPath(), normOSPath(dstPath))
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(dirname(dstFilePath))

        # test publish from a directory from the file system
        srcTmpDir = TemporaryDirectory()
        dirs = ('test1/subdir1', 'test2/subdir1')
        for dir in dirs:
            fullPath = join(srcTmpDir.name, dir)
            makedirs(fullPath)
            with open(join(fullPath, 'text.html'), 'w') as _f:
                pass
        try:
            cdm.publishFromDir('testdir3', srcTmpDir.name)
            dstDirPath = join(d.getRepositoryPath(), 'testdir3')
            for dir in dirs:
                dstFilePath = join(dstDirPath, dir, 'text.html')
                self.assertTrue(isfile(dstFilePath))
                self.assertEqual(
                    datetime.fromtimestamp(stat(dstFilePath).st_mtime),
                    cdm.getTimestamp(join('testdir3', dir, 'text.html')))
            # test remove path
            filePath = 'testdir3/test1/subdir1/text.html'
            self.assertTrue(isfile(join(d.getRepositoryPath(), filePath)))
            cdm.republish(filePath, filePath + '.new')
            self.assertTrue(
                isfile(join(d.getRepositoryPath(), filePath + '.new')))
            cdm.republish(filePath + '.new', filePath)
            cdm.remove(filePath)
            self.assertFalse(isfile(join(d.getRepositoryPath(), filePath)))
            dirPath = 'testdir3/test2'
            self.assertTrue(isdir(join(d.getRepositoryPath(), dirPath)))
            cdm.remove(dirPath)
            self.assertFalse(isdir(join(d.getRepositoryPath(), dirPath)))
        finally:
            rmtree(dstDirPath)

        # test publish from a directory from a zip file
        try:
            cdm.publishFromDir('testdir4',
                               join(dirname(__file__), 'test.zip', 'dir1'))
            dstDirPath = join(d.getRepositoryPath(), 'testdir4')
            dstFilePath = join(dstDirPath, 'subdir1', 'file1.txt')
            self.assertTrue(isfile(dstFilePath))
            dstFilePath = join(dstDirPath, 'subdir2', 'file2.txt')
            self.assertTrue(isfile(dstFilePath))
            # Test whether republishing the same directory checks the last modified date
            # The file created manually in the repository should not be deleted because
            # the zip archive was not modified from the last publish
            dstFilePath = join(dstDirPath, 'sometestfile.txt')
            with open(dstFilePath, 'w') as _f:
                pass
            cdm.publishFromDir('testdir4',
                               join(dirname(__file__), 'test.zip', 'dir1'))
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(dstDirPath)

        # test publish from a string
        try:
            path = join('testdir5', 'somecontent.txt')
            cdm.publishContent(path, BytesIO(b'test'))
            dstFilePath = join(d.getRepositoryPath(), path)
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(join(d.getRepositoryPath(), dirname(path)))

        # test publish from a file object
        try:
            path = join('testdir6', 'somecontent2.txt')
            cdm.publishFromFile(path, BytesIO(b'test 2'))
            dstFilePath = join(d.getRepositoryPath(), path)
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(join(d.getRepositoryPath(), dirname(path)))
コード例 #2
0
ファイル: service.py プロジェクト: Eduardoescamilla/Live-Blog
def contentDeliveryManager() -> ICDM:
    cdm = LocalFileSystemCDM();
    cdm.delivery = delivery()
    return cdm
コード例 #3
0
ファイル: service.py プロジェクト: patriciagarcia/Live-Blog
def contentDeliveryManager() -> ICDM:
    cdm = LocalFileSystemCDM()
    cdm.delivery = delivery()
    return cdm
コード例 #4
0
    def testLocalFilesystemCDM(self):
        d = HTTPDelivery()
        rootDir = TemporaryDirectory()
        d.serverURI = "http://localhost/content/"
        d.repositoryPath = rootDir.name
        #        d.repositoryPath = '/var/www/repository'
        #        ioc.Initializer.initialize(d)
        cdm = LocalFileSystemCDM()
        cdm.delivery = d

        # test publish from a file from the file system
        try:
            srcTmpFile = NamedTemporaryFile(delete=False)
            srcTmpFile.close()
            dstPath = "testdir1/tempfile.txt"
            cdm.publishFromFile(dstPath, srcTmpFile.name)
            dstFilePath = join(d.getRepositoryPath(), normOSPath(dstPath))
            self.assertTrue(isfile(dstFilePath))
            self.assertEqual(datetime.fromtimestamp(stat(dstFilePath).st_mtime), cdm.getTimestamp(dstPath))
        finally:
            rmtree(dirname(dstFilePath))
            remove(srcTmpFile.name)

        # test publish from a file from a zip archive
        try:
            inFileName = join("dir1", "subdir2", "file1.txt")
            dstPath = join("testdir2", "tempfile2.txt")
            cdm.publishFromFile(dstPath, join(dirname(__file__), "test.zip", inFileName))
            dstFilePath = join(d.getRepositoryPath(), normOSPath(dstPath))
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(dirname(dstFilePath))

        # test publish from a directory from the file system
        srcTmpDir = TemporaryDirectory()
        dirs = ("test1/subdir1", "test2/subdir1")
        for dir in dirs:
            fullPath = join(srcTmpDir.name, dir)
            makedirs(fullPath)
            with open(join(fullPath, "text.html"), "w") as _f:
                pass
        try:
            cdm.publishFromDir("testdir3", srcTmpDir.name)
            dstDirPath = join(d.getRepositoryPath(), "testdir3")
            for dir in dirs:
                dstFilePath = join(dstDirPath, dir, "text.html")
                self.assertTrue(isfile(dstFilePath))
                self.assertEqual(
                    datetime.fromtimestamp(stat(dstFilePath).st_mtime),
                    cdm.getTimestamp(join("testdir3", dir, "text.html")),
                )
            # test remove path
            filePath = "testdir3/test1/subdir1/text.html"
            self.assertTrue(isfile(join(d.getRepositoryPath(), filePath)))
            cdm.republish(filePath, filePath + ".new")
            self.assertTrue(isfile(join(d.getRepositoryPath(), filePath + ".new")))
            cdm.republish(filePath + ".new", filePath)
            cdm.remove(filePath)
            self.assertFalse(isfile(join(d.getRepositoryPath(), filePath)))
            dirPath = "testdir3/test2"
            self.assertTrue(isdir(join(d.getRepositoryPath(), dirPath)))
            cdm.remove(dirPath)
            self.assertFalse(isdir(join(d.getRepositoryPath(), dirPath)))
        finally:
            rmtree(dstDirPath)

        # test publish from a directory from a zip file
        try:
            cdm.publishFromDir("testdir4", join(dirname(__file__), "test.zip", "dir1"))
            dstDirPath = join(d.getRepositoryPath(), "testdir4")
            dstFilePath = join(dstDirPath, "subdir1", "file1.txt")
            self.assertTrue(isfile(dstFilePath))
            dstFilePath = join(dstDirPath, "subdir2", "file2.txt")
            self.assertTrue(isfile(dstFilePath))
            # Test whether republishing the same directory checks the last modified date
            # The file created manually in the repository should not be deleted because
            # the zip archive was not modified from the last publish
            dstFilePath = join(dstDirPath, "sometestfile.txt")
            with open(dstFilePath, "w") as _f:
                pass
            cdm.publishFromDir("testdir4", join(dirname(__file__), "test.zip", "dir1"))
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(dstDirPath)

        # test publish from a string
        try:
            path = join("testdir5", "somecontent.txt")
            cdm.publishContent(path, BytesIO(b"test"))
            dstFilePath = join(d.getRepositoryPath(), path)
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(join(d.getRepositoryPath(), dirname(path)))

        # test publish from a file object
        try:
            path = join("testdir6", "somecontent2.txt")
            cdm.publishFromFile(path, BytesIO(b"test 2"))
            dstFilePath = join(d.getRepositoryPath(), path)
            self.assertTrue(isfile(dstFilePath))
        finally:
            rmtree(join(d.getRepositoryPath(), dirname(path)))