projects
/
osm
/
SO.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix unittests
[osm/SO.git]
/
common
/
python
/
test
/
utest_url_downloader.py
diff --git
a/common/python/test/utest_url_downloader.py
b/common/python/test/utest_url_downloader.py
index
33e24a8
..
379f3c9
100755
(executable)
--- a/
common/python/test/utest_url_downloader.py
+++ b/
common/python/test/utest_url_downloader.py
@@
-29,10
+29,14
@@
import rift.downloader as downloader
TEST_URL = "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell"
TEST_URL = "https://raw.githubusercontent.com/RIFTIO/RIFT.ware/master/rift-shell"
-class TestCase(unittest.TestCase):
+class
Url
TestCase(unittest.TestCase):
def setUp(self):
pass
def setUp(self):
pass
+ @classmethod
+ def set_logger(cls, log):
+ cls.log = log
+
def _common_checks(self, job):
if job.status != "COMPLETED":
return
def _common_checks(self, job):
if job.status != "COMPLETED":
return
@@
-42,6
+46,9
@@
class TestCase(unittest.TestCase):
assert job.start_time > 0
assert job.stop_time >= job.start_time
assert job.start_time > 0
assert job.stop_time >= job.start_time
+ def _display_result(self, url_downl):
+ UrlTestCase.log.debug("URL download result: {}".format(url_downl))
+
def test_file_download(self):
"""
Asserts:
def test_file_download(self):
"""
Asserts:
@@
-50,9
+57,9
@@
class TestCase(unittest.TestCase):
"""
url_downl = downloader.UrlDownloader(TEST_URL)
url_downl.download()
"""
url_downl = downloader.UrlDownloader(TEST_URL)
url_downl.download()
- assert os.path.isfile(url_downl.filename)
-
+ assert os.path.isfile(url_downl.filepath)
+ self._display_result(url_downl)
assert url_downl.meta.status == downloader.DownloadStatus.COMPLETED
# assert url_downl.job.progress_percent == 100
assert "success" in url_downl.meta.detail
assert url_downl.meta.status == downloader.DownloadStatus.COMPLETED
# assert url_downl.job.progress_percent == 100
assert "success" in url_downl.meta.detail
@@
-67,7
+74,8
@@
class TestCase(unittest.TestCase):
url_downl = downloader.UrlDownloader(TEST_URL + ".blah")
url_downl.download()
url_downl = downloader.UrlDownloader(TEST_URL + ".blah")
url_downl.download()
- assert not os.path.isfile(url_downl.filename)
+ self._display_result(url_downl)
+ assert not os.path.isfile(url_downl.filepath)
assert url_downl.meta.status == downloader.DownloadStatus.FAILED
assert "Max retries" in url_downl.meta.detail or "404" in url_downl.meta.detail
assert url_downl.meta.status == downloader.DownloadStatus.FAILED
assert "Max retries" in url_downl.meta.detail or "404" in url_downl.meta.detail
@@
-79,7
+87,7
@@
class TestCase(unittest.TestCase):
1. Cancel for a download and clean up of the downloaded file.
2. Model attributes (Process percent, detail, status)
"""
1. Cancel for a download and clean up of the downloaded file.
2. Model attributes (Process percent, detail, status)
"""
- url = "http://speedtest.ftp.otenet.gr/files/test1Mb.db"
+ url = "http://speedtest.ftp.otenet.gr/files/test1
0
Mb.db"
url_dwld = downloader.UrlDownloader(url)
loop = asyncio.get_event_loop()
fut = loop.run_in_executor(None, url_dwld.download)
url_dwld = downloader.UrlDownloader(url)
loop = asyncio.get_event_loop()
fut = loop.run_in_executor(None, url_dwld.download)
@@
-96,6
+104,7
@@
class TestCase(unittest.TestCase):
loop.run_until_complete(sleep())
loop.run_until_complete(sleep())
+ self._display_result(url_dwld)
assert url_dwld.meta.status == downloader.DownloadStatus.CANCELLED
assert url_dwld.meta.bytes_downloaded == url_dwld.meta.bytes_downloaded
assert "cancel" in url_dwld.meta.detail
assert url_dwld.meta.status == downloader.DownloadStatus.CANCELLED
assert url_dwld.meta.bytes_downloaded == url_dwld.meta.bytes_downloaded
assert "cancel" in url_dwld.meta.detail
@@
-106,6
+115,7
@@
class TestCase(unittest.TestCase):
'https://api.github.com/user')
url_downl.download()
'https://api.github.com/user')
url_downl.download()
+ self._display_result(url_downl)
def tearDown(self):
def tearDown(self):
@@
-125,7
+135,9
@@
def main(argv=sys.argv[1:]):
runner = None
# Set the global logging level
runner = None
# Set the global logging level
- logging.getLogger().setLevel(logging.DEBUG if args.verbose else logging.ERROR)
+ log = logging.getLogger()
+ log.setLevel(logging.DEBUG if args.verbose else logging.ERROR)
+ UrlTestCase.set_logger(log)
# The unittest framework requires a program name, so use the name of this
# file instead (we do not want to have to pass a fake program name to main
# The unittest framework requires a program name, so use the name of this
# file instead (we do not want to have to pass a fake program name to main