Ejemplo n.º 1
0
    def test_transmit_single_learner_data_performs_only_one_transmission(self):
        """
        Test sending single user's data should only update one `CornerstoneLearnerDataTransmissionAudit` entry
        """
        course_id = 'course-v1:edX+NmX+Demo_Course_2'
        course_key = 'edX+NmX'
        self._setup_enterprise_enrollment(self.user, course_id, course_key)

        # Course API course_details response
        responses.add(responses.GET,
                      urljoin(lms_api.CourseApiClient.API_BASE_URL,
                              "courses/{course}/".format(course=course_id)),
                      json={
                          "course_id": course_key,
                          "pacing": "instructor",
                          "end": "2038-06-21T12:58:17.428373Z",
                      })

        # Enrollment API
        responses.add(responses.GET,
                      urljoin(
                          lms_api.EnrollmentApiClient.API_BASE_URL,
                          "enrollment/{username},{course_id}".format(
                              username=self.user.username,
                              course_id=course_id),
                      ),
                      json=dict(mode='verified'))

        # Certificates API user's grade response
        responses.add(
            responses.GET,
            urljoin(
                lms_api.CertificatesApiClient.API_BASE_URL,
                "certificates/{user}/courses/{course}/".format(
                    course=course_id, user=self.user.username)),
            json={
                "is_passing": "true",
                "created_date": "2019-06-21T12:58:17.428373Z",
                "grade": "0.8"
            },
        )

        responses.add(
            responses.POST,
            re.compile('{base_url}{callback}{completion_path}'.format(
                base_url=self.config.cornerstone_base_url,
                callback=self.callback_url,
                completion_path=self.global_config.completion_status_api_path)
                       ),
            json={})

        transmissions = CornerstoneLearnerDataTransmissionAudit.objects.filter(
            user=self.user, course_completed=False)
        # assert we have two uncompleted data transmission
        self.assertEqual(transmissions.count(), 2)
        transmit_single_learner_data(self.user.username, course_id)
        # assert we have now one uncompleted data transmission
        self.assertEqual(transmissions.count(), 1)
Ejemplo n.º 2
0
 def test_transmit_single_learner_data(self, mock_learner_exporter):
     """
     The transmit_single_learner_data is called and passes kwargs to underlying transmitter.
     """
     kwargs = {
         'learner_to_transmit': self.user,
         'course_run_id': self.demo_course_run_id,
         'completed_date': NOW,
         'grade': 'Pass',
         'is_passing': True,
     }
     mock_learner_exporter.return_value = 'mock_learner_exporter'
     with mock.patch(
         'integrated_channels.cornerstone.models.CornerstoneEnterpriseCustomerConfiguration'
         '.get_learner_data_transmitter'
     ) as mock_transmitter:
         transmit_single_learner_data(self.user.username, self.demo_course_run_id)
         mock_transmitter.return_value.transmit.assert_called_once_with('mock_learner_exporter', **kwargs)
    def test_transmit_single_learner_data_performs_only_one_transmission(self):
        """
        Test sending single user's data sould only update one `CornerstoneLearnerDataTransmissionAudit` entry
        """
        course_id = 'course-v1:edX+NmX+Demo_Course_2'
        course_key = 'edX+NmX'
        self._setup_enterprise_enrollment(self.user, course_id, course_key)

        # Course API course_details response
        responses.add(responses.GET,
                      urljoin(lms_api.CourseApiClient.API_BASE_URL,
                              "courses/{course}/".format(course=course_id)),
                      json={
                          "course_id": course_key,
                          "pacing": "instructor",
                          "end": "2038-06-21T12:58:17.428373Z",
                      })

        # Certificates API user's grade response
        responses.add(
            responses.GET,
            urljoin(
                lms_api.CertificatesApiClient.API_BASE_URL,
                "certificates/{user}/courses/{course}/".format(
                    course=course_id, user=self.user.username)),
            json={
                "is_passing": "true",
                "created_date": "2019-06-21T12:58:17.428373Z",
                "grade": "0.8"
            },
        )

        transmissions = CornerstoneLearnerDataTransmissionAudit.objects.filter(
            user=self.user, course_completed=False)
        # assert we have two uncompleted data transmission
        self.assertEqual(transmissions.count(), 2)
        transmit_single_learner_data(self.user.username, course_id)
        # assert we have now one uncompleted data transmission
        self.assertEqual(transmissions.count(), 1)