def test_handle_log_found(self, mock_log): """If a command log is found, save the given output to the log.""" command_log = CommandLogFactory.create() monitor_shove_logs.handle_log_event(command_log.pk, 6, 'asdf') mock_log.assert_called_with('asdf') command_log = CommandLog.objects.get(pk=command_log.pk) # Refresh from DB assert_equal(command_log.return_code, 6)
def test_handle_log_not_found(self, log): """If no log can be found with the given key, log a warning and return.""" monitor_shove_logs.handle_log_event({ 'log_key': 99999999999, 'return_code': 0, 'output': 'asdf' }) assert_true(log.warning.called) assert_equal(CommandLog.objects.count(), 0)
def test_handle_log_key_invalid(self, log): """If the given log key isn't a valid pk, log a warning and return.""" monitor_shove_logs.handle_log_event({ 'log_key': 'not.an.int', 'return_code': 0, 'output': 'asdf' }) assert_true(log.warning.called) assert_equal(CommandLog.objects.count(), 0)
def test_handle_log_event_missing_key(self): """If the log event is missing a required key, log and return.""" with patch('captain.projects.management.commands.monitor_shove_logs.log') as log: monitor_shove_logs.handle_log_event({ 'return_code': 6, 'output': 'asdf' }) assert_true(log.warning.called) assert_equal(CommandLog.objects.count(), 0)