tests: add `assert_ ` prefix to a bunch of asserts missing it

This commit is contained in:
Joel Beckmeyer 2024-02-01 17:33:45 -05:00
parent ed7561bded
commit eef6ae8863
6 changed files with 34 additions and 30 deletions

View File

@ -62,7 +62,7 @@ class ThemeListWidgetItem(QtWidgets.QListWidgetItem):
thumbnail = sample_theme_data['thumbnail']
self.file_name = sample_theme_data['file_name']
self.sha256 = sample_theme_data['sha256']
self.setIcon(UiIcons().picture) # Set a place holder icon whilst the thumbnails download
self.setIcon(UiIcons().get_icon_variant('picture')) # Set a place holder icon whilst the thumbnails download
self.setText(title)
self.setToolTip(title)
worker = DownloadWorker(themes_url, thumbnail)
@ -78,7 +78,7 @@ class ThemeListWidgetItem(QtWidgets.QListWidgetItem):
:rtype: None
"""
self.setIcon(UiIcons().exception)
self.setIcon(UiIcons().get_icon_variant('exception'))
def _on_thumbnail_downloaded(self, thumbnail_path):
"""

View File

@ -161,7 +161,7 @@ def test_save(mocked_information, api_tab, registry, settings):
# THEN: The text should have been changed to the default value
mocked_information.assert_called_once_with(api_tab, 'Restart Required',
'This change will only take effect once OpenLP has been restarted.')
mocked_settings_form.register_post_process.called_once_with('remotes_config_updated')
mocked_settings_form.register_post_process.assert_called_once_with('remotes_config_updated')
assert settings.value('api/twelve hour') is True
assert settings.value('api/thumbnails') is True
assert settings.value('api/authentication enabled') is True

View File

@ -73,7 +73,7 @@ def test_local_send_command_network_error(mock_log, mock_reset, mock_state, mock
mock_log.error.assert_has_calls(log_error_calls)
mock_log.warning.assert_has_calls(log_warning_calls)
mock_log.debug.assert_has_calls(log_debug_calls)
mock_change_status.called_with(E_NETWORK, 'Error while sending data to projector')
mock_change_status.assert_called_with(E_NETWORK, 'Error while sending data to projector')
assert not pjlink.send_queue, 'Send queue should be empty'
assert not pjlink.priority_queue, 'Priority queue should be empty'
assert mock_timer.start.called, 'Timer should have been called'
@ -421,7 +421,7 @@ def test_send_command_add_normal_command(mock_log, mock_send_command, mock_reset
pjlink.send_command(cmd='CLSS')
# THEN:
mock_send.append.called_with(test_command)
mock_send.append.assert_called_with(test_command)
mock_priority.append.called is False
mock_log.debug.assert_has_calls(log_debug_calls)
mock_log.warning.assert_has_calls(log_warning_calls)

View File

@ -25,7 +25,7 @@ from unittest.mock import MagicMock, call, patch
import openlp.core.projectors.pjlink
from openlp.core.projectors.pjlinkcommands import process_command
from openlp.core.projectors.constants import E_NOT_CONNECTED, E_PARAMETER, E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, \
from openlp.core.projectors.constants import E_NOT_CONNECTED, E_UNKNOWN_SOCKET_ERROR, QSOCKET_STATE, \
S_CONNECTED, S_CONNECTING, S_OK, S_ON, STATUS_CODE, STATUS_MSG
@ -38,11 +38,8 @@ def test_status_change(mock_changeStatus, pjlink):
# WHEN: process_command is called with "ERR2" status from projector
process_command(projector=pjlink, cmd='POWR', data='ERR2')
# THEN: change_status should have called change_status with E_UNDEFINED
# as first parameter
mock_changeStatus.called_with(E_PARAMETER,
'change_status should have been called '
'with "{}"'.format(STATUS_CODE[E_PARAMETER]))
# THEN: change_status should not have been called
mock_changeStatus.assert_not_called()
@patch.object(openlp.core.projectors.pjlink.PJLink, 'disconnect_from_host')

View File

@ -70,7 +70,7 @@ def test_setup(mocked_register_views: MagicMock, media_env: MediaController):
# THEN: the functions should be defined along with the api blueprint
assert list(Registry().functions_list.keys()) == expected_functions_list, \
f'The function list should have been {(Registry().functions_list.keys())}'
mocked_register_views.called_once(), 'The media blueprint has not been registered'
mocked_register_views.assert_called_once(), 'The media blueprint has not been registered'
def test_initialise_good(media_env: MediaController, state_media: State):
@ -82,7 +82,7 @@ def test_initialise_good(media_env: MediaController, state_media: State):
# THEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
def test_initialise_missing_vlc(media_env: MediaController, state_media: State):
@ -95,7 +95,7 @@ def test_initialise_missing_vlc(media_env: MediaController, state_media: State):
# THEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
text = State().get_text()
if not is_macosx():
assert text.find("python3-vlc") > 0, "VLC should not be missing"
@ -111,7 +111,7 @@ def test_initialise_missing_pymedia(media_env: MediaController, state_media: Sta
# THEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
text = State().get_text()
if not is_macosx():
assert text.find("python3-pymediainfo") > 0, "PyMedia should not be missing"
@ -129,7 +129,7 @@ def test_initialise_missing_pymedia_fedora(media_env: MediaController, state_med
# WHEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
text = State().get_text()
assert text.find("python3-pymediainfo") == -1, "PyMedia should be missing"
assert text.find("python3-vlc") > 0, "VLC should not be missing"
@ -148,7 +148,7 @@ def test_initialise_missing_pymedia_not_fedora(media_env: MediaController, state
# WHEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
text = State().get_text()
assert text.find("python3-pymediainfo") == -1, "PyMedia should be missing"
assert text.find("python3-vlc") > 0, "VLC should not be missing"
@ -166,7 +166,7 @@ def test_initialise_missing_pymedia_mac_os(media_env: MediaController, state_med
# WHEN: The underlying method is called
media_env.media_controller.bootstrap_initialise()
# THEN: The following should have happened
mocked_setup.called_once(), 'The setup function has been called'
mocked_setup.assert_called_once(), 'The setup function has been called'
text = State().get_text()
assert text.find("python3-pymediainfo") == -1, "PyMedia should be missing"
assert text.find("python3-vlc") == -1, "PyMedia should be missing"
@ -178,8 +178,10 @@ def test_post_set_up_good(media_env: MediaController, state_media: State, regist
Test the Bootstrap post set up assuming all functions are good
"""
# GIVEN: A working environment
registry.register('live_controller', MagicMock())
registry.register('preview_controller', MagicMock())
mocked_live_controller = MagicMock()
registry.register('live_controller', mocked_live_controller)
mocked_preview_controller = MagicMock()
registry.register('preview_controller', mocked_preview_controller)
media_env.vlc_live_media_stop = MagicMock()
media_env.vlc_preview_media_stop = MagicMock()
media_env.vlc_live_media_tick = MagicMock()
@ -193,8 +195,8 @@ def test_post_set_up_good(media_env: MediaController, state_media: State, regist
assert mocked_display.call_count == 2, "Should have been called twice"
text = State().get_text()
assert text.find("No Displays") == -1, "No Displays have been disable"
assert mocked_display.has_calls(None, False) # Live Controller
assert mocked_display.has_calls(None, True) # Preview Controller
mocked_display.assert_any_call(mocked_live_controller, False) # Live Controller
mocked_display.assert_any_call(mocked_preview_controller, True) # Preview Controller
def test_media_state_live(media_env: MediaController, state_media: State):
@ -209,16 +211,20 @@ def test_media_state_live(media_env: MediaController, state_media: State):
mocked_live_controller.is_live = True
mocked_live_controller.media_info.media_type = MediaType.Audio
Registry().register('live_controller', mocked_live_controller)
mocked_preview_controller = MagicMock()
Registry().register('preview_controller', mocked_preview_controller)
media_env.media_controller.vlc_player = MagicMock()
media_env.media_controller._display_controllers = MagicMock(return_value=mocked_live_controller)
State().add_service("mediacontroller", 0)
State().update_pre_conditions("mediacontroller", True)
# WHEN: I call the function
with patch.object(media_env.media_controller, u'setup_display') as mocked_display:
media_env.bootstrap_post_set_up()
# THEN: the environment is set up correctly
text = State().get_text()
assert text.find("No Displays") == -1, "No Displays have been disable"
assert mocked_display.has_calls(None, False) # Live Controller
assert mocked_display.has_calls(None, True) # Preview Controller
mocked_display.assert_any_call(mocked_live_controller, False) # Live Controller
mocked_display.assert_any_call(mocked_preview_controller, True) # Preview Controller
def test_post_set_up_no_controller(media_env: MediaController, state_media: State):

View File

@ -77,7 +77,7 @@ def mocked_set_icon(mock_settings):
q_thread_patcher.stop()
def test_init_sample_data(download_env):
def test_init_sample_data(download_env, mock_settings):
"""
Test that the theme data is loaded correctly in to a ThemeListWidgetItem object when instantiated
"""
@ -94,7 +94,7 @@ def test_init_sample_data(download_env):
mocked_download_worker.assert_called_once_with('url', 'BlueBurst.png')
def test_init_download_worker(download_env):
def test_init_download_worker(download_env, mock_settings):
"""
Test that the `DownloadWorker` worker is set up correctly and that the thread is started.
"""
@ -109,8 +109,8 @@ def test_init_download_worker(download_env):
# THEN: The `DownloadWorker` should have been set up with the appropriate data
mocked_download_worker.assert_called_once_with('url', 'BlueBurst.png')
mocked_download_worker.download_failed.connect.called_once_with(instance._on_download_failed())
mocked_download_worker.download_succeeded.connect.called_once_with(instance._on_thumbnail_downloaded)
mocked_download_worker().download_failed.connect.assert_called_once_with(instance._on_download_failed)
mocked_download_worker().download_succeeded.connect.assert_called_once_with(instance._on_thumbnail_downloaded)
mocked_run_thread.assert_called_once_with(mocked_download_worker(), 'thumbnail_download_BlueBurst.png')
assert mocked_ftw.thumbnail_download_threads == ['thumbnail_download_BlueBurst.png']
@ -461,7 +461,8 @@ def test_failed_download(mocked_set_icon):
worker.download_failed.emit()
# THEN: Then the initial loading icon should have been replaced by the exception icon
mocked_set_icon.assert_has_calls([call(UiIcons().picture), call(UiIcons().exception)])
mocked_set_icon.assert_has_calls([call(UiIcons().get_icon_variant('picture')),
call(UiIcons().get_icon_variant('exception'))])
@patch('openlp.core.ui.firsttimeform.build_icon')
@ -481,7 +482,7 @@ def test_successful_download(mocked_build_icon, mocked_set_icon):
# THEN: An icon should have been built from the downloaded file and used to replace the loading icon
mocked_build_icon.assert_called_once_with(test_path)
mocked_set_icon.assert_has_calls([call(UiIcons().picture), call(mocked_build_icon())])
mocked_set_icon.assert_has_calls([call(UiIcons().get_icon_variant('picture')), call(mocked_build_icon())])
@patch.object(FirstTimeForm, 'provide_help')