def test_send_notification_bad_send(self, m_profile, m_subj, m_body, m_send, m_log_failure, **kwargs):
     """ if notification fails due to send mail helper then command should log state and fail gracefully """
     m_profile.return_value = {'primary_email': '*****@*****.**'}
     m_send.side_effect = Exception('problem with send email helper')
     m_bulk_job = get_mock_bulk_job()
     self.assertFalse(_send_notification(m_bulk_job))
     m_log_failure.assert_called_once_with(m_bulk_job)
 def test_send_notification_all_good(self, m_profile, m_subj, m_body, m_send, **kwargs):
     """ notification for finalized bulk jobs where all subjobs succeeded should reflect that fact """
     m_profile.return_value = {'primary_email': '*****@*****.**'}
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 0
     self.assertTrue(_send_notification(m_bulk_job))
     m_body.assert_called_once_with(ANY, ANY, 1, 0)
 def test_send_notification_mixed_results(self, m_profile, m_subj, m_body, m_send, **kwargs):
     """ notifications for finalized bulk jobs should represent the successes and failures of the subjobs """
     m_profile.return_value = {'primary_email': '*****@*****.**'}
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 2
     self.assertTrue(_send_notification(m_bulk_job))
     m_body.assert_called_once_with(ANY, ANY, 1, 2)
 def test_send_notification_bad_canvas_user(self, m_profile, m_log_failure,
                                            **kwargs):
     """ if notification fails due to Canvas user lookup then command should log state and fail gracefully """
     m_profile.side_effect = Exception(
         'problem getting canvas user profile')
     m_bulk_job = get_mock_bulk_job()
     self.assertFalse(_send_notification(m_bulk_job))
     m_log_failure.assert_called_once_with(m_bulk_job)
 def test_send_notification_bad_send(self, m_profile, m_subj, m_body,
                                     m_send, m_log_failure, **kwargs):
     """ if notification fails due to send mail helper then command should log state and fail gracefully """
     m_profile.return_value = {
         'primary_email': '*****@*****.**'
     }
     m_send.side_effect = Exception('problem with send email helper')
     m_bulk_job = get_mock_bulk_job()
     self.assertFalse(_send_notification(m_bulk_job))
     m_log_failure.assert_called_once_with(m_bulk_job)
 def test_send_notification_mixed_results(self, m_profile, m_subj, m_body,
                                          m_send, **kwargs):
     """ notifications for finalized bulk jobs should represent the successes and failures of the subjobs """
     m_profile.return_value = {
         'primary_email': '*****@*****.**'
     }
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 2
     self.assertTrue(_send_notification(m_bulk_job))
     m_body.assert_called_once_with(ANY, ANY, 1, 2)
 def test_send_notification_all_good(self, m_profile, m_subj, m_body,
                                     m_send, **kwargs):
     """ notification for finalized bulk jobs where all subjobs succeeded should reflect that fact """
     m_profile.return_value = {
         'primary_email': '*****@*****.**'
     }
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 0
     self.assertTrue(_send_notification(m_bulk_job))
     m_body.assert_called_once_with(ANY, ANY, 1, 0)
 def test_send_notification_bad_display_name_lookup(self, m_profile, m_term, m_subj, m_body, m_send, **kwargs):
     """
     If a database call or attribute access fails for Term, School objects,
      default term and school IDs should be the less-display-friendly
      versions in the job record
     """
     m_profile.return_value = {
         'primary_email': '*****@*****.**'
     }
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 1
     m_term.side_effect = Exception('term lookup failed')
     self.assertTrue(_send_notification(m_bulk_job))
     m_subj.assert_called_with(m_bulk_job.school_id, m_bulk_job.sis_term_id)
 def test_send_notification_bad_display_name_lookup(self, m_profile, m_term,
                                                    m_subj, m_body, m_send,
                                                    **kwargs):
     """
     If a database call or attribute access fails for Term, School objects,
      default term and school IDs should be the less-display-friendly
      versions in the job record
     """
     m_profile.return_value = {
         'primary_email': '*****@*****.**'
     }
     m_bulk_job = get_mock_bulk_job()
     m_bulk_job.get_completed_subjobs_count.return_value = 1
     m_bulk_job.get_failed_subjobs_count.return_value = 1
     m_term.side_effect = Exception('term lookup failed')
     self.assertTrue(_send_notification(m_bulk_job))
     m_subj.assert_called_with(m_bulk_job.school_id, m_bulk_job.sis_term_id)
 def test_send_notification_bad_canvas_user(self, m_profile, m_log_failure, **kwargs):
     """ if notification fails due to Canvas user lookup then command should log state and fail gracefully """
     m_profile.side_effect = Exception('problem getting canvas user profile')
     m_bulk_job = get_mock_bulk_job()
     self.assertFalse(_send_notification(m_bulk_job))
     m_log_failure.assert_called_once_with(m_bulk_job)