Test tidy ups

This commit is contained in:
Phill Ridout 2017-12-22 21:20:49 +00:00
parent 590f44e212
commit c3c1f1dc66
23 changed files with 139 additions and 163 deletions

View File

@ -23,13 +23,12 @@
Provides the generic functions for interfacing plugins with the Media Manager. Provides the generic functions for interfacing plugins with the Media Manager.
""" """
import logging import logging
import os
import re import re
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
from openlp.core.common.i18n import UiStrings, translate from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.path import Path, path_to_str, str_to_path from openlp.core.common.path import path_to_str, str_to_path
from openlp.core.common.mixins import RegistryProperties from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings

View File

@ -27,6 +27,7 @@ for the Songs plugin.
import logging import logging
import os import os
import sqlite3 import sqlite3
from pathlib import Path
from tempfile import gettempdir from tempfile import gettempdir
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
@ -316,17 +317,16 @@ class SongsPlugin(Plugin):
self.application.process_events() self.application.process_events()
self.on_tools_reindex_item_triggered() self.on_tools_reindex_item_triggered()
self.application.process_events() self.application.process_events()
db_dir = os.path.join(gettempdir(), 'openlp') db_dir_path = Path(gettempdir(), 'openlp')
if not os.path.exists(db_dir): if not db_dir_path.exists():
return return
song_dbs = [] song_db_paths = []
song_count = 0 song_count = 0
for sfile in os.listdir(db_dir): for db_file_path in db_dir_path.glob('songs_*.sqlite'):
if sfile.startswith('songs_') and sfile.endswith('.sqlite'): self.application.process_events()
self.application.process_events() song_db_paths.append(db_file_path)
song_dbs.append(os.path.join(db_dir, sfile)) song_count += SongsPlugin._count_songs(db_file_path)
song_count += SongsPlugin._count_songs(os.path.join(db_dir, sfile)) if not song_db_paths:
if not song_dbs:
return return
self.application.process_events() self.application.process_events()
progress = QtWidgets.QProgressDialog(self.main_window) progress = QtWidgets.QProgressDialog(self.main_window)
@ -338,8 +338,8 @@ class SongsPlugin(Plugin):
progress.setMinimumDuration(0) progress.setMinimumDuration(0)
progress.forceShow() progress.forceShow()
self.application.process_events() self.application.process_events()
for db in song_dbs: for db_path in song_db_paths:
importer = OpenLPSongImport(self.manager, file_path=db) importer = OpenLPSongImport(self.manager, file_path=db_path)
importer.do_import(progress) importer.do_import(progress)
self.application.process_events() self.application.process_events()
progress.setValue(song_count) progress.setValue(song_count)
@ -373,13 +373,15 @@ class SongsPlugin(Plugin):
self.manager.delete_object(Song, song.id) self.manager.delete_object(Song, song.id)
@staticmethod @staticmethod
def _count_songs(db_file): def _count_songs(db_path):
""" """
Provide a count of the songs in the database Provide a count of the songs in the database
:param db_file: the database name to count :param openlp.core.common.path.Path db_path: The database to use
:return: The number of songs in the db.
:rtype: int
""" """
connection = sqlite3.connect(db_file) connection = sqlite3.connect(str(db_path))
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute('SELECT COUNT(id) AS song_count FROM songs') cursor.execute('SELECT COUNT(id) AS song_count FROM songs')
song_count = cursor.fetchone()[0] song_count = cursor.fetchone()[0]

View File

@ -22,7 +22,6 @@
""" """
This module contains tests for the lib submodule of the Remotes plugin. This module contains tests for the lib submodule of the Remotes plugin.
""" """
import os
import re import re
from unittest import TestCase from unittest import TestCase
from unittest.mock import patch from unittest.mock import patch
@ -45,7 +44,6 @@ __default_settings__ = {
'remotes/download version': '0000_00_00' 'remotes/download version': '0000_00_00'
} }
ZERO_URL = '0.0.0.0' ZERO_URL = '0.0.0.0'
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestApiTab(TestCase, TestMixin): class TestApiTab(TestCase, TestMixin):

View File

@ -22,14 +22,11 @@
""" """
Package to test the openlp.core.lib package. Package to test the openlp.core.lib package.
""" """
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock from unittest.mock import MagicMock
from openlp.core.common.registry import Registry, RegistryBase from openlp.core.common.registry import Registry, RegistryBase
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../', '..', 'resources'))
class TestRegistry(TestCase): class TestRegistry(TestCase):

View File

@ -35,8 +35,9 @@ from openlp.core.display.screens import ScreenList
from openlp.core.lib.imagemanager import ImageManager, Priority from openlp.core.lib.imagemanager import ImageManager, Priority
from tests.helpers.testmixin import TestMixin from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources')) TEST_PATH = str(RESOURCE_PATH)
class TestImageManager(TestCase, TestMixin): class TestImageManager(TestCase, TestMixin):

View File

@ -22,7 +22,6 @@
""" """
Package to test the openlp.core.lib package. Package to test the openlp.core.lib package.
""" """
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -32,8 +31,7 @@ from openlp.core.common.path import Path
from openlp.core.lib import FormattingTags, build_icon, check_item_selected, clean_tags, compare_chord_lyric, \ from openlp.core.lib import FormattingTags, build_icon, check_item_selected, clean_tags, compare_chord_lyric, \
create_separated_list, create_thumb, expand_chords, expand_chords_for_printing, expand_tags, find_formatting_tags, \ create_separated_list, create_thumb, expand_chords, expand_chords_for_printing, expand_tags, find_formatting_tags, \
get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
class TestLib(TestCase): class TestLib(TestCase):
@ -273,8 +271,8 @@ class TestLib(TestCase):
Test the create_thumb() function with a given size. Test the create_thumb() function with a given size.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
thumb_size = QtCore.QSize(10, 20) thumb_size = QtCore.QSize(10, 20)
# Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the
@ -307,8 +305,8 @@ class TestLib(TestCase):
Test the create_thumb() function with no size specified. Test the create_thumb() function with no size specified.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
expected_size = QtCore.QSize(63, 88) expected_size = QtCore.QSize(63, 88)
# Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the # Remove the thumb so that the test actually tests if the thumb will be created. Maybe it was not deleted in the
@ -341,8 +339,8 @@ class TestLib(TestCase):
Test the create_thumb() function with invalid size specified. Test the create_thumb() function with invalid size specified.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
thumb_size = QtCore.QSize(-1, -1) thumb_size = QtCore.QSize(-1, -1)
expected_size = QtCore.QSize(63, 88) expected_size = QtCore.QSize(63, 88)
@ -376,8 +374,8 @@ class TestLib(TestCase):
Test the create_thumb() function with a size of only width specified. Test the create_thumb() function with a size of only width specified.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
thumb_size = QtCore.QSize(100, -1) thumb_size = QtCore.QSize(100, -1)
expected_size = QtCore.QSize(100, 137) expected_size = QtCore.QSize(100, 137)
@ -411,8 +409,8 @@ class TestLib(TestCase):
Test the create_thumb() function with a size of only height specified. Test the create_thumb() function with a size of only height specified.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
thumb_size = QtCore.QSize(-1, 100) thumb_size = QtCore.QSize(-1, 100)
expected_size = QtCore.QSize(72, 100) expected_size = QtCore.QSize(72, 100)
@ -446,8 +444,8 @@ class TestLib(TestCase):
Test the create_thumb() function with a size of only height specified. Test the create_thumb() function with a size of only height specified.
""" """
# GIVEN: An image to create a thumb of. # GIVEN: An image to create a thumb of.
image_path = Path(TEST_PATH, 'church.jpg') image_path = RESOURCE_PATH / 'church.jpg'
thumb_path = Path(TEST_PATH, 'church_thumb.jpg') thumb_path = RESOURCE_PATH / 'church_thumb.jpg'
thumb_size = QtCore.QSize(-1, 100) thumb_size = QtCore.QSize(-1, 100)
expected_size_1 = QtCore.QSize(88, 88) expected_size_1 = QtCore.QSize(88, 88)
expected_size_2 = QtCore.QSize(100, 100) expected_size_2 = QtCore.QSize(100, 100)
@ -639,7 +637,7 @@ class TestLib(TestCase):
Test the resize_thumb() function Test the resize_thumb() function
""" """
# GIVEN: A path to an image. # GIVEN: A path to an image.
image_path = os.path.join(TEST_PATH, 'church.jpg') image_path = str(RESOURCE_PATH / 'church.jpg')
wanted_width = 777 wanted_width = 777
wanted_height = 72 wanted_height = 72
# We want the background to be white. # We want the background to be white.
@ -660,7 +658,7 @@ class TestLib(TestCase):
Test the resize_thumb() function ignoring aspect ratio Test the resize_thumb() function ignoring aspect ratio
""" """
# GIVEN: A path to an image. # GIVEN: A path to an image.
image_path = os.path.join(TEST_PATH, 'church.jpg') image_path = str(RESOURCE_PATH / 'church.jpg')
wanted_width = 1000 wanted_width = 1000
wanted_height = 1000 wanted_height = 1000
# We want the background to be white. # We want the background to be white.

View File

@ -31,7 +31,6 @@ from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings
from openlp.core.lib import ItemCapabilities, ServiceItem, ServiceItemType, FormattingTags from openlp.core.lib import ItemCapabilities, ServiceItem, ServiceItemType, FormattingTags
from tests.helpers.testmixin import TestMixin from tests.helpers.testmixin import TestMixin
from tests.utils import assert_length, convert_file_service_item from tests.utils import assert_length, convert_file_service_item
VERSE = 'The Lord said to {r}Noah{/r}: \n'\ VERSE = 'The Lord said to {r}Noah{/r}: \n'\

View File

@ -24,7 +24,6 @@ This module contains tests for the CSV Bible importer.
""" """
import csv import csv
import json import json
import os
from collections import namedtuple from collections import namedtuple
from unittest import TestCase from unittest import TestCase
from unittest.mock import ANY, MagicMock, PropertyMock, call, patch from unittest.mock import ANY, MagicMock, PropertyMock, call, patch
@ -33,10 +32,9 @@ from openlp.core.common.path import Path
from openlp.core.lib.exceptions import ValidationError from openlp.core.lib.exceptions import ValidationError
from openlp.plugins.bibles.lib.bibleimport import BibleImport from openlp.plugins.bibles.lib.bibleimport import BibleImport
from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse from openlp.plugins.bibles.lib.importers.csvbible import Book, CSVBible, Verse
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'bibles'
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', '..', 'resources', 'bibles'))
class TestCSVImport(TestCase): class TestCSVImport(TestCase):
@ -332,10 +330,10 @@ class TestCSVImport(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
books_file = Path(TEST_PATH, 'dk1933-books.csv') books_file = TEST_PATH / 'dk1933-books.csv'
verses_file = Path(TEST_PATH, 'dk1933-verses.csv') verses_file = TEST_PATH / 'dk1933-verses.csv'
with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'): with patch('openlp.plugins.bibles.lib.importers.csvbible.CSVBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
mocked_import_wizard = MagicMock() mocked_import_wizard = MagicMock()

View File

@ -23,21 +23,19 @@
This module contains tests for the OpenSong Bible importer. This module contains tests for the OpenSong Bible importer.
""" """
import json import json
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock, patch, call from unittest.mock import MagicMock, patch, call
from lxml import objectify from lxml import objectify
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number from openlp.plugins.bibles.lib.importers.opensong import OpenSongBible, get_text, parse_chapter_number
from openlp.plugins.bibles.lib.bibleimport import BibleImport from openlp.plugins.bibles.lib.bibleimport import BibleImport
from tests.helpers.testmixin import TestMixin from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), TEST_PATH = RESOURCE_PATH / 'bibles'
'..', '..', '..', 'resources', 'bibles'))
class TestOpenSongImport(TestCase, TestMixin): class TestOpenSongImport(TestCase, TestMixin):
@ -401,8 +399,8 @@ class TestOpenSongImportFileImports(TestCase, TestMixin):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'opensong-dk1933.xml' bible_file = 'opensong-dk1933.xml'
with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'): with patch('openlp.plugins.bibles.lib.importers.opensong.OpenSongBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -417,7 +415,7 @@ class TestOpenSongImportFileImports(TestCase, TestMixin):
importer.get_language.return_value = 'Danish' importer.get_language.return_value = 'Danish'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.

View File

@ -22,17 +22,17 @@
""" """
This module contains tests for the OSIS Bible importer. This module contains tests for the OSIS Bible importer.
""" """
import os
import json import json
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock, call, patch from unittest.mock import MagicMock, call, patch
from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.bibleimport import BibleImport from openlp.plugins.bibles.lib.bibleimport import BibleImport
from openlp.plugins.bibles.lib.db import BibleDB from openlp.plugins.bibles.lib.db import BibleDB
from openlp.plugins.bibles.lib.importers.osis import OSISBible from openlp.plugins.bibles.lib.importers.osis import OSISBible
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'bibles')) from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'bibles'
class TestOsisImport(TestCase): class TestOsisImport(TestCase):
@ -422,8 +422,8 @@ class TestOsisImportFileImports(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'osis-dk1933.xml' bible_file = 'osis-dk1933.xml'
with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -438,7 +438,7 @@ class TestOsisImportFileImports(TestCase):
importer.get_language.return_value = 'Danish' importer.get_language.return_value = 'Danish'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.
@ -452,8 +452,8 @@ class TestOsisImportFileImports(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'kjv.json'), 'rb') file_data = (TEST_PATH / 'kjv.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'osis-kjv.xml' bible_file = 'osis-kjv.xml'
with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -468,7 +468,7 @@ class TestOsisImportFileImports(TestCase):
importer.get_language.return_value = 'English' importer.get_language.return_value = 'English'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.
@ -482,8 +482,8 @@ class TestOsisImportFileImports(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'web.json'), 'rb') file_data = (TEST_PATH / 'web.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'osis-web.xml' bible_file = 'osis-web.xml'
with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -498,7 +498,7 @@ class TestOsisImportFileImports(TestCase):
importer.get_language.return_value = 'English' importer.get_language.return_value = 'English'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.
@ -512,8 +512,8 @@ class TestOsisImportFileImports(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'osis-dk1933-empty-verse.xml' bible_file = 'osis-dk1933-empty-verse.xml'
with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'): with patch('openlp.plugins.bibles.lib.importers.osis.OSISBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -528,7 +528,7 @@ class TestOsisImportFileImports(TestCase):
importer.get_language.return_value = 'Danish' importer.get_language.return_value = 'Danish'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.

View File

@ -22,8 +22,6 @@
""" """
This module contains tests for the SWORD Bible importer. This module contains tests for the SWORD Bible importer.
""" """
import os
import json import json
from unittest import TestCase, skipUnless from unittest import TestCase, skipUnless
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -36,8 +34,9 @@ except ImportError:
from openlp.plugins.bibles.lib.db import BibleDB from openlp.plugins.bibles.lib.db import BibleDB
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), from tests.utils.constants import TEST_RESOURCES_PATH
'..', '..', '..', 'resources', 'bibles'))
TEST_PATH = TEST_RESOURCES_PATH / 'bibles'
@skipUnless(HAS_PYSWORD, 'pysword not installed') @skipUnless(HAS_PYSWORD, 'pysword not installed')
@ -81,8 +80,8 @@ class TestSwordImport(TestCase):
mocked_manager = MagicMock() mocked_manager = MagicMock()
mocked_import_wizard = MagicMock() mocked_import_wizard = MagicMock()
importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='') importer = SwordBible(mocked_manager, path='.', name='.', file_path=None, sword_key='', sword_path='')
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
importer.wizard = mocked_import_wizard importer.wizard = mocked_import_wizard
importer.get_book_ref_id_by_name = MagicMock() importer.get_book_ref_id_by_name = MagicMock()
importer.create_verse = MagicMock() importer.create_verse = MagicMock()

View File

@ -22,18 +22,17 @@
""" """
This module contains tests for the WordProject Bible importer. This module contains tests for the WordProject Bible importer.
""" """
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock, patch, call from unittest.mock import MagicMock, patch, call
from openlp.core.common.path import Path from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible from openlp.plugins.bibles.lib.importers.wordproject import WordProjectBible
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), TEST_PATH = RESOURCE_PATH / 'bibles'
'..', '..', '..', 'resources', 'bibles')) INDEX_PAGE = (TEST_PATH / 'wordproject_index.htm').read_text()
INDEX_PAGE = open(os.path.join(TEST_PATH, 'wordproject_index.htm')).read() CHAPTER_PAGE = (TEST_PATH / 'wordproject_chapter.htm').read_text()
CHAPTER_PAGE = open(os.path.join(TEST_PATH, 'wordproject_chapter.htm')).read()
class TestWordProjectImport(TestCase): class TestWordProjectImport(TestCase):

View File

@ -31,8 +31,9 @@ from openlp.core.common.path import Path
from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible from openlp.plugins.bibles.lib.importers.zefania import ZefaniaBible
from openlp.plugins.bibles.lib.db import BibleDB from openlp.plugins.bibles.lib.db import BibleDB
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), from tests.utils.constants import RESOURCE_PATH
'..', '..', '..', 'resources', 'bibles'))
TEST_PATH = RESOURCE_PATH / 'bibles'
class TestZefaniaImport(TestCase): class TestZefaniaImport(TestCase):
@ -67,8 +68,8 @@ class TestZefaniaImport(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb') file_data = (TEST_PATH / 'dk1933.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'zefania-dk1933.xml' bible_file = 'zefania-dk1933.xml'
with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -82,7 +83,7 @@ class TestZefaniaImport(TestCase):
importer.get_language.return_value = 'Danish' importer.get_language.return_value = 'Danish'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.
@ -97,8 +98,8 @@ class TestZefaniaImport(TestCase):
""" """
# GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions # GIVEN: Test files with a mocked out "manager", "import_wizard", and mocked functions
# get_book_ref_id_by_name, create_verse, create_book, session and get_language. # get_book_ref_id_by_name, create_verse, create_book, session and get_language.
result_file = open(os.path.join(TEST_PATH, 'rst.json'), 'rb') file_data = (TEST_PATH / 'rst.json').read_text()
test_data = json.loads(result_file.read().decode()) test_data = json.loads(file_data)
bible_file = 'zefania-rst.xml' bible_file = 'zefania-rst.xml'
with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'): with patch('openlp.plugins.bibles.lib.importers.zefania.ZefaniaBible.application'):
mocked_manager = MagicMock() mocked_manager = MagicMock()
@ -112,7 +113,7 @@ class TestZefaniaImport(TestCase):
importer.get_language.return_value = 'Russian' importer.get_language.return_value = 'Russian'
# WHEN: Importing bible file # WHEN: Importing bible file
importer.file_path = Path(TEST_PATH, bible_file) importer.file_path = TEST_PATH / bible_file
importer.do_import() importer.do_import()
# THEN: The create_verse() method should have been called with each verse in the file. # THEN: The create_verse() method should have been called with each verse in the file.

View File

@ -22,15 +22,12 @@
""" """
This module contains tests for the OpenSong song importer. This module contains tests for the OpenSong song importer.
""" """
import os
from openlp.core.common.path import Path
from tests.helpers.songfileimport import SongImportTestHelper
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
TEST_PATH = os.path.abspath( from tests.helpers.songfileimport import SongImportTestHelper
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'chordprosongs')) from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'chordprosongs'
class TestChordProFileImport(SongImportTestHelper): class TestChordProFileImport(SongImportTestHelper):
@ -50,5 +47,5 @@ class TestChordProFileImport(SongImportTestHelper):
mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings mocked_settings.return_value = mocked_returned_settings
# Do the test import # Do the test import
self.file_import([Path(TEST_PATH, 'swing-low.chordpro')], self.file_import([TEST_PATH / 'swing-low.chordpro'],
self.load_external_result_data(os.path.join(TEST_PATH, 'swing-low.json'))) self.load_external_result_data(TEST_PATH / 'swing-low.json'))

View File

@ -21,14 +21,10 @@
""" """
This module contains tests for the EasySlides song importer. This module contains tests for the EasySlides song importer.
""" """
import os
from openlp.core.common.path import Path
from tests.helpers.songfileimport import SongImportTestHelper from tests.helpers.songfileimport import SongImportTestHelper
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath( TEST_PATH = RESOURCE_PATH / 'easyslidessongs'
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'easyslidessongs'))
class TestEasySlidesFileImport(SongImportTestHelper): class TestEasySlidesFileImport(SongImportTestHelper):
@ -42,7 +38,7 @@ class TestEasySlidesFileImport(SongImportTestHelper):
""" """
Test that loading an EasySlides file works correctly on various files Test that loading an EasySlides file works correctly on various files
""" """
self.file_import(Path(TEST_PATH, 'amazing-grace.xml'), self.file_import(TEST_PATH / 'amazing-grace.xml',
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import(Path(TEST_PATH, 'Export_2017-01-12_BB.xml'), self.file_import(TEST_PATH / 'Export_2017-01-12_BB.xml',
self.load_external_result_data(os.path.join(TEST_PATH, 'Export_2017-01-12_BB.json'))) self.load_external_result_data(TEST_PATH / 'Export_2017-01-12_BB.json'))

View File

@ -29,8 +29,9 @@ from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.plugins.songs.lib.importers.easyworship import EasyWorshipSongImport, FieldDescEntry, FieldType from openlp.plugins.songs.lib.importers.easyworship import EasyWorshipSongImport, FieldDescEntry, FieldType
TEST_PATH = os.path.abspath( from tests.utils.constants import RESOURCE_PATH
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'easyworshipsongs'))
TEST_PATH = RESOURCE_PATH / 'easyworshipsongs'
SONG_TEST_DATA = [ SONG_TEST_DATA = [
{'title': 'Amazing Grace', {'title': 'Amazing Grace',
'authors': ['John Newton'], 'authors': ['John Newton'],
@ -387,10 +388,10 @@ class TestEasyWorshipSongImport(TestCase):
mocked_retrieve_windows_encoding.assert_any_call(encoding) mocked_retrieve_windows_encoding.assert_any_call(encoding)
def test_db_file_import(self): def test_db_file_import(self):
return self._run_db_file_import(os.path.join(TEST_PATH, 'Songs.DB')) return self._run_db_file_import(TEST_PATH / 'Songs.DB')
def test_sqlite_db_file_import(self): def test_sqlite_db_file_import(self):
return self._run_db_file_import(os.path.join(TEST_PATH, 'ew6')) return self._run_db_file_import(TEST_PATH / 'ew6')
def _run_db_file_import(self, source_path): def _run_db_file_import(self, source_path):
""" """
@ -420,7 +421,8 @@ class TestEasyWorshipSongImport(TestCase):
importer.topics = [] importer.topics = []
# WHEN: Importing each file # WHEN: Importing each file
importer.import_source = source_path # TODO: To Path object
importer.import_source = str(source_path)
import_result = importer.do_import() import_result = importer.do_import()
# THEN: do_import should return none, the song data should be as expected, and finish should have been # THEN: do_import should return none, the song data should be as expected, and finish should have been
@ -475,7 +477,7 @@ class TestEasyWorshipSongImport(TestCase):
importer.topics = [] importer.topics = []
# WHEN: Importing ews file # WHEN: Importing ews file
importer.import_source = os.path.join(TEST_PATH, 'test1.ews') importer.import_source = str(TEST_PATH / 'test1.ews')
import_result = importer.do_import() import_result = importer.do_import()
# THEN: do_import should return none, the song data should be as expected, and finish should have been # THEN: do_import should return none, the song data should be as expected, and finish should have been

View File

@ -22,15 +22,11 @@
""" """
This module contains tests for the SongShow Plus song importer. This module contains tests for the SongShow Plus song importer.
""" """
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from openlp.plugins.songs.lib.importers.foilpresenter import FoilPresenter from openlp.plugins.songs.lib.importers.foilpresenter import FoilPresenter
TEST_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', '/resources/foilpresentersongs'))
class TestFoilPresenter(TestCase): class TestFoilPresenter(TestCase):
""" """

View File

@ -21,14 +21,10 @@
""" """
This module contains tests for the LyriX song importer. This module contains tests for the LyriX song importer.
""" """
import os
from openlp.core.common.path import Path
from tests.helpers.songfileimport import SongImportTestHelper from tests.helpers.songfileimport import SongImportTestHelper
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath( TEST_PATH = RESOURCE_PATH / 'lyrixsongs'
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'lyrixsongs'))
class TestLyrixFileImport(SongImportTestHelper): class TestLyrixFileImport(SongImportTestHelper):
@ -42,9 +38,9 @@ class TestLyrixFileImport(SongImportTestHelper):
""" """
Test that loading an LyriX file works correctly on various files Test that loading an LyriX file works correctly on various files
""" """
self.file_import([Path(TEST_PATH, 'A06.TXT')], self.file_import([TEST_PATH / 'A06.TXT'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([Path(TEST_PATH, 'A002.TXT')], self.file_import([TEST_PATH / 'A002.TXT'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace2.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace2.json'))
self.file_import([Path(TEST_PATH, 'AO05.TXT')], self.file_import([TEST_PATH / 'AO05.TXT'],
self.load_external_result_data(os.path.join(TEST_PATH, 'in die regterhand.json'))) self.load_external_result_data(TEST_PATH / 'in die regterhand.json'))

View File

@ -22,14 +22,12 @@
""" """
This module contains tests for the OpenLyrics song importer. This module contains tests for the OpenLyrics song importer.
""" """
import os
import json import json
from unittest import TestCase from unittest import TestCase
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from lxml import etree, objectify from lxml import etree, objectify
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings
from openlp.plugins.songs.lib.importers.openlyrics import OpenLyricsImport from openlp.plugins.songs.lib.importers.openlyrics import OpenLyricsImport
@ -37,9 +35,9 @@ from openlp.plugins.songs.lib.importers.songimport import SongImport
from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics from openlp.plugins.songs.lib.openlyricsxml import OpenLyrics
from tests.helpers.testmixin import TestMixin from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), TEST_PATH = RESOURCE_PATH / 'openlyricssongs'
'..', '..', '..', 'resources', 'openlyricssongs'))
SONG_TEST_DATA = { SONG_TEST_DATA = {
'What a friend we have in Jesus.xml': { 'What a friend we have in Jesus.xml': {
'title': 'What A Friend We Have In Jesus', 'title': 'What A Friend We Have In Jesus',
@ -130,7 +128,7 @@ class TestOpenLyricsImport(TestCase, TestMixin):
importer.open_lyrics.xml_to_song = MagicMock() importer.open_lyrics.xml_to_song = MagicMock()
# WHEN: Importing each file # WHEN: Importing each file
importer.import_source = [Path(TEST_PATH, song_file)] importer.import_source = [TEST_PATH / song_file]
importer.do_import() importer.do_import()
# THEN: The xml_to_song() method should have been called # THEN: The xml_to_song() method should have been called
@ -145,7 +143,7 @@ class TestOpenLyricsImport(TestCase, TestMixin):
Settings().setValue('formattingTags/html_tags', json.dumps(start_tags)) Settings().setValue('formattingTags/html_tags', json.dumps(start_tags))
ol = OpenLyrics(mocked_manager) ol = OpenLyrics(mocked_manager)
parser = etree.XMLParser(remove_blank_text=True) parser = etree.XMLParser(remove_blank_text=True)
parsed_file = etree.parse(open(os.path.join(TEST_PATH, 'duchu-tags.xml'), 'rb'), parser) parsed_file = etree.parse((TEST_PATH / 'duchu-tags.xml').open('rb'), parser)
xml = etree.tostring(parsed_file).decode() xml = etree.tostring(parsed_file).decode()
song_xml = objectify.fromstring(xml) song_xml = objectify.fromstring(xml)

View File

@ -22,18 +22,16 @@
""" """
This module contains tests for the OpenSong song importer. This module contains tests for the OpenSong song importer.
""" """
import os
from unittest import TestCase from unittest import TestCase
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.common.path import Path
from openlp.plugins.songs.lib.importers.opensong import OpenSongImport from openlp.plugins.songs.lib.importers.opensong import OpenSongImport
from tests.helpers.songfileimport import SongImportTestHelper from tests.helpers.songfileimport import SongImportTestHelper
from tests.utils.constants import RESOURCE_PATH
TEST_PATH = os.path.abspath( TEST_PATH = RESOURCE_PATH / 'opensongsongs'
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'opensongsongs'))
class TestOpenSongFileImport(SongImportTestHelper): class TestOpenSongFileImport(SongImportTestHelper):
@ -53,16 +51,16 @@ class TestOpenSongFileImport(SongImportTestHelper):
mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False mocked_returned_settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False
mocked_settings.return_value = mocked_returned_settings mocked_settings.return_value = mocked_returned_settings
# Do the test import # Do the test import
self.file_import([Path(TEST_PATH, 'Amazing Grace')], self.file_import([TEST_PATH / 'Amazing Grace'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([Path(TEST_PATH, 'Beautiful Garden Of Prayer')], self.file_import([TEST_PATH / 'Beautiful Garden Of Prayer'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) self.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json'))
self.file_import([Path(TEST_PATH, 'One, Two, Three, Four, Five')], self.file_import([TEST_PATH / 'One, Two, Three, Four, Five'],
self.load_external_result_data(os.path.join(TEST_PATH, 'One, Two, Three, Four, Five.json'))) self.load_external_result_data(TEST_PATH / 'One, Two, Three, Four, Five.json'))
self.file_import([Path(TEST_PATH, 'Amazing Grace2')], self.file_import([TEST_PATH / 'Amazing Grace2'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace.json'))
self.file_import([Path(TEST_PATH, 'Amazing Grace with bad CCLI')], self.file_import([TEST_PATH / 'Amazing Grace with bad CCLI'],
self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace without CCLI.json'))) self.load_external_result_data(TEST_PATH / 'Amazing Grace without CCLI.json'))
class TestOpenSongImport(TestCase): class TestOpenSongImport(TestCase):

View File

@ -22,7 +22,6 @@
""" """
This module contains tests for the WorshipCenter Pro song importer. This module contains tests for the WorshipCenter Pro song importer.
""" """
import os
import json import json
from unittest import TestCase, skipUnless from unittest import TestCase, skipUnless
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
@ -34,7 +33,9 @@ try:
except ImportError: except ImportError:
CAN_RUN_TESTS = False CAN_RUN_TESTS = False
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'opsprosongs')) from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'opsprosongs'
def _get_item(data, key): def _get_item(data, key):
@ -59,8 +60,7 @@ def _build_data(test_file, dual_language):
song.Version = '1' song.Version = '1'
song.Origin = '...' song.Origin = '...'
lyrics = MagicMock() lyrics = MagicMock()
test_file = open(os.path.join(TEST_PATH, test_file), 'rb') lyrics.Lyrics = (TEST_PATH / test_file).read_text()
lyrics.Lyrics = test_file.read().decode()
lyrics.Type = 1 lyrics.Type = 1
lyrics.IsDualLanguage = dual_language lyrics.IsDualLanguage = dual_language
return song, lyrics return song, lyrics
@ -106,8 +106,8 @@ class TestOpsProSongImport(TestCase):
importer.process_song(song, lyrics, []) importer.process_song(song, lyrics, [])
# THEN: The imported data should look like expected # THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'You are so faithful.json'), 'rb') file_data = (TEST_PATH / 'You are so faithful.json').read_text()
result_data = json.loads(result_file.read().decode()) result_data = json.loads(file_data)
self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
@ -126,8 +126,8 @@ class TestOpsProSongImport(TestCase):
importer.process_song(song, lyrics, []) importer.process_song(song, lyrics, [])
# THEN: The imported data should look like expected # THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace.json'), 'rb') file_data = (TEST_PATH / 'Amazing Grace.json').read_text()
result_data = json.loads(result_file.read().decode()) result_data = json.loads(file_data)
self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
@ -146,8 +146,8 @@ class TestOpsProSongImport(TestCase):
importer.process_song(song, lyrics, []) importer.process_song(song, lyrics, [])
# THEN: The imported data should look like expected # THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace.json'), 'rb') file_data = (TEST_PATH / 'Amazing Grace.json').read_text()
result_data = json.loads(result_file.read().decode()) result_data = json.loads(file_data)
self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))
@ -166,7 +166,7 @@ class TestOpsProSongImport(TestCase):
importer.process_song(song, lyrics, []) importer.process_song(song, lyrics, [])
# THEN: The imported data should look like expected # THEN: The imported data should look like expected
result_file = open(os.path.join(TEST_PATH, 'Amazing Grace3.json'), 'rb') file_data = (TEST_PATH / 'Amazing Grace3.json').read_text()
result_data = json.loads(result_file.read().decode()) result_data = json.loads(file_data)
self.assertListEqual(importer.verses, _get_item(result_data, 'verses')) self.assertListEqual(importer.verses, _get_item(result_data, 'verses'))
self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list')) self.assertListEqual(importer.verse_order_list_generated, _get_item(result_data, 'verse_order_list'))

View File

@ -82,7 +82,8 @@ class SongImportTestHelper(TestCase):
""" """
A method to load and return an object containing the song data from an external file. A method to load and return an object containing the song data from an external file.
""" """
result_file = open(file_name, 'rb') # TODO: To path object
result_file = open(str(file_name, 'rb'))
return json.loads(result_file.read().decode()) return json.loads(result_file.read().decode())
def file_import(self, source_file_name, result_data): def file_import(self, source_file_name, result_data):

View File

@ -1,5 +1,8 @@
import os import os
from openlp.core.common.path import Path
OPENLP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) OPENLP_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
TEST_RESOURCES_PATH = os.path.join(OPENLP_PATH, 'tests', 'resources') TEST_RESOURCES_PATH = os.path.join(OPENLP_PATH, 'tests', 'resources')
RESOURCE_PATH = Path(TEST_RESOURCES_PATH)