openlp/tests/functional/openlp_plugins/songs/test_songformat.py

96 lines
5.0 KiB
Python
Raw Normal View History

2015-12-30 21:36:37 +00:00
# -*- 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 SongFormat class
"""
from unittest import TestCase
from openlp.plugins.songs.lib.importer import SongFormat
class TestSongFormat(TestCase):
2016-01-05 21:35:35 +00:00
"""
Test the functions in the :class:`SongFormat` class.
"""
2015-12-30 21:36:37 +00:00
def test_get_format_list(self):
2016-01-05 21:35:35 +00:00
"""
Test that get_format_list() returns all available formats
"""
2016-01-02 23:37:22 +00:00
# GIVEN: The SongFormat class
# WHEN: Retrieving the format list
# THEN: All SongFormats should be returned
self.assertEquals(len(SongFormat.get_format_list()), len(SongFormat.__attributes__),
2016-01-09 16:26:14 +00:00
"The returned SongFormats don't match the stored ones")
2015-12-30 21:36:37 +00:00
def test_get_attributed_no_attributes(self):
2016-01-05 21:35:35 +00:00
"""
Test that SongFormat.get(song_format) returns all attributes associated with the given song_format
"""
2016-01-02 23:37:22 +00:00
# GIVEN: A SongFormat
# WHEN: Retrieving all attributes of a SongFormat
2015-12-30 21:36:37 +00:00
for song_format in SongFormat.get_format_list():
2016-01-02 23:37:22 +00:00
# THEN: All attributes associated with the SongFormat should be returned
self.assertEquals(SongFormat.get(song_format), SongFormat.__attributes__[song_format],
2016-01-09 16:26:14 +00:00
"The returned attributes don't match the stored ones")
2015-12-30 21:36:37 +00:00
def test_get_attributed_single_attribute(self):
2016-01-05 21:35:35 +00:00
"""
Test that SongFormat.get(song_format, attribute) returns only one -and the correct- attribute
"""
2016-01-02 23:37:22 +00:00
# GIVEN: A SongFormat
2015-12-30 21:36:37 +00:00
for song_format in SongFormat.get_format_list():
2016-01-02 23:37:22 +00:00
# WHEN: Retrieving an attribute that overrides the default values
2015-12-30 21:36:37 +00:00
for attribute in SongFormat.get(song_format).keys():
2016-01-02 23:37:22 +00:00
# THEN: Return the attribute
self.assertEquals(SongFormat.get(song_format, attribute), SongFormat.get(song_format)[attribute],
2016-01-09 16:26:14 +00:00
"The returned attribute doesn't match the stored one")
2016-01-02 23:37:22 +00:00
# WHEN: Retrieving an attribute that was not overridden
2015-12-30 21:36:37 +00:00
for attribute in SongFormat.__defaults__.keys():
if attribute not in SongFormat.get(song_format).keys():
2016-01-02 23:37:22 +00:00
# THEN: Return the default value
self.assertEquals(SongFormat.get(song_format, attribute), SongFormat.__defaults__[attribute],
2016-01-09 16:26:14 +00:00
"The returned attribute does not match the default values stored")
2015-12-30 21:36:37 +00:00
def test_get_attributed_multiple_attributes(self):
2016-01-05 21:35:35 +00:00
"""
Test that multiple attributes can be retrieved for a song_format
"""
2016-01-02 23:37:22 +00:00
# GIVEN: A SongFormat
# WHEN: Retrieving multiple attributes at the same time
2015-12-30 21:36:37 +00:00
for song_format in SongFormat.get_format_list():
2016-01-02 23:37:22 +00:00
# THEN: Return all attributes that were specified
self.assertEquals(len(SongFormat.get(song_format, 'canDisable', 'availability')), 2,
2016-01-09 16:26:14 +00:00
"Did not return the correct number of attributes"
" when retrieving multiple attributes at once")
2016-01-09 16:50:08 +00:00
2016-01-10 00:18:27 +00:00
def test_get_format_list_returns_ordered_list(self):
"""
Test that get_format_list() returns a list that is ordered
according to the order specified in SongFormat
"""
2016-01-10 00:34:53 +00:00
# GIVEN: The SongFormat class
# WHEN: Retrieving all formats
# THEN: The returned list should be sorted according to the ordering defined in SongFormat
2016-01-10 00:18:27 +00:00
self.assertEquals(sorted(SongFormat.get_format_list()), SongFormat.get_format_list(),
2016-01-10 00:34:53 +00:00
"The list returned should be sorted according to the ordering in SongFormat")