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

95 lines
4.8 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
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
2015-12-30 21:36:37 +00:00
"""
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
2017-12-22 22:20:04 +00:00
assert len(SongFormat.get_format_list()) == len(SongFormat.__attributes__), \
"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
2017-12-22 22:20:04 +00:00
assert SongFormat.get(song_format) == SongFormat.__attributes__[song_format], \
"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
2017-12-22 22:20:04 +00:00
assert SongFormat.get(song_format, attribute) == SongFormat.get(song_format)[attribute], \
"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
2017-12-22 22:20:04 +00:00
assert SongFormat.get(song_format, attribute) == SongFormat.__defaults__[attribute], \
"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
2017-12-22 22:20:04 +00:00
assert len(SongFormat.get(song_format, 'canDisable', 'availability')) == 2, \
"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
2017-12-22 22:20:04 +00:00
assert sorted(SongFormat.get_format_list()) == SongFormat.get_format_list(), \
"The list returned should be sorted according to the ordering in SongFormat"