From e5bae7e88540023caf2e67590a75c42ee0b4b7f8 Mon Sep 17 00:00:00 2001 From: Phill Ridout Date: Wed, 14 Jan 2015 21:35:02 +0000 Subject: [PATCH] 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 --- openlp/core/utils/__init__.py | 6 ++++-- tests/functional/openlp_core_utils/test_utils.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 257351758..6de358f65 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -34,6 +34,7 @@ from distutils.version import LooseVersion import logging import locale import os +import platform import re import time 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') else: 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 retries = 0 while True: try: remote_version = str(urllib.request.urlopen(req, None, timeout=CONNECTION_TIMEOUT).read().decode()).strip() - except ConnectionException: + except (urllib.error.URLError, ConnectionError): if retries > CONNECTION_RETRIES: log.exception('Failed to download the latest OpenLP version file') else: diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index e19bcb30e..39cf15c89 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -236,6 +236,19 @@ class TestUtils(TestCase): # THEN: the resolve method is called with the correct argument 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): """ Test that getting a user agent on Linux returns a user agent suitable for Linux