def test_report_finished_post_files_absent_file(self, mock_report_event): """Absent files provided with post_files result in empty content.""" tmpfname = self.tmp_path('testfile') self.assertFalse(os.path.exists(tmpfname)) events.report_finish_event(self.ev_name, self.ev_desc, post_files=[tmpfname]) event = self._get_reported_event(mock_report_event) files = event.as_dict().get('files') self.assertTrue(len(files) == 1) self.assertEqual(files[0].get('path'), tmpfname) self.assertEqual(files[0].get('encoding'), 'base64') self.assertIsNone(files[0]['content'], 'Unexpected content found for absent post_file.')
def test_report_finished_event_levelset(self, mock_report_event): events.report_finish_event(self.ev_name, self.ev_desc, result=events.status.FAIL) event_dict = self._get_reported_event(mock_report_event).as_dict() self.assertEqual(event_dict.get('level'), 'ERROR') self.assertEqual(event_dict.get('description'), self.ev_desc) events.report_finish_event(self.ev_name, self.ev_desc, result=events.status.WARN) event_dict = self._get_reported_event(mock_report_event).as_dict() self.assertEqual(event_dict.get('level'), 'WARN') self.assertEqual(event_dict.get('description'), self.ev_desc)
def test_report_finished_post_files(self, mock_report_event): test_data = b'abcdefg' tmpfname = self.tmp_path('testfile') with open(tmpfname, 'wb') as fp: fp.write(test_data) events.report_finish_event(self.ev_name, self.ev_desc, post_files=[tmpfname]) event = self._get_reported_event(mock_report_event) files = event.as_dict().get('files') self.assertTrue(len(files) == 1) self.assertEqual(files[0].get('path'), tmpfname) self.assertEqual(files[0].get('encoding'), 'base64') self.assertEqual(files[0].get('content'), base64.b64encode(test_data).decode())
def report_finish_event(self, context, description, result): result = getattr(status, result.name, status.WARN) report_finish_event(context.full_name(), description, result, level=context.level)
def test_report_finish_event(self, mock_report_event): events.report_finish_event(self.ev_name, self.ev_desc) event = self._get_reported_event(mock_report_event) self.assertIsInstance(event, events.FinishReportingEvent) event_dict = event.as_dict() self.assertEqual(event_dict.get('description'), self.ev_desc)
def report_finish_event(self, name, description, result, level): result = getattr(status, result.name, status.WARN) report_finish_event(name, description, result, level=level)