def test_confirm_operations(self, _error, _info, _confirm, tqdm, _position_after_bars): with thespiae.cli.CLI('thespiae') as ui: ui.feedback.confirm_operations([DownloadSpec(name='test')], [AppEntry(name='test2')], [AppEntry(name='test3')]) _info.assert_called() _error.assert_not_called() _confirm.assert_called_once() tqdm.assert_not_called() _position_after_bars.assert_not_called()
def test_report_entry_download_progress(self, _error, _info, _confirm, tqdm, _position_after_bars): with thespiae.cli.CLI('thespiae') as ui: ui.feedback.confirm_operations([DownloadSpec(name='test')], [AppEntry(name='test2')], [AppEntry(name='test3')]) ui.feedback.report_entry_download_initiated(DownloadSpec(name='test')) ui.feedback.report_entry_download_progress(DownloadSpec(name='test'), 10) _info.assert_called() _error.assert_not_called() _confirm.assert_called_once() tqdm.assert_called_once() tqdm.return_value.update.assert_called_once_with(10) _position_after_bars.assert_not_called()
def test_report_entry_download_started(self, _error, _info, _confirm, tqdm, _position_after_bars): with thespiae.cli.CLI('thespiae') as ui: ui.feedback.confirm_operations([DownloadSpec(name='test')], [AppEntry(name='test2')], [AppEntry(name='test3')]) ui.feedback.report_entry_download_initiated(DownloadSpec(name='test')) ui.feedback.report_entry_download_started(DownloadSpec(name='test'), 5, 15) _info.assert_called() _error.assert_not_called() _confirm.assert_called_once() tqdm.assert_called_once() self.assertEqual(tqdm.return_value.total, 15) self.assertEqual(tqdm.return_value.n, 5) tqdm.return_value.refresh.assert_called_once() _position_after_bars.assert_not_called()
def test_processing5(self): fb = NonCallableMock(spec_set=Feedback) set_download_manager_data(set()) data = AppData([AppEntry(name='test', uninstaller_path='C:\\uninst.exe', keep=True)]) with self.assertRaises(UnknownInstallTypeError) as c: software_processor.process('C:\\temp', data, fb) self.assertEqual(c.exception.app_entry, data.to_install[0])
def test_processing4(self): fb = NonCallableMock(spec_set=Feedback) set_download_manager_data(set()) data = AppData([AppEntry(name='test', installer_url='http://example.com/file.exe')]) with self.assertRaises(UnknownUninstallTypeError) as c: software_processor.process('C:\\temp', data, fb) self.assertEqual(c.exception.app_entry, data.to_uninstall[0])
def test_report_entry_installation_finished(self, _error, _info, _confirm, tqdm, _position_after_bars): with thespiae.cli.CLI('thespiae') as ui: ui.feedback.report_entry_installation_finished(AppEntry(name='test2')) _info.assert_called() _error.assert_not_called() _confirm.assert_not_called() tqdm.assert_not_called() _position_after_bars.assert_not_called()
from unittest import TestCase from unittest.mock import call, NonCallableMock from thespiae.conf import AppData, AppEntry from thespiae.conf.core import get_app_config_from from thespiae.install.exception import InvalidOrMissingAppDataError, InterruptedFileOperationsError, \ UnknownInstallTypeError, UnknownUninstallTypeError from thespiae.install.protocol import Feedback from .helper import set_install_manager_data, InstallManagerMockResetMixin, DownloadManagerMockResetMixin, \ ExtraAssertMixin, set_download_manager_data from .singleton import exe_install_handler, msi_install_handler, command_install_handler, install_manager, \ software_processor, download_manager, exe_uninstall_handler, msi_uninstall_handler, command_uninstall_handler, \ file_install_handler, file_uninstall_handler, archive_install_handler, archive_uninstall_handler from ..conf.helper import load_yaml_from_test_dir _exe_entry1 = AppEntry(name='test', installer_url='http://example.com/123.exe', file_hash='4567', version='890', uninstaller_path='123.exe', install_args=['a'], uninstall_args=['b']) class ExeInstallHandlerTest(InstallManagerMockResetMixin, TestCase): def test_applicability(self): self.assertTrue(exe_install_handler.is_applicable(_exe_entry1)) def test_applicability2(self): self.assertFalse(exe_install_handler.is_applicable(replace(_exe_entry1, installer_url=None))) def test_creating_download_spec(self): spec = exe_install_handler.create_download_spec(_exe_entry1, 'C:\\') self.assertEqual(spec.url, 'http://example.com/123.exe') self.assertEqual(spec.download_path, 'C:\\test\\890\\test_890.exe') self.assertEqual(spec.hash, '4567')