forked from openlp/openlp
Added test for csvbible import
This commit is contained in:
parent
c3dc1e1a78
commit
81de433df4
@ -216,7 +216,8 @@ class Settings(QtCore.QSettings):
|
|||||||
'shortcuts/moveDown': [QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
'shortcuts/moveDown': [QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
||||||
'shortcuts/nextTrackItem': [],
|
'shortcuts/nextTrackItem': [],
|
||||||
'shortcuts/nextItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Down), QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
'shortcuts/nextItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Down), QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
||||||
'shortcuts/nextItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Down), QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
'shortcuts/nextItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Down),
|
||||||
|
QtGui.QKeySequence(QtCore.Qt.Key_PageDown)],
|
||||||
'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)],
|
'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)],
|
||||||
'shortcuts/newService': [],
|
'shortcuts/newService': [],
|
||||||
'shortcuts/offlineHelpItem': [],
|
'shortcuts/offlineHelpItem': [],
|
||||||
@ -230,7 +231,8 @@ class Settings(QtCore.QSettings):
|
|||||||
'shortcuts/playSlidesLoop': [],
|
'shortcuts/playSlidesLoop': [],
|
||||||
'shortcuts/playSlidesOnce': [],
|
'shortcuts/playSlidesOnce': [],
|
||||||
'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)],
|
'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)],
|
||||||
'shortcuts/previousItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Up), QtGui.QKeySequence(QtCore.Qt.Key_PageUp)],
|
'shortcuts/previousItem_preview': [QtGui.QKeySequence(QtCore.Qt.Key_Up),
|
||||||
|
QtGui.QKeySequence(QtCore.Qt.Key_PageUp)],
|
||||||
'shortcuts/printServiceItem': [QtGui.QKeySequence('Ctrl+P')],
|
'shortcuts/printServiceItem': [QtGui.QKeySequence('Ctrl+P')],
|
||||||
'shortcuts/songExportItem': [],
|
'shortcuts/songExportItem': [],
|
||||||
'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)],
|
'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)],
|
||||||
|
@ -99,14 +99,14 @@ class CSVBible(BibleDB):
|
|||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', 'Importing books... %s')
|
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', 'Importing books... %s')
|
||||||
% line[2])
|
% line[2])
|
||||||
book_ref_id = self.get_book_ref_id_by_name(line[2], 67, language_id)
|
book_ref_id = self.get_book_ref_id_by_name(line[2], 67, language_id)
|
||||||
if not book_ref_id:
|
if not book_ref_id:
|
||||||
log.error('Importing books from "%s" failed' % self.books_file)
|
log.error('Importing books from "%s" failed' % self.books_file)
|
||||||
return False
|
return False
|
||||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||||
self.create_book(line[2], book_ref_id, book_details['testament_id'])
|
self.create_book(line[2], book_ref_id, book_details['testament_id'])
|
||||||
book_list[int(line[0])] = line[2]
|
book_list.update({int(line[0]): line[2]})
|
||||||
self.application.process_events()
|
self.application.process_events()
|
||||||
except (IOError, IndexError):
|
except (IOError, IndexError):
|
||||||
log.exception('Loading books from file failed')
|
log.exception('Loading books from file failed')
|
||||||
|
97
tests/functional/openlp_plugins/bibles/test_csvimport.py
Normal file
97
tests/functional/openlp_plugins/bibles/test_csvimport.py
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2015 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# This program is free software; you can redistribute it and/or modify it #
|
||||||
|
# under the terms of the GNU General Public License as published by the Free #
|
||||||
|
# Software Foundation; version 2 of the License. #
|
||||||
|
# #
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||||
|
# more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License along #
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
|
###############################################################################
|
||||||
|
"""
|
||||||
|
This module contains tests for the CSV Bible importer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from tests.functional import MagicMock, patch
|
||||||
|
from openlp.plugins.bibles.lib.csvbible import CSVBible
|
||||||
|
from openlp.plugins.bibles.lib.db import BibleDB
|
||||||
|
|
||||||
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||||
|
'..', '..', '..', 'resources', 'bibles'))
|
||||||
|
|
||||||
|
|
||||||
|
class TestCSVImport(TestCase):
|
||||||
|
"""
|
||||||
|
Test the functions in the :mod:`csvimport` module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.registry_patcher = patch('openlp.plugins.bibles.lib.db.Registry')
|
||||||
|
self.registry_patcher.start()
|
||||||
|
self.manager_patcher = patch('openlp.plugins.bibles.lib.db.Manager')
|
||||||
|
self.manager_patcher.start()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.registry_patcher.stop()
|
||||||
|
self.manager_patcher.stop()
|
||||||
|
|
||||||
|
def create_importer_test(self):
|
||||||
|
"""
|
||||||
|
Test creating an instance of the CSV file importer
|
||||||
|
"""
|
||||||
|
# GIVEN: A mocked out "manager"
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
|
||||||
|
# WHEN: An importer object is created
|
||||||
|
importer = CSVBible(mocked_manager, path='.', name='.', booksfile='.', versefile='.')
|
||||||
|
|
||||||
|
# THEN: The importer should be an instance of BibleDB
|
||||||
|
self.assertIsInstance(importer, BibleDB)
|
||||||
|
|
||||||
|
def file_import_test(self):
|
||||||
|
"""
|
||||||
|
Test the actual import of CSV Bible file
|
||||||
|
"""
|
||||||
|
# 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.
|
||||||
|
result_file = open(os.path.join(TEST_PATH, 'dk1933.json'), 'rb')
|
||||||
|
test_data = json.loads(result_file.read().decode())
|
||||||
|
books_file = os.path.join(TEST_PATH, 'dk1933-books.csv')
|
||||||
|
verses_file = os.path.join(TEST_PATH, 'dk1933-verses.csv')
|
||||||
|
with patch('openlp.plugins.bibles.lib.csvbible.CSVBible.application'):
|
||||||
|
mocked_manager = MagicMock()
|
||||||
|
mocked_import_wizard = MagicMock()
|
||||||
|
importer = CSVBible(mocked_manager, path='.', name='.', booksfile=books_file, versefile=verses_file)
|
||||||
|
importer.wizard = mocked_import_wizard
|
||||||
|
importer.get_book_ref_id_by_name = MagicMock()
|
||||||
|
importer.create_verse = MagicMock()
|
||||||
|
importer.create_book = MagicMock()
|
||||||
|
importer.session = MagicMock()
|
||||||
|
importer.get_language = MagicMock()
|
||||||
|
importer.get_language.return_value = 'Danish'
|
||||||
|
importer.get_book = MagicMock()
|
||||||
|
|
||||||
|
# WHEN: Importing bible file
|
||||||
|
importer.do_import()
|
||||||
|
|
||||||
|
# THEN: The create_verse() method should have been called with each verse in the file.
|
||||||
|
self.assertTrue(importer.create_verse.called)
|
||||||
|
for verse_tag, verse_text in test_data['verses']:
|
||||||
|
importer.create_verse.assert_any_call(importer.get_book().id, '1', verse_tag, verse_text)
|
||||||
|
importer.create_book.assert_any_call('1. Mosebog', importer.get_book_ref_id_by_name(), 1)
|
||||||
|
importer.create_book.assert_any_call('1. Krønikebog', importer.get_book_ref_id_by_name(), 1)
|
22
tests/resources/bibles/dk1933-books.csv
Normal file
22
tests/resources/bibles/dk1933-books.csv
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
1,1,1. Mosebog,1Mos
|
||||||
|
2,1,2. Mosebog,2Mos
|
||||||
|
3,1,3. Mosebog,3Mos
|
||||||
|
4,1,4. Mosebog,4Mos
|
||||||
|
5,1,5. Mosebog,5Mos
|
||||||
|
6,1,Josvabogen,jos
|
||||||
|
7,1,Dommerbogen,dom
|
||||||
|
8,1,Ruths Bog,ruth
|
||||||
|
9,1,1. Samuelsbog,1Sam
|
||||||
|
10,1,2. Samuelsbog,2Sam
|
||||||
|
11,1,1. Kongebog,1kong
|
||||||
|
12,1,2. Kongebog,2kong
|
||||||
|
13,1,1. Krønikebog,1kron
|
||||||
|
14,1,2. Krønikebog,2kron
|
||||||
|
15,1,Ezras Bog,ezra
|
||||||
|
16,1,Nehemias' Bog,neh
|
||||||
|
17,1,Esters Bog,est
|
||||||
|
18,1,Jobs Bog,job
|
||||||
|
19,1,Salmernes Bog,sl
|
||||||
|
20,1,Ordsprogenes Bog,ordsp
|
||||||
|
21,1,Prædikerens Bog,prad
|
||||||
|
22,1,Højsangen,hojs
|
|
10
tests/resources/bibles/dk1933-verses.csv
Normal file
10
tests/resources/bibles/dk1933-verses.csv
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
1,1,1,"I Begyndelsen skabte Gud Himmelen og Jorden."
|
||||||
|
1,1,2,"Og Jorden var øde og tom, og der var Mørke over Verdensdybet. Men Guds Ånd svævede over Vandene."
|
||||||
|
1,1,3,"Og Gud sagde: ""Der blive Lys!"" Og der blev Lys."
|
||||||
|
1,1,4,"Og Gud så, at Lyset var godt, og Gud satte Skel mellem Lyset og Mørket,"
|
||||||
|
1,1,5,"og Gud kaldte Lyset Dag, og Mørket kaldte han Nat. Og det blev Aften, og det blev Morgen, første Dag."
|
||||||
|
1,1,6,"Derpå sagde Gud: ""Der blive en Hvælving midt i Vandene til at skille Vandene ad!"""
|
||||||
|
1,1,7,"Og således skete det: Gud gjorde Hvælvingen og skilte Vandet under Hvælvingen fra Vandet over Hvælvingen;"
|
||||||
|
1,1,8,"og Gud kaldte Hvælvingen Himmel. Og det blev Aften, og det blev Morgen, anden Dag."
|
||||||
|
1,1,9,"Derpå sagde Gud: ""Vandet under Himmelen samle sig på eet Sted, så det faste Land kommer til Syne!"" Og således skete det;"
|
||||||
|
1,1,10,"og Gud kaldte det faste Land Jord, og Stedet, hvor Vandet samlede sig, kaldte han Hav. Og Gud så, at det var godt."
|
|
Loading…
Reference in New Issue
Block a user