forked from openlp/openlp
added test
This commit is contained in:
parent
25b1584a9d
commit
51eb93fe75
@ -113,7 +113,9 @@ class AppLocation(object):
|
||||
Defaults to *None*. The section of code getting the files - used to load from a section's data subdirectory.
|
||||
|
||||
``extension``
|
||||
Defaults to *None*. The extension to search for.
|
||||
Defaults to *None*. The extension to search for. For example::
|
||||
|
||||
u'.png'
|
||||
"""
|
||||
path = AppLocation.get_data_path()
|
||||
if section:
|
||||
|
@ -1,12 +1,17 @@
|
||||
"""
|
||||
Functional tests to test the AppLocation class and related methods.
|
||||
"""
|
||||
import copy
|
||||
from unittest import TestCase
|
||||
|
||||
from mock import patch
|
||||
|
||||
from openlp.core.utils import AppLocation
|
||||
|
||||
|
||||
FILE_LIST = [u'file1', u'file2', u'file3.txt', u'file4.txt', u'file5.mp3', u'file6.mp3']
|
||||
|
||||
|
||||
class TestAppLocation(TestCase):
|
||||
"""
|
||||
A test suite to test out various methods around the AppLocation class.
|
||||
@ -51,6 +56,38 @@ class TestAppLocation(TestCase):
|
||||
mocked_settings.value.assert_called_with(u'advanced/data path')
|
||||
assert data_path == u'custom/dir', u'Result should be "custom/dir"'
|
||||
|
||||
def get_files_no_section_no_extension_test(self):
|
||||
"""
|
||||
Test the AppLocation.get_files() method with no parameters passed.
|
||||
"""
|
||||
with patch(u'openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \
|
||||
patch(u'openlp.core.utils.applocation.os.listdir') as mocked_listdir:
|
||||
# GIVEN: Our mocked modules/methods.
|
||||
mocked_get_data_path.return_value = u'test/dir'
|
||||
mocked_listdir.return_value = copy.deepcopy(FILE_LIST)
|
||||
|
||||
# When: Get the list of files.
|
||||
result = AppLocation.get_files()
|
||||
|
||||
# Then: check if the file lists are identically.
|
||||
assert result == FILE_LIST, u'The file lists should be identically.'
|
||||
|
||||
def get_files_test(self):
|
||||
"""
|
||||
Test the AppLocation.get_files() method with all parameters passed.
|
||||
"""
|
||||
with patch(u'openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \
|
||||
patch(u'openlp.core.utils.applocation.os.listdir') as mocked_listdir:
|
||||
# GIVEN: Our mocked modules/methods.
|
||||
mocked_get_data_path.return_value = u'test/dir'
|
||||
mocked_listdir.return_value = copy.deepcopy(FILE_LIST)
|
||||
|
||||
# When: Get the list of files.
|
||||
result = AppLocation.get_files(u'section', u'.mp3')
|
||||
|
||||
# Then: check if the file lists are identically.
|
||||
assert result == [u'file5.mp3', u'file6.mp3'], u'The file lists should be identically.'
|
||||
|
||||
def get_section_data_path_test(self):
|
||||
"""
|
||||
Test the AppLocation.get_section_data_path() method
|
||||
|
Loading…
Reference in New Issue
Block a user