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
1=== modified file '.bzrignore'
2--- .bzrignore 2017-10-10 07:08:44 +0000
3+++ .bzrignore 2017-12-29 13:59:25 +0000
4@@ -45,3 +45,4 @@
5 output
6 htmlcov
7 openlp-test-projectordb.sqlite
8+.cache
9
10=== modified file 'openlp/core/version.py'
11--- openlp/core/version.py 2017-11-18 11:23:15 +0000
12+++ openlp/core/version.py 2017-12-29 13:59:25 +0000
13@@ -75,13 +75,11 @@
14 * If a version number's minor version is an even number, it is a stable release.
15 """
16 log.debug('VersionWorker - Start')
17- # I'm not entirely sure why this was here, I'm commenting it out until I hit the same scenario
18- time.sleep(1)
19- download_url = 'http://www.openlp.org/files/version.txt'
20+ download_url = 'https://www.openlp.org/files/version.txt'
21 if self.current_version['build']:
22- download_url = 'http://www.openlp.org/files/nightly_version.txt'
23+ download_url = 'https://www.openlp.org/files/nightly_version.txt'
24 elif int(self.current_version['version'].split('.')[1]) % 2 != 0:
25- download_url = 'http://www.openlp.org/files/dev_version.txt'
26+ download_url = 'https://www.openlp.org/files/dev_version.txt'
27 headers = {
28 'User-Agent': 'OpenLP/{version} {system}/{release}; '.format(version=self.current_version['full'],
29 system=platform.system(),
30@@ -92,7 +90,7 @@
31 while retries < 3:
32 try:
33 response = requests.get(download_url, headers=headers)
34- remote_version = response.text
35+ remote_version = response.text.strip()
36 log.debug('New version found: %s', remote_version)
37 break
38 except OSError:
39
40=== modified file 'tests/functional/openlp_core/test_version.py'
41--- tests/functional/openlp_core/test_version.py 2017-09-13 06:08:38 +0000
42+++ tests/functional/openlp_core/test_version.py 2017-12-29 13:59:25 +0000
43@@ -63,7 +63,7 @@
44 worker.start()
45
46 # THEN: The check completes and the signal is emitted
47- expected_download_url = 'http://www.openlp.org/files/version.txt'
48+ expected_download_url = 'https://www.openlp.org/files/version.txt'
49 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
50 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
51 mock_new_version.emit.assert_called_once_with('2.4.6')
52@@ -88,7 +88,7 @@
53 worker.start()
54
55 # THEN: The check completes and the signal is emitted
56- expected_download_url = 'http://www.openlp.org/files/dev_version.txt'
57+ expected_download_url = 'https://www.openlp.org/files/dev_version.txt'
58 expected_headers = {'User-Agent': 'OpenLP/2.1.3 Linux/4.12.0-1-amd64; '}
59 mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
60 mock_new_version.emit.assert_called_once_with('2.4.6')
61@@ -113,7 +113,7 @@
62 worker.start()
63
64 # THEN: The check completes and the signal is emitted
65- expected_download_url = 'http://www.openlp.org/files/nightly_version.txt'
66+ expected_download_url = 'https://www.openlp.org/files/nightly_version.txt'
67 expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
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')
70@@ -122,6 +122,31 @@
71
72 @patch('openlp.core.version.platform')
73 @patch('openlp.core.version.requests')
74+def test_worker_empty_response(mock_requests, mock_platform):
75+ """Test the VersionWorkder.start() method for empty responses"""
76+ # GIVEN: A last check date, current version, and an instance of worker
77+ last_check_date = '1970-01-01'
78+ current_version = {'full': '2.1-bzr2345', 'version': '2.1', 'build': '2345'}
79+ mock_platform.system.return_value = 'Linux'
80+ mock_platform.release.return_value = '4.12.0-1-amd64'
81+ mock_requests.get.return_value = MagicMock(text='\n')
82+ worker = VersionWorker(last_check_date, current_version)
83+
84+ # WHEN: The worker is run
85+ with patch.object(worker, 'new_version') as mock_new_version, \
86+ patch.object(worker, 'quit') as mock_quit:
87+ worker.start()
88+
89+ # THEN: The check completes and the signal is emitted
90+ expected_download_url = 'https://www.openlp.org/files/nightly_version.txt'
91+ expected_headers = {'User-Agent': 'OpenLP/2.1-bzr2345 Linux/4.12.0-1-amd64; '}
92+ mock_requests.get.assert_called_once_with(expected_download_url, headers=expected_headers)
93+ assert mock_new_version.emit.call_count == 0
94+ mock_quit.emit.assert_called_once_with()
95+
96+
97+@patch('openlp.core.version.platform')
98+@patch('openlp.core.version.requests')
99 def test_worker_start_connection_error(mock_requests, mock_platform):
100 """Test the VersionWorkder.start() method when a ConnectionError happens"""
101 # GIVEN: A last check date, current version, and an instance of worker
102@@ -138,7 +163,7 @@
103 worker.start()
104
105 # THEN: The check completes and the signal is emitted
106- expected_download_url = 'http://www.openlp.org/files/version.txt'
107+ expected_download_url = 'https://www.openlp.org/files/version.txt'
108 expected_headers = {'User-Agent': 'OpenLP/2.0 Linux/4.12.0-1-amd64; '}
109 mock_requests.get.assert_called_with(expected_download_url, headers=expected_headers)
110 assert mock_requests.get.call_count == 3