mirror of https://gitlab.com/openlp/openlp.git
Fix api crash on background audio attached
This commit is contained in:
parent
bd811c2b7a
commit
dc3015bd74
|
@ -22,9 +22,11 @@ import logging
|
|||
|
||||
from openlp.core.api.lib import login_required
|
||||
from openlp.core.common import ThemeLevel
|
||||
from openlp.core.common.json import OpenLPJSONEncoder
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.lib import image_to_data_uri
|
||||
|
||||
import json
|
||||
from flask import jsonify, request, abort, Blueprint, Response
|
||||
|
||||
controller_views = Blueprint('controller', __name__)
|
||||
|
@ -41,7 +43,8 @@ def controller_live_items():
|
|||
live_item = current_item.to_dict()
|
||||
live_item['slides'][live_controller.selected_row]['selected'] = True
|
||||
live_item['id'] = str(current_item.unique_identifier)
|
||||
return jsonify(live_item)
|
||||
json_live_item = json.dumps(live_item, cls=OpenLPJSONEncoder)
|
||||
return Response(json_live_item, mimetype='application/json')
|
||||
|
||||
|
||||
@controller_views.route('/live-item')
|
||||
|
@ -53,7 +56,8 @@ def controller_live_item():
|
|||
if current_item:
|
||||
live_item = current_item.to_dict(True, live_controller.selected_row)
|
||||
live_item['id'] = str(current_item.unique_identifier)
|
||||
return jsonify(live_item)
|
||||
json_live_item = json.dumps(live_item, cls=OpenLPJSONEncoder)
|
||||
return Response(json_live_item, mimetype='application/json')
|
||||
|
||||
|
||||
@controller_views.route('/show', methods=['POST'])
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
"""
|
||||
Package to test the openlp.core.lib package.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
@ -28,6 +29,7 @@ from unittest.mock import Mock, MagicMock, patch
|
|||
|
||||
from openlp.core.common import ThemeLevel
|
||||
from openlp.core.common.enum import ServiceItemType
|
||||
from openlp.core.common.json import OpenLPJSONEncoder
|
||||
from openlp.core.common.platform import is_win
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.lib.formattingtags import FormattingTags
|
||||
|
@ -442,6 +444,26 @@ def test_service_item_load_song_and_audio_from_service(mock_sha256_file_hash, st
|
|||
'The tuple ("/test/abcd.mp3", "abcd") should be in the background_audio list'
|
||||
|
||||
|
||||
@patch('openlp.core.lib.serviceitem.sha256_file_hash')
|
||||
def test_service_item_to_dict_is_valid_json(mock_sha256_file_hash, state_media, settings, service_item_env):
|
||||
"""
|
||||
Test the Service Item - Converting to to_dict response to json
|
||||
"""
|
||||
# GIVEN: A new service item with song slide
|
||||
service_item = ServiceItem(None)
|
||||
service_item.add_icon = MagicMock()
|
||||
FormattingTags.load_tags()
|
||||
mock_sha256_file_hash.return_value = 'abcd'
|
||||
line = convert_file_service_item(TEST_PATH, 'serviceitem-song-linked-audio.osj')
|
||||
service_item.set_from_service(line, Path('/test/'))
|
||||
|
||||
# WHEN: Generating a service item
|
||||
service_dict = service_item.to_dict()
|
||||
|
||||
# THEN: We should get back a valid json object
|
||||
assert json.dumps(service_dict, cls=OpenLPJSONEncoder) is not None
|
||||
|
||||
|
||||
def test_service_item_get_theme_data_global_level(settings):
|
||||
"""
|
||||
Test the service item - get theme data when set to global theme level
|
||||
|
|
Loading…
Reference in New Issue