From 2f8b12934b8bcd90271cfe92c39104fa92257873 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 17 May 2016 22:28:27 +0100 Subject: [PATCH 1/4] fix theme display in servicemanager --- openlp/core/ui/servicemanager.py | 4 ++-- openlp/plugins/remotes/lib/httprouter.py | 16 +++++++++------- openlp/plugins/remotes/lib/httpserver.py | 1 - scripts/check_dependencies.py | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index a59f94377..0e464f287 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1324,8 +1324,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa The theme may have changed in the settings dialog so make sure the theme combo box is in the correct state. """ visible = not self.renderer.theme_level == ThemeLevel.Global - self.theme_label.setVisible(visible) - self.theme_combo_box.setVisible(visible) + self.toolbar.actions['theme_combo_box'].setVisible(visible) + self.toolbar.actions['theme_label'].setVisible(visible) def regenerate_service_items(self, changed=False): """ diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index d5e8cda1c..5d14a5637 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -221,9 +221,13 @@ class HttpRouter(RegistryProperties): self.request_data = None url_path_split = urlparse(url_path) url_query = parse_qs(url_path_split.query) - # GET - if 'data' in url_query.keys(): - self.request_data = url_query['data'][0] + # Get data from HTTP request + if self.command == 'GET': + if 'data' in url_query.keys(): + self.request_data = url_query['data'][0] + elif self.command == 'POST': + content_len = int(self.headers['content-length']) + self.request_data = self.rfile.read(content_len).decode("utf-8") for route, func in self.routes: match = re.match(route, url_path_split.path) if match: @@ -401,10 +405,8 @@ class HttpRouter(RegistryProperties): log.debug('serve file request %s' % file_name) if not file_name: file_name = 'index.html' - elif file_name == 'stage': - file_name = 'stage.html' - elif file_name == 'main': - file_name = 'main.html' + if '.' not in file_name: + file_name += '.html' if file_name.startswith('/'): file_name = file_name[1:] path = os.path.normpath(os.path.join(self.html_dir, file_name)) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 26f00c359..88d1097dc 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -167,7 +167,6 @@ class HTTPSServer(HTTPServer): local_data = AppLocation.get_directory(AppLocation.DataDir) self.socket = ssl.SSLSocket( sock=socket.socket(self.address_family, self.socket_type), - ssl_version=ssl.PROTOCOL_TLSv1_2, certfile=os.path.join(local_data, 'remotes', 'openlp.crt'), keyfile=os.path.join(local_data, 'remotes', 'openlp.key'), server_side=True) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index e6f7d2c37..fb0d024ae 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -93,6 +93,7 @@ MODULES = [ 'bs4', 'mako', 'uno', + 'six' ] From 7c1e922f10961720111f40a65c3ea83c32994908 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 18 May 2016 18:06:25 +0100 Subject: [PATCH 2/4] pep8 --- openlp/core/ui/servicemanager.py | 1 - tests/functional/openlp_core_lib/test_lib.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 5b75aad63..35ec1bb9e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1328,7 +1328,6 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ServiceMa self.toolbar.actions['theme_label'].setVisible(visible) self.regenerate_service_items() - def regenerate_service_items(self, changed=False): """ Rebuild the service list as things have changed and a repaint is the easiest way to do this. diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index c8493d005..d519837bf 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -431,7 +431,6 @@ class TestLib(TestCase): thumb_size = QtCore.QSize(-1, 100) expected_size_1 = QtCore.QSize(88, 88) expected_size_2 = QtCore.QSize(100, 100) - # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the # last test. @@ -458,7 +457,7 @@ class TestLib(TestCase): with patch('openlp.core.lib.QtGui.QImageReader.size') as mocked_size: mocked_size.return_value = QtCore.QSize(0, 0) icon = create_thumb(image_path, thumb_path, size=thumb_size) - + # THEN: Check if the thumb was created with aspect ratio of 1. self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon') self.assertFalse(icon.isNull(), 'The icon should not be null') From fd33d9a0c5ed31c4861b663fd5ad91370aab831c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 18 May 2016 18:16:40 +0100 Subject: [PATCH 3/4] fixes --- .../openlp_plugins/remotes/test_router.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 28af5f2c1..d1715ab8d 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -94,6 +94,7 @@ class TestRouter(TestCase, TestMixin): (r'^/stage/api/poll$', {'function': mocked_function, 'secure': False}), ] self.router.routes = test_route + self.router.command = 'GET' # WHEN: called with a poll route function, args = self.router.process_http_request('/stage/api/poll', None) @@ -121,6 +122,7 @@ class TestRouter(TestCase, TestMixin): self.router.send_header = MagicMock() self.router.end_headers = MagicMock() self.router.wfile = MagicMock() + self.router.command = 'GET' # WHEN: called with a poll route self.router.do_post_processor() @@ -211,6 +213,29 @@ class TestRouter(TestCase, TestMixin): self.router.send_header.assert_called_once_with('Content-type', 'text/html') self.assertEqual(self.router.end_headers.call_count, 1, 'end_headers called once') + def serve_file_with_partial_params_test(self): + """ + Test the serve_file method with an existing file + """ + # GIVEN: mocked environment + self.router.send_response = MagicMock() + self.router.send_header = MagicMock() + self.router.end_headers = MagicMock() + self.router.wfile = MagicMock() + self.router.html_dir = os.path.normpath('test/dir') + self.router.template_vars = MagicMock() + with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ + patch('builtins.open', mock_open(read_data='123')): + mocked_exists.return_value = True + + # WHEN: call serve_file with an existing html file + self.router.serve_file(os.path.normpath('test/dir/test')) + + # THEN: it should return a 200 and the file + self.router.send_response.assert_called_once_with(200) + self.router.send_header.assert_called_once_with('Content-type', 'text/html') + self.assertEqual(self.router.end_headers.call_count, 1, 'end_headers called once') + def serve_thumbnail_without_params_test(self): """ Test the serve_thumbnail routine without params From 8507d3e26348c335ba4677564c0f1624ba8fffee Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 18 May 2016 18:25:16 +0100 Subject: [PATCH 4/4] fixes --- tests/functional/openlp_core_common/test_actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_common/test_actions.py b/tests/functional/openlp_core_common/test_actions.py index 92f030df2..afdc89c34 100644 --- a/tests/functional/openlp_core_common/test_actions.py +++ b/tests/functional/openlp_core_common/test_actions.py @@ -118,7 +118,7 @@ class TestCategoryActionList(TestCase): # GIVEN: The list including two actions self.list.add(self.action1) self.list.add(self.action2) - + # WHEN: Iterating over the list l = [a for a in self.list] # THEN: Make sure they are returned in correct order