def test_download(self): url = 'http://www.vistrails.org/testing/httpdirectory/test/' import shutil import tempfile testdir = tempfile.mkdtemp(prefix='vt_test_http_') try: download_directory(url, testdir) files = {} def addfiles(dirpath): td = os.path.join(testdir, dirpath) for name in os.listdir(td): filename = os.path.join(testdir, dirpath, name) dn = os.path.join(dirpath, name) if os.path.isdir(filename): addfiles(os.path.join(dirpath, name)) else: with open(filename, 'rb') as f: files[dn.replace(os.sep, '/')] = f.read() addfiles('') self.assertEqual(len(files), 4) del files['f.html'] self.assertEqual(files, { 'a': 'aa\n', 'bb': 'bb\n', 'cc/d': 'dd\n', }) finally: shutil.rmtree(testdir)
def test_download(self): url = 'http://a.remram.fr/test/' import os import shutil import tempfile testdir = tempfile.mkdtemp() try: download_directory(url, testdir) files = {} def addfiles(dirpath): td = os.path.join(testdir, dirpath) for name in os.listdir(td): filename = os.path.join(testdir, dirpath, name) dn = os.path.join(dirpath, name) if os.path.isdir(filename): addfiles(os.path.join(dirpath, name)) else: with open(filename, 'rb') as f: files[dn.replace(os.sep, '/')] = f.read() addfiles('') self.assertEqual(len(files), 4) del files['f.html'] self.assertEqual(files, { 'a': 'aa\n', 'bb': 'bb\n', 'cc/d': 'dd\n', }) finally: shutil.rmtree(testdir)
def download(self, url): local_path = self.interpreter.filePool.create_directory( prefix='vt_http').name download_directory(url, local_path) return local_path