Add some tests for the update check
This commit is contained in:
parent
f5253c7f45
commit
adb3db3d22
2 changed files with 35 additions and 8 deletions
|
@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function
|
|||
|
||||
import os
|
||||
|
||||
from distutils.version import StrictVersion
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
import dosagelib
|
||||
from dosagelib import configuration
|
||||
|
@ -41,18 +41,20 @@ def check_update():
|
|||
def get_online_version():
|
||||
"""Download update info and parse it."""
|
||||
page = http.default_session.get(UPDATE_URL).json()
|
||||
version, url = None, None
|
||||
version = page['tag_name']
|
||||
version = page.get('tag_name', None)
|
||||
|
||||
if os.name == 'nt':
|
||||
try:
|
||||
url = next((x['browser_download_url'] for x in page['assets'] if
|
||||
x['content_type'] == 'application/x-msdos-program'),
|
||||
configuration.Url)
|
||||
except KeyError:
|
||||
url = None
|
||||
else:
|
||||
url = page['tarball_url']
|
||||
url = page.get('tarball_url', None)
|
||||
return version, url
|
||||
|
||||
|
||||
def is_newer_version(version):
|
||||
"""Check if given version is newer than current version."""
|
||||
return StrictVersion(version) > StrictVersion(dosagelib.__version__)
|
||||
return LooseVersion(version) > LooseVersion(dosagelib.__version__)
|
||||
|
|
|
@ -39,9 +39,34 @@ class TestDosage(object):
|
|||
for option in ("-l", "--list", "--singlelist"):
|
||||
cmd_ok(option)
|
||||
|
||||
@responses.activate
|
||||
def test_display_version(self):
|
||||
cmd_ok("--version")
|
||||
|
||||
@responses.activate
|
||||
def test_update_available(self, capsys):
|
||||
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
|
||||
json={'tag_name': '9999.0', 'tarball_url': 'NOWHERE'})
|
||||
cmd_ok('--version', '-v')
|
||||
captured = capsys.readouterr()
|
||||
assert 'A new version' in captured.out
|
||||
|
||||
@responses.activate
|
||||
def test_no_update_available(self, capsys):
|
||||
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
|
||||
json={'tag_name': '1.0', 'tarball_url': 'NOWHERE'})
|
||||
cmd_ok('--version', '-v')
|
||||
captured = capsys.readouterr()
|
||||
assert 'Detected local or development' in captured.out
|
||||
|
||||
@responses.activate
|
||||
def test_update_broken(self, capsys):
|
||||
responses.add(responses.GET, re.compile(r'https://api\.github\.com/'),
|
||||
json={})
|
||||
cmd_ok('--version', '-v')
|
||||
captured = capsys.readouterr()
|
||||
assert 'invalid update file' in captured.out
|
||||
|
||||
def test_display_help(self):
|
||||
for option in ("-h", "--help"):
|
||||
with pytest.raises(SystemExit):
|
||||
|
|
Loading…
Reference in a new issue