def test_transmit_failure_user_inactive(self, content,
                                         ecu_active_expectation):
     """Learner data transmission fails because the user is inactive on the SAPSF side, so we mark them inactive
     internally."""
     self.create_course_completion_mock.side_effect = RequestException(
         'error occurred',
         response=mock.MagicMock(content=content),
     )
     payload = SapSuccessFactorsLearnerDataTransmissionAudit(
         enterprise_course_enrollment_id=self.enterprise_course_enrollment.
         id,
         sapsf_user_id='sap_user',
         course_id='course-v1:edX+DemoX+DemoCourse',
         course_completed=True,
         completed_timestamp=1486755998,
         instructor_name='Professor Professorson',
         grade='Pass',
     )
     transmitter = learner_data.SapSuccessFactorsLearnerTransmitter(
         self.enterprise_config)
     transmitter.transmit(self.exporter(payload))
     self.create_course_completion_mock.assert_called_with(
         payload.sapsf_user_id, payload.serialize())
     self.enterprise_customer_user.refresh_from_db()
     assert self.enterprise_customer_user.active == ecu_active_expectation
     assert payload.status == '500'
     assert payload.error_message == 'error occurred'
 def test_transmit_failure(self):
     """
     Learner data fails for some reason and the payload is saved with the appropriate data.
     """
     self.create_course_completion_mock.side_effect = RequestException('error occurred')
     payload = SapSuccessFactorsLearnerDataTransmissionAudit(
         enterprise_course_enrollment_id=5,
         sapsf_user_id='sap_user',
         course_id='course-v1:edX+DemoX+DemoCourse',
         course_completed=True,
         completed_timestamp=1486755998,
         instructor_name='Professor Professorson',
         grade='Pass',
     )
     transmitter = learner_data.SapSuccessFactorsLearnerTransmitter(self.enterprise_config)
     transmitter.transmit(self.exporter(payload))
     self.create_course_completion_mock.assert_called_with(payload.sapsf_user_id, payload.serialize())
     assert payload.status == '500'
     assert payload.error_message == 'error occurred'
 def test_transmit_success(self):
     """
     Learner data transmission is successful and the payload is saved with the appropriate data.
     """
     self.create_course_completion_mock.return_value = 200, '{"success":"true"}'
     payload = SapSuccessFactorsLearnerDataTransmissionAudit(
         enterprise_course_enrollment_id=5,
         sapsf_user_id='sap_user',
         course_id='course-v1:edX+DemoX+DemoCourse',
         course_completed=True,
         completed_timestamp=1486755998,
         instructor_name='Professor Professorson',
         grade='Pass',
     )
     transmitter = learner_data.SapSuccessFactorsLearnerTransmitter(self.enterprise_config)
     transmitter.transmit(self.exporter(payload))
     self.create_course_completion_mock.assert_called_with(payload.sapsf_user_id, payload.serialize())
     assert payload.status == '200'
     assert payload.error_message == ''