Skip to content

Instantly share code, notes, and snippets.

@apahim
Created February 29, 2016 15:18
Show Gist options
  • Save apahim/b4486b10bcd726f3697e to your computer and use it in GitHub Desktop.
Save apahim/b4486b10bcd726f3697e to your computer and use it in GitHub Desktop.
diff --git a/avocado/core/test.py b/avocado/core/test.py
index 0a37f75..76ffb8c 100644
--- a/avocado/core/test.py
+++ b/avocado/core/test.py
@@ -207,8 +207,6 @@ class Test(unittest.TestCase):
"""
cache_dirs = settings.get_value('datadir.paths', 'cache_dirs',
key_type=list, default=[])
- if isinstance(cache_dirs, str):
- cache_dirs = [cache_dirs]
cache_dirs.append(utils_path.init_dir(self.workdir, 'cache'))
return cache_dirs
@@ -607,7 +605,7 @@ class Test(unittest.TestCase):
:returns: asset file local path
"""
return asset.Asset(name, asset_hash, algorithm, locations,
- self.cachedirs).path
+ self.cachedirs).fetch()
class SimpleTest(Test):
diff --git a/avocado/utils/asset.py b/avocado/utils/asset.py
index 5207b94..ec615ea 100644
--- a/avocado/utils/asset.py
+++ b/avocado/utils/asset.py
@@ -41,8 +41,9 @@ class Asset(object):
:param name: the asset filename. url is also supported
:param asset_hash: asset hash
- :param algorithm: hash algorithm (default sha1)
+ :param algorithm: hash algorithm
:param locations: list of locations fetch asset from
+ :params cache_dirs: list of cache directories
"""
self.name = name
self.asset_hash = asset_hash
@@ -51,7 +52,6 @@ class Asset(object):
self.cache_dirs = cache_dirs
self.nameobj = urlparse.urlparse(self.name)
self.basename = os.path.basename(self.nameobj.path)
- self.path = self.fetch()
def fetch(self):
urls = []
@@ -88,7 +88,7 @@ class Asset(object):
for url in urls:
urlobj = urlparse.urlparse(url)
- if urlobj.scheme == 'http':
+ if urlobj.scheme == 'http' or urlobj.scheme == 'https':
log.debug('Downloading from %s.' % url)
try:
url_download(url, self.asset_file)
diff --git a/selftests/unit/test_utils_asset.py b/selftests/unit/test_utils_asset.py
index 0278533..6dea1d3 100644
--- a/selftests/unit/test_utils_asset.py
+++ b/selftests/unit/test_utils_asset.py
@@ -24,7 +24,7 @@ class TestAsset(unittest.TestCase):
asset_hash=self.assethash,
algorithm='sha1',
locations=None,
- cache_dirs=[self.cache_dir]).path
+ cache_dirs=[self.cache_dir]).fetch()
expected_tarball = os.path.join(self.cache_dir, self.assetname)
self.assertEqual(foo_tarball, expected_tarball)
hashfile = '.'.join([expected_tarball, 'sha1'])
@@ -39,7 +39,7 @@ class TestAsset(unittest.TestCase):
asset_hash=self.assethash,
algorithm='sha1',
locations=[self.url],
- cache_dirs=[self.cache_dir]).path
+ cache_dirs=[self.cache_dir]).fetch()
expected_tarball = os.path.join(self.cache_dir, self.assetname)
self.assertEqual(foo_tarball, expected_tarball)
hashfile = '.'.join([expected_tarball, 'sha1'])
@@ -50,9 +50,9 @@ class TestAsset(unittest.TestCase):
self.assertEqual(content, expected_content)
def testException(self):
- self.assertRaises(EnvironmentError, asset.Asset, name='bar.tgz',
- asset_hash=None, algorithm=None, locations=None,
- cache_dirs=[self.cache_dir])
+ a = asset.Asset(name='bar.tgz', asset_hash=None, algorithm=None,
+ locations=None, cache_dirs=[self.cache_dir])
+ self.assertRaises(EnvironmentError, a.fetch)
def tearDown(self):
shutil.rmtree(self.basedir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment