This repository has been archived on 2023-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
WebPicDownloader/tests/test_update_utils.py

75 lines
2.8 KiB
Python
Raw Permalink Normal View History

import unittest
from urllib.error import HTTPError, URLError
from test_update_regex import TestUpdateRegex
from webpicdownloader.util.UpdateUtils import fetch_version, check_for_update
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'
def test_fetch_version__good_url(self):
"""
We test the recovery of the available version with a URL
indicating a correct version file.
"""
self.assertTrue(fetch_version(self.good_url) == '1.0.0')
def test_fetch_version__bad_url(self):
"""
We test the recovery of the version with erroneous URLs,
or not leading to any specific file
"""
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_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
))
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))