2022-09-11 13:38:36 +02:00
|
|
|
import unittest
|
|
|
|
from urllib.error import HTTPError, URLError
|
|
|
|
from test_update_regex import TestUpdateRegex
|
2022-09-12 00:29:39 +02:00
|
|
|
from webpicdownloader.util.UpdateUtils import fetch_version, check_for_update
|
2022-09-11 13:38:36 +02:00
|
|
|
|
|
|
|
class TestUpdateUtils(unittest.TestCase):
|
|
|
|
"""
|
|
|
|
Test Class for Update Utils
|
|
|
|
<!> can not be executed directly <!>
|
|
|
|
|
|
|
|
* regex -> use UpdateRegex unittest regex.
|
|
|
|
* good_url -> use a permalink VERSION file.
|
|
|
|
* bad_url -> bad link that point a 404 error.
|
|
|
|
"""
|
|
|
|
regex = TestUpdateRegex.regex
|
|
|
|
good_url = 'https://git.endmove.eu/EndMove/WebPicDownloader/raw/commit/6b26b89c6901841faaa09154c185d202223492c2/VERSION'
|
|
|
|
bad_url = 'https://git.endmove.eu/EndMove/WebPicDownloader/raw/commit/bad-commit/VERSION'
|
2022-09-12 00:29:39 +02:00
|
|
|
|
|
|
|
|
2022-09-11 13:38:36 +02:00
|
|
|
def test_fetch_version__good_url(self):
|
2022-09-12 00:29:39 +02:00
|
|
|
"""
|
|
|
|
We test the recovery of the available version with a URL
|
|
|
|
indicating a correct version file.
|
|
|
|
"""
|
2022-09-11 13:38:36 +02:00
|
|
|
self.assertTrue(fetch_version(self.good_url) == '1.0.0')
|
2022-09-12 00:29:39 +02:00
|
|
|
|
|
|
|
|
2022-09-11 13:38:36 +02:00
|
|
|
def test_fetch_version__bad_url(self):
|
2022-09-12 00:29:39 +02:00
|
|
|
"""
|
|
|
|
We test the recovery of the version with erroneous URLs,
|
|
|
|
or not leading to any specific file
|
|
|
|
"""
|
2022-09-11 13:38:36 +02:00
|
|
|
self.assertRaises(HTTPError, lambda: fetch_version(self.bad_url))
|
|
|
|
self.assertRaises(URLError, lambda: fetch_version('https://bad'))
|
|
|
|
self.assertRaises(ValueError, lambda: fetch_version('bad'))
|
|
|
|
|
|
|
|
|
2022-09-12 00:29:39 +02:00
|
|
|
def test_check_for_update__new_version(self):
|
|
|
|
"""
|
|
|
|
We check the availability of an update with softwares whose
|
|
|
|
versions are different from the one indicated by the repository
|
|
|
|
(thus available update).
|
|
|
|
"""
|
|
|
|
self.assertTrue(check_for_update('0.0.0', self.good_url, self.regex))
|
|
|
|
self.assertTrue(check_for_update('0.48.0', self.good_url, self.regex))
|
|
|
|
self.assertTrue(check_for_update('0.48.14', self.good_url, self.regex))
|
|
|
|
self.assertTrue(check_for_update('5.48.14', self.good_url, self.regex))
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_for_update__no_new_version(self):
|
|
|
|
"""
|
|
|
|
We check the availability of an update with software that has the
|
|
|
|
same version as the one on the repository (so no update available).
|
|
|
|
"""
|
|
|
|
self.assertFalse(check_for_update('1.0.0', self.good_url, self.regex))
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_for_update__bad_version(self):
|
|
|
|
"""
|
|
|
|
We check for the availability of an update with an incorrect version
|
|
|
|
in the repository.
|
|
|
|
"""
|
|
|
|
self.assertRaises(ValueError, lambda: check_for_update(
|
|
|
|
'1.0.0',
|
|
|
|
'https://git.endmove.eu/EndMove/WebPicDownloader/src/commit/6b26b89c6901841faaa09154c185d202223492c2/app_version_file.txt',
|
|
|
|
self.regex
|
|
|
|
))
|
|
|
|
|
2022-09-11 13:38:36 +02:00
|
|
|
|
2022-09-12 00:29:39 +02:00
|
|
|
def test_check_for_update__bad_url(self):
|
|
|
|
"""
|
|
|
|
We check the availability of an update with a bad repository url
|
|
|
|
"""
|
|
|
|
self.assertRaises(HTTPError, lambda: check_for_update('1.0.0', self.bad_url, self.regex))
|