def test_check_failed(self, mock_failed_queue, mock_requeue_job, mock_send_mail): """Test JOB check failed works.""" fq = MagicMock fq.job_ids = ['1'] job = MagicMock() fq.fetch_job = job mock_failed_queue.return_value = fq for i in range(self.flask_app.config.get('FAILED_JOBS_RETRIES') - 1): response = check_failed() msg = "JOBS: ['1'] You have failed the system." assert msg == response, response mock_requeue_job.assert_called_with('1') assert not mock_send_mail.called response = check_failed() assert mock_send_mail.called mock_send_mail.reset_mock() response = check_failed() assert not mock_send_mail.called
def test_check_failed_variant(self, mock_failed_queue, mock_requeue_job, mock_send_mail): """Test JOB check failed works when no failed jobs.""" fq = MagicMock fq.job_ids = [] job = MagicMock() fq.fetch_job = job mock_failed_queue.return_value = fq response = check_failed() msg = "You have not failed the system" assert msg == response, response