forked from openlp/openlp
Finish tests
This commit is contained in:
parent
f629504b5b
commit
7c39bcda97
@ -38,7 +38,11 @@ class TestHandleMimeDataUrls(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test the :func:`openlp.core.widgets.views.handle_mime_data_urls` function.
|
Test the :func:`openlp.core.widgets.views.handle_mime_data_urls` function.
|
||||||
"""
|
"""
|
||||||
# TODO: Finish tests here!!!!!
|
def test_files(self):
|
||||||
|
"""
|
||||||
|
Test handle_mime_data_urls when the data points to some files.
|
||||||
|
"""
|
||||||
|
# GIVEN: Some mocked objects that return True when is_file is called, and some mocked mime data
|
||||||
mocked_path_instance_1 = MagicMock(**{'is_file.return_value': True})
|
mocked_path_instance_1 = MagicMock(**{'is_file.return_value': True})
|
||||||
mocked_path_instance_2 = MagicMock(**{'is_file.return_value': True})
|
mocked_path_instance_2 = MagicMock(**{'is_file.return_value': True})
|
||||||
with patch('openlp.core.widgets.views.Path',
|
with patch('openlp.core.widgets.views.Path',
|
||||||
@ -47,11 +51,41 @@ class TestHandleMimeDataUrls(TestCase):
|
|||||||
mocked_q_url_2 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path', '2.ext')})
|
mocked_q_url_2 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path', '2.ext')})
|
||||||
mocked_q_mime_data = MagicMock(**{'urls.return_value': [mocked_q_url_1, mocked_q_url_2]})
|
mocked_q_mime_data = MagicMock(**{'urls.return_value': [mocked_q_url_1, mocked_q_url_2]})
|
||||||
|
|
||||||
|
# WHEN: Calling handle_mime_data_urls with the mocked mime data
|
||||||
result = handle_mime_data_urls(mocked_q_mime_data)
|
result = handle_mime_data_urls(mocked_q_mime_data)
|
||||||
|
|
||||||
|
# THEN: Both mocked Path objects should be returned in the list
|
||||||
mocked_path.assert_has_calls([call(os.path.join('file', 'test', 'path', '1.ext')),
|
mocked_path.assert_has_calls([call(os.path.join('file', 'test', 'path', '1.ext')),
|
||||||
call(os.path.join('file', 'test', 'path', '2.ext'))])
|
call(os.path.join('file', 'test', 'path', '2.ext'))])
|
||||||
assert result == [mocked_path_instance_1, mocked_path_instance_2]
|
assert result == [mocked_path_instance_1, mocked_path_instance_2]
|
||||||
|
|
||||||
|
def test_directory(self):
|
||||||
|
"""
|
||||||
|
Test handle_mime_data_urls when the data points to some directories.
|
||||||
|
"""
|
||||||
|
# GIVEN: Some mocked objects that return True when is_dir is called, and some mocked mime data
|
||||||
|
mocked_path_instance_1 = MagicMock()
|
||||||
|
mocked_path_instance_2 = MagicMock()
|
||||||
|
mocked_path_instance_3 = MagicMock()
|
||||||
|
mocked_path_instance_4 = MagicMock(**{'is_file.return_value': False, 'is_directory.return_value': True,
|
||||||
|
'iterdir.return_value': [mocked_path_instance_1, mocked_path_instance_2]})
|
||||||
|
mocked_path_instance_5 = MagicMock(**{'is_file.return_value': False, 'is_directory.return_value': True,
|
||||||
|
'iterdir.return_value': [mocked_path_instance_3]})
|
||||||
|
with patch('openlp.core.widgets.views.Path',
|
||||||
|
side_effect=[mocked_path_instance_4, mocked_path_instance_5]) as mocked_path:
|
||||||
|
mocked_q_url_1 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path')})
|
||||||
|
mocked_q_url_2 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path')})
|
||||||
|
mocked_q_mime_data = MagicMock(**{'urls.return_value': [mocked_q_url_1, mocked_q_url_2]})
|
||||||
|
|
||||||
|
# WHEN: Calling handle_mime_data_urls with the mocked mime data
|
||||||
|
result = handle_mime_data_urls(mocked_q_mime_data)
|
||||||
|
|
||||||
|
# THEN: The three mocked Path file objects should be returned in the list
|
||||||
|
mocked_path.assert_has_calls([call(os.path.join('file', 'test', 'path')),
|
||||||
|
call(os.path.join('file', 'test', 'path'))])
|
||||||
|
assert result == [mocked_path_instance_1, mocked_path_instance_2, mocked_path_instance_3]
|
||||||
|
|
||||||
|
|
||||||
class TestListPreviewWidget(TestCase):
|
class TestListPreviewWidget(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user