Finish tests

This commit is contained in:
Phill Ridout 2017-12-18 19:57:13 +00:00
parent f629504b5b
commit 7c39bcda97

View File

@ -38,19 +38,53 @@ class TestHandleMimeDataUrls(TestCase):
"""
Test the :func:`openlp.core.widgets.views.handle_mime_data_urls` function.
"""
# TODO: Finish tests here!!!!!
mocked_path_instance_1 = MagicMock(**{'is_file.return_value': True})
mocked_path_instance_2 = MagicMock(**{'is_file.return_value': True})
with patch('openlp.core.widgets.views.Path',
side_effect=[mocked_path_instance_1, mocked_path_instance_2]) as mocked_path:
mocked_q_url_1 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path', '1.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]})
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_2 = MagicMock(**{'is_file.return_value': True})
with patch('openlp.core.widgets.views.Path',
side_effect=[mocked_path_instance_1, mocked_path_instance_2]) as mocked_path:
mocked_q_url_1 = MagicMock(**{'toLocalFile.return_value': os.path.join('file', 'test', 'path', '1.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]})
# WHEN: Calling handle_mime_data_urls with the mocked 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')),
call(os.path.join('file', 'test', 'path', '2.ext'))])
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]
result = handle_mime_data_urls(mocked_q_mime_data)
mocked_path.assert_has_calls([call(os.path.join('file', 'test', 'path', '1.ext')),
call(os.path.join('file', 'test', 'path', '2.ext'))])
assert result == [mocked_path_instance_1, mocked_path_instance_2]
class TestListPreviewWidget(TestCase):