def test_can_sign_solved_reports(self): e = LibraryEnvError("first", "second", "third") for report in e.args: if report == "second": e.sign_processed(report) self.assertEqual(["first", "third"], e.unprocessed)
def test_report_unprocessed_library_env_errors(self, mock_process_report): report1 = ReportItem.error("OTHER ERROR", info={}) report2 = ReportItem.error("OTHER ERROR", info={}) report3 = ReportItem.error("OTHER ERROR", info={}) e = LibraryEnvError(report1, report2, report3) e.sign_processed(report2) mock_middleware = mock.Mock(side_effect=e) binded = bind(cli_env=None, run_with_middleware=mock_middleware, run_library_command=None) self.assertRaises(SystemExit, lambda: binded(cli_env=None)) mock_process_report.assert_called_once_with([report1, report3])
def test_catch_exactly_his_exception(self): report_missing = self.setup_patch("env_file.report_missing") next_in_line = mock.Mock(side_effect=LibraryEnvError( ReportItem.error(report_codes.FILE_DOES_NOT_EXIST, info={ "file_role": env_file_role_codes.BOOTH_CONFIG, }), ReportItem.error(report_codes.FILE_DOES_NOT_EXIST, info={ "file_role": env_file_role_codes.BOOTH_KEY, }), ReportItem.error("OTHER ERROR", info={}), )) mock_env = mock.MagicMock() self.read.return_value = {"content": None} booth_conf_middleware = env.middleware_config( "booth-name", "/local/file/path.conf", "/local/file/path.key", ) raised_exception = [] def run_middleware(): try: booth_conf_middleware(next_in_line, mock_env) except Exception as e: raised_exception.append(e) raise e self.assertRaises(LibraryEnvError, run_middleware) self.assertEqual(1, len(raised_exception[0].unprocessed)) self.assertEqual("OTHER ERROR", raised_exception[0].unprocessed[0].code) self.assertEqual(report_missing.mock_calls, [ mock.call('Booth config file', '/local/file/path.conf'), mock.call('Booth key file', '/local/file/path.key'), ])
def test_report_unprocessed_library_env_errors(self, mock_process_report): report1 = ReportItem.error("OTHER ERROR", "", info={}) report2 = ReportItem.error("OTHER ERROR", "", info={}) report3 = ReportItem.error("OTHER ERROR", "", info={}) e = LibraryEnvError(report1, report2, report3) e.sign_processed(report2) mock_middleware = mock.Mock(side_effect=e) binded = bind( cli_env=None, run_with_middleware=mock_middleware, run_library_command=None ) self.assertRaises(SystemExit, lambda: binded(cli_env=None)) mock_process_report.assert_called_once_with([report1, report3])
def read(self): if self.__content is None: raise LibraryEnvError( reports.file_does_not_exist(self.__file_role) ) return self.__content
def test_catch_exactly_his_exception(self, mock_is_file, mock_console_report): next_in_line = mock.Mock(side_effect=LibraryEnvError( ReportItem.error(report_codes.FILE_DOES_NOT_EXIST, info={ "file_role": env_file_role_codes.BOOTH_CONFIG, }), ReportItem.error(report_codes.FILE_DOES_NOT_EXIST, info={ "file_role": env_file_role_codes.BOOTH_KEY, }), ReportItem.error("OTHER ERROR", info={}), )) mock_is_file.return_value = False mock_env = mock.MagicMock() #run tested code booth_conf_middleware = middleware_config( "booth-name", "/local/file/path.conf", "/local/file/path.key", ) raised_exception = [] def run_middleware(): try: booth_conf_middleware(next_in_line, mock_env) except Exception as e: raised_exception.append(e) raise e self.assertRaises(LibraryEnvError, run_middleware) self.assertEqual(1, len(raised_exception[0].unprocessed)) self.assertEqual("OTHER ERROR", raised_exception[0].unprocessed[0].code) self.assertEqual(mock_console_report.error.mock_calls, [ mock.call( "Booth config file '/local/file/path.conf' does not exist"), mock.call("Booth key file '/local/file/path.key' does not exist"), ])