43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
|
import unittest
|
||
|
from urllib.error import HTTPError, URLError
|
||
|
from test_update_regex import TestUpdateRegex
|
||
|
from webpicdownloader.util.UpdateUtils import fetch_version, is_new_version_available
|
||
|
|
||
|
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.
|
||
|
* bad_version -> use a permalink VERSION file for wich version format is bad.
|
||
|
"""
|
||
|
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'
|
||
|
bad_version = 'https://git.endmove.eu/EndMove/WebPicDownloader/src/commit/6b26b89c6901841faaa09154c185d202223492c2/app_version_file.txt'
|
||
|
|
||
|
def test_fetch_version__good_url(self):
|
||
|
self.assertTrue(fetch_version(self.good_url) == '1.0.0')
|
||
|
|
||
|
def test_fetch_version__bad_url(self):
|
||
|
self.assertRaises(HTTPError, lambda: fetch_version(self.bad_url))
|
||
|
self.assertRaises(URLError, lambda: fetch_version('https://bad'))
|
||
|
self.assertRaises(ValueError, lambda: fetch_version('bad'))
|
||
|
|
||
|
def test_is_new_version_available__new_version_available(self):
|
||
|
self.assertTrue(is_new_version_available('0.0.0', self.good_url, self.regex))
|
||
|
self.assertTrue(is_new_version_available('0.48.0', self.good_url, self.regex))
|
||
|
self.assertTrue(is_new_version_available('0.48.14', self.good_url, self.regex))
|
||
|
self.assertTrue(is_new_version_available('5.48.14', self.good_url, self.regex))
|
||
|
|
||
|
def test_is_new_version_available__no_new_version_available(self):
|
||
|
self.assertFalse(is_new_version_available('1.0.0', self.good_url, self.regex))
|
||
|
|
||
|
def test_is_new_version_available__bad_version(self):
|
||
|
self.assertRaises(ValueError, lambda: is_new_version_available('1.0.0', self.bad_version, self.regex))
|
||
|
|
||
|
def test_is_new_version_available__bad_url(self):
|
||
|
self.assertRaises(HTTPError, lambda: is_new_version_available('1.0.0', self.bad_url, self.regex))
|