Themes api get_themes returns the preview image instead of the full background image in the theme_list

This commit is contained in:
Fernando Quant 2020-08-27 06:19:47 +00:00 committed by Tim Bentley
parent e2a65a3264
commit 0a64cc95ec
2 changed files with 18 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import logging
from openlp.core.api.lib import login_required from openlp.core.api.lib import login_required
from openlp.core.common import ThemeLevel from openlp.core.common import ThemeLevel
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.lib import image_to_data_uri
from flask import jsonify, request, abort, Blueprint, Response from flask import jsonify, request, abort, Blueprint, Response
@ -133,9 +134,14 @@ def get_themes():
themes = Registry().execute('get_theme_names') themes = Registry().execute('get_theme_names')
try: try:
for theme in themes[0]: for theme in themes[0]:
# Gets the background path, get the thumbnail from it, and encode it to a base64 data uri
theme_path = Registry().get('theme_manager').theme_path
encoded_thumb = image_to_data_uri(theme_path / 'thumbnails' / '{file_name}.png'.format(file_name=theme))
# Append the theme to the list
theme_list.append({ theme_list.append({
'name': theme, 'name': theme,
'selected': False 'selected': False,
'thumbnail': encoded_thumb
}) })
for i in theme_list: for i in theme_list:
if i["name"] == current_theme: if i["name"] == current_theme:

View File

@ -18,9 +18,10 @@
# You should have received a copy of the GNU General Public License # # You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. # # along with this program. If not, see <https://www.gnu.org/licenses/>. #
########################################################################## ##########################################################################
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from pathlib import Path
def test_retrieve_live_item(flask_client, settings): def test_retrieve_live_item(flask_client, settings):
@ -150,16 +151,21 @@ def test_controller_get_themes_retrieves_themes_list(flask_client, settings):
assert type(res) is list assert type(res) is list
def test_controller_get_themes_retrieves_themes_list_service(flask_client, settings): @patch('openlp.core.api.versions.v2.controller.image_to_data_uri')
def test_controller_get_themes_retrieves_themes_list_service(mocked_image_to_data_uri, flask_client, settings):
settings.setValue('themes/theme level', 2) settings.setValue('themes/theme level', 2)
mocked_theme_manager = MagicMock()
mocked_theme_manager.theme_path = Path()
mocked_service_manager = MagicMock() mocked_service_manager = MagicMock()
mocked_service_manager.service_theme = 'test_theme' mocked_service_manager.service_theme = 'test_theme'
Registry().register('theme_manager', MagicMock()) Registry().register('theme_manager', mocked_theme_manager)
Registry().register('service_manager', mocked_service_manager) Registry().register('service_manager', mocked_service_manager)
Registry().register_function('get_theme_names', MagicMock(side_effect=[['theme1', 'test_theme', 'theme2']])) Registry().register_function('get_theme_names', MagicMock(side_effect=[['theme1', 'test_theme', 'theme2']]))
mocked_image_to_data_uri.return_value = ''
res = flask_client.get('api/v2/controller/themes').get_json() res = flask_client.get('api/v2/controller/themes').get_json()
assert res == [{'name': 'theme1', 'selected': False}, {'name': 'test_theme', 'selected': True}, assert res == [{'thumbnail': '', 'name': 'theme1', 'selected': False},
{'name': 'theme2', 'selected': False}] {'thumbnail': '', 'name': 'test_theme', 'selected': True},
{'thumbnail': '', 'name': 'theme2', 'selected': False}]
def test_controller_get_theme_data(flask_client, settings): def test_controller_get_theme_data(flask_client, settings):