def test_show_history_most_recent(self, mock_open, mock_load, mock_get_log, mock_stat): first_validation = mock.MagicMock() second_validation = mock.MagicMock() first_validation.st_mtime = 5 second_validation.st_mtime = 7 validations = { '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json': first_validation, '/tmp/123_bar_2020-03-05T13:17:22.447857Z.json': second_validation } def _generator(x=None): if x: return validations[x] return first_validation mock_stat.side_effect = _generator v_actions = ValidationActions() col, values = v_actions.show_history(history_limit=1) self.assertEqual( col, ('UUID', 'Validations', 'Status', 'Execution at', 'Duration')) self.assertEqual( values, [('008886df-d297-1eaa-2a74-000000000008', '512e', 'PASSED', '2019-11-25T13:40:14.404623Z', '0:00:03.753')])
def test_show_history_all(self, mock_open, mock_load, mock_get_log): v_actions = ValidationActions() col, values = v_actions.show_history() self.assertEqual( col, ('UUID', 'Validations', 'Status', 'Execution at', 'Duration')) self.assertEqual( values, [('008886df-d297-1eaa-2a74-000000000008', '512e', 'PASSED', '2019-11-25T13:40:14.404623Z', '0:00:03.753')])
def take_action(self, parsed_args): if parsed_args.history_limit < 1: raise ValueError( ("Number <n> of the most recent runs must be > 0. " "You have provided {}").format(parsed_args.history_limit)) self.app.LOG.info( ("Limiting output to the maximum of " "{} last validations.").format(parsed_args.history_limit)) actions = ValidationActions(parsed_args.validation_log_dir) return actions.show_history(validation_ids=parsed_args.validation, history_limit=parsed_args.history_limit)
def take_action(self, parsed_args): """Take validation action""" # Get parameters: group = parsed_args.group validation_dir = parsed_args.validation_dir v_actions = ValidationActions(validation_path=validation_dir, group=group) results = v_actions.show_history(validation_name) if results: if parsed_args.output_log: self._write_output(parsed_args.output_log, results) else: self._print_tuple_table(data=results, status_col=2)
def take_action(self, parsed_args): actions = ValidationActions(parsed_args.validation_dir) return actions.show_history(parsed_args.validation)