2014-11-16 22:44:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2017-12-29 09:15:48 +00:00
|
|
|
# Copyright (c) 2008-2018 OpenLP Developers #
|
2014-11-16 22:44:44 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 OpenLyrics song importer.
|
|
|
|
"""
|
|
|
|
from tempfile import mkdtemp
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
from unittest.mock import MagicMock, patch
|
2014-11-16 22:44:44 +00:00
|
|
|
|
2017-11-20 21:57:34 +00:00
|
|
|
from openlp.core.common.path import Path
|
2017-12-28 08:22:55 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2017-09-30 20:16:30 +00:00
|
|
|
from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
|
2017-04-24 05:17:55 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
|
|
|
|
2014-11-16 22:44:44 +00:00
|
|
|
|
|
|
|
class TestOpenLyricsExport(TestCase, TestMixin):
|
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`openlyricsexport` module.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the registry
|
|
|
|
"""
|
|
|
|
Registry.create()
|
2017-09-30 20:16:30 +00:00
|
|
|
self.temp_folder = Path(mkdtemp())
|
2014-11-16 22:44:44 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Cleanup
|
|
|
|
"""
|
2017-11-20 21:57:34 +00:00
|
|
|
self.temp_folder.rmtree()
|
2014-11-16 22:44:44 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_export_same_filename(self):
|
2014-11-16 22:44:44 +00:00
|
|
|
"""
|
|
|
|
Test that files is not overwritten if songs has same title and author
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked song_to_xml, 2 mocked songs, a mocked application and an OpenLyricsExport instance
|
|
|
|
with patch('openlp.plugins.songs.lib.openlyricsexport.OpenLyrics.song_to_xml') as mocked_song_to_xml:
|
|
|
|
mocked_song_to_xml.return_value = '<?xml version="1.0" encoding="UTF-8"?>\n<empty/>'
|
|
|
|
author = MagicMock()
|
|
|
|
author.display_name = 'Test Author'
|
|
|
|
song = MagicMock()
|
|
|
|
song.authors = [author]
|
|
|
|
song.title = 'Test Title'
|
|
|
|
parent = MagicMock()
|
|
|
|
parent.stop_export_flag = False
|
|
|
|
mocked_application_object = MagicMock()
|
|
|
|
Registry().register('application', mocked_application_object)
|
|
|
|
ol_export = OpenLyricsExport(parent, [song, song], self.temp_folder)
|
|
|
|
|
|
|
|
# WHEN: Doing the export
|
|
|
|
ol_export.do_export()
|
|
|
|
|
|
|
|
# THEN: The exporter should have created 2 files
|
2017-12-22 17:51:59 +00:00
|
|
|
assert (self.temp_folder / '{title} ({display_name}).xml'.format(
|
|
|
|
title=song.title, display_name=author.display_name)).exists() is True
|
|
|
|
assert (self.temp_folder / '{title} ({display_name})-1.xml'.format(
|
|
|
|
title=song.title, display_name=author.display_name)).exists() is True
|