Fixes1410694 by fixing typo, also added additional error. Added the OS Name and version to the version file request headers

Fixes: https://launchpad.net/bugs/1410694
This commit is contained in:
Phill Ridout 2015-01-14 21:35:02 +00:00
parent 38db55a37c
commit e5bae7e885
2 changed files with 17 additions and 2 deletions

View File

@ -34,6 +34,7 @@ from distutils.version import LooseVersion
import logging import logging
import locale import locale
import os import os
import platform
import re import re
import time import time
from shutil import which from shutil import which
@ -251,14 +252,15 @@ def check_latest_version(current_version):
req = urllib.request.Request('http://www.openlp.org/files/dev_version.txt') req = urllib.request.Request('http://www.openlp.org/files/dev_version.txt')
else: else:
req = urllib.request.Request('http://www.openlp.org/files/version.txt') req = urllib.request.Request('http://www.openlp.org/files/version.txt')
req.add_header('User-Agent', 'OpenLP/%s' % current_version['full']) req.add_header('User-Agent', 'OpenLP/%s %s/%s; ' % (current_version['full'], platform.system(),
platform.release()))
remote_version = None remote_version = None
retries = 0 retries = 0
while True: while True:
try: try:
remote_version = str(urllib.request.urlopen(req, None, remote_version = str(urllib.request.urlopen(req, None,
timeout=CONNECTION_TIMEOUT).read().decode()).strip() timeout=CONNECTION_TIMEOUT).read().decode()).strip()
except ConnectionException: except (urllib.error.URLError, ConnectionError):
if retries > CONNECTION_RETRIES: if retries > CONNECTION_RETRIES:
log.exception('Failed to download the latest OpenLP version file') log.exception('Failed to download the latest OpenLP version file')
else: else:

View File

@ -236,6 +236,19 @@ class TestUtils(TestCase):
# THEN: the resolve method is called with the correct argument # THEN: the resolve method is called with the correct argument
mock_resolver.resolve.assert_called_with('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') mock_resolver.resolve.assert_called_with('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext')
def get_uno_instance_socket_test(self):
"""
Test that when the UNO connection type is other than "pipe" the resolver is given the "socket" URI
"""
# GIVEN: A mock resolver object and UNO_CONNECTION_TYPE is "socket"
mock_resolver = MagicMock()
# WHEN: get_uno_instance() is called
get_uno_instance(mock_resolver, 'socket')
# THEN: the resolve method is called with the correct argument
mock_resolver.resolve.assert_called_with('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
def get_user_agent_linux_test(self): def get_user_agent_linux_test(self):
""" """
Test that getting a user agent on Linux returns a user agent suitable for Linux Test that getting a user agent on Linux returns a user agent suitable for Linux