Merge lp:~thelinuxguy/openlp/fix-version-check into lp:openlp

Proposed by Simon Hanna
Status: Merged
Merged at revision: 2805
Proposed branch: lp:~thelinuxguy/openlp/fix-version-check
Merge into: lp:openlp
Diff against target: 110 lines (+34/-10)
3 files modified
.bzrignore (+1/-0)
openlp/core/version.py (+4/-6)
tests/functional/openlp_core/test_version.py (+29/-4)
To merge this branch: bzr merge lp:~thelinuxguy/openlp/fix-version-check
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+335602@code.launchpad.net

Description of the change

Fixed the version checking to be more robust

* Strip the response so empty responses that contain whitespace are in fact empty
* Change http to https to result in one less query
* Add test for responses containing white space
* Add .cache to bzrignore (generated by pytest when tests fail)

To post a comment you must log in.
2807. By Simon Hanna

Remove sleep statement

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Looks good to me.

review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2017-10-10 07:08:44 +0000
+++ .bzrignore 2017-12-29 13:59:25 +0000
@@ -45,3 +45,4 @@
45output45output
46htmlcov46htmlcov
47openlp-test-projectordb.sqlite47openlp-test-projectordb.sqlite
48.cache
4849
=== modified file 'openlp/core/version.py'
--- openlp/core/version.py 2017-11-18 11:23:15 +0000
+++ openlp/core/version.py 2017-12-29 13:59:25 +0000
@@ -75,13 +75,11 @@
75 * If a version number's minor version is an even number, it is a stable release.75 * If a version number's minor version is an even number, it is a stable release.
76 """76 """
77 log.debug('VersionWorker - Start')77 log.debug('VersionWorker - Start')
78 # I'm not entirely sure why this was here, I'm commenting it out until I hit the same scenario78 download_url = 'https://www.openlp.org/files/version.txt'
79 time.sleep(1)
80 download_url = 'http://www.openlp.org/files/version.txt'
81 if self.current_version['build']:79 if self.current_version['build']:
82 download_url = 'http://www.openlp.org/files/nightly_version.txt'80 download_url = 'https://www.openlp.org/files/nightly_version.txt'
83 elif int(self.current_version['version'].split('.')[1]) % 2 != 0:81 elif int(self.current_version['version'].split('.')[1]) % 2 != 0:
84 download_url = 'http://www.openlp.org/files/dev_version.txt'82 download_url = 'https://www.openlp.org/files/dev_version.txt'
85 headers = {83 headers = {
86 'User-Agent': 'OpenLP/{version} {system}/{release}; '.format(version=self.current_version['full'],84 'User-Agent': 'OpenLP/{version} {system}/{release}; '.format(version=self.current_version['full'],
87 system=platform.system(),85 system=platform.system(),
@@ -92,7 +90,7 @@
92 while retries < 3:90 while retries < 3:
93 try:91 try:
94 response = requests.get(download_url, headers=headers)92 response = requests.get(download_url, headers=headers)
95 remote_version = response.text93 remote_version = response.text.strip()
96 log.debug('New version found: %s', remote_version)94 log.debug('New version found: %s', remote_version)
97 break95 break
98 except OSError:96 except OSError:
9997
=== modified file 'tests/functional/openlp_core/test_version.py'
--- tests/functional/openlp_core/test_version.py 2017-09-13 06:08:38 +0000
+++ tests/functional/openlp_core/test_version.py 2017-12-29 13:59:25 +0000
@@ -63,7 +63,7 @@
63 worker.start()63 worker.start()
6464
65 # THEN: The check completes and the signal is emitted65 # THEN: The check completes and the signal is emitted
66 expected_download_url = 'http://www.openlp.org/files/version.txt'66 expected_download_url = 'https://www.openlp.org/files/version.txt'
67 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}67 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
68 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)68 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
69 mock_new_version.emit.assert_called_once_with('2.4.6')69 mock_new_version.emit.assert_called_once_with('2.4.6')
@@ -88,7 +88,7 @@
88 worker.start()88 worker.start()
8989
90 # THEN: The check completes and the signal is emitted90 # THEN: The check completes and the signal is emitted
91 expected_download_url = 'http://www.openlp.org/files/dev_version.txt'91 expected_download_url = 'https://www.openlp.org/files/dev_version.txt'
92 expected_headers = {'User-Agent': 'OpenLP/2.1.3 Linux/4.12.0-1-amd64; '}92 expected_headers = {'User-Agent': 'OpenLP/2.1.3 Linux/4.12.0-1-amd64; '}
93 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)93 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
94 mock_new_version.emit.assert_called_once_with('2.4.6')94 mock_new_version.emit.assert_called_once_with('2.4.6')
@@ -113,7 +113,7 @@
113 worker.start()113 worker.start()
114114
115 # THEN: The check completes and the signal is emitted115 # THEN: The check completes and the signal is emitted
116 expected_download_url = 'http://www.openlp.org/files/nightly_version.txt'116 expected_download_url = 'https://www.openlp.org/files/nightly_version.txt'
117 expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}117 expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
118 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)118 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
119 mock_new_version.emit.assert_called_once_with('2.4.6')119 mock_new_version.emit.assert_called_once_with('2.4.6')
@@ -122,6 +122,31 @@
122122
123@patch('openlp.core.version.platform')123@patch('openlp.core.version.platform')
124@patch('openlp.core.version.requests')124@patch('openlp.core.version.requests')
125def test_worker_empty_response(mock_requests, mock_platform):
126 """Test the VersionWorkder.start() method for empty responses"""
127 # GIVEN: A last check date, current version, and an instance of worker
128 last_check_date = '1970-01-01'
129 current_version = {'full': '2.1-bzr2345', 'version': '2.1', 'build': '2345'}
130 mock_platform.system.return_value = 'Linux'
131 mock_platform.release.return_value = '4.12.0-1-amd64'
132 mock_requests.get.return_value = MagicMock(text='\n')
133 worker = VersionWorker(last_check_date, current_version)
134
135 # WHEN: The worker is run
136 with patch.object(worker, 'new_version') as mock_new_version, \
137 patch.object(worker, 'quit') as mock_quit:
138 worker.start()
139
140 # THEN: The check completes and the signal is emitted
141 expected_download_url = 'https://www.openlp.org/files/nightly_version.txt'
142 expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
143 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
144 assert mock_new_version.emit.call_count == 0
145 mock_quit.emit.assert_called_once_with()
146
147
148@patch('openlp.core.version.platform')
149@patch('openlp.core.version.requests')
125def test_worker_start_connection_error(mock_requests, mock_platform):150def test_worker_start_connection_error(mock_requests, mock_platform):
126 """Test the VersionWorkder.start() method when a ConnectionError happens"""151 """Test the VersionWorkder.start() method when a ConnectionError happens"""
127 # GIVEN: A last check date, current version, and an instance of worker152 # GIVEN: A last check date, current version, and an instance of worker
@@ -138,7 +163,7 @@
138 worker.start()163 worker.start()
139164
140 # THEN: The check completes and the signal is emitted165 # THEN: The check completes and the signal is emitted
141 expected_download_url = 'http://www.openlp.org/files/version.txt'166 expected_download_url = 'https://www.openlp.org/files/version.txt'
142 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}167 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
143 mock_requests.get.assert_called_with(expected_download_url, headers=expected_headers)168 mock_requests.get.assert_called_with(expected_download_url, headers=expected_headers)
144 assert mock_requests.get.call_count == 3169 assert mock_requests.get.call_count == 3