Ejemplo n.º 1
0
    def test_send_course_enrollment_statement(self):
        """
        Verify that send_course_enrollment_statement sends XAPI statement to LRS.
        """
        send_course_enrollment_statement(self.x_api_lrs_config, self.course_enrollment)

        self.x_api_client.lrs.save_statement.assert_called()  # pylint: disable=no-member
Ejemplo n.º 2
0
    def send_xapi_statements(self, lrs_configuration, days):
        """
        Send xAPI analytics data of the enterprise learners to the given LRS.

        Arguments:
            lrs_configuration (XAPILRSConfiguration): Configuration object containing LRS configurations
                of the LRS where to send xAPI  learner analytics.
            days (int): Include course enrollment of this number of days.
        """
        for course_enrollment in self.get_course_enrollments(
                lrs_configuration.enterprise_customer, days):
            error_message = None
            course_id = six.text_type(course_enrollment.course.id)
            try:
                send_course_enrollment_statement(lrs_configuration,
                                                 course_enrollment)
            except ClientError:
                error_message = 'Client error while sending course enrollment to xAPI for ' \
                                'enterprise customer: {enterprise_customer}, user: {username} ' \
                                'and course: {course_id}'.format(
                                    enterprise_customer=lrs_configuration.enterprise_customer.name,
                                    username=course_enrollment.user.username,
                                    course_id=course_id
                                )
                LOGGER.exception(error_message)
                status = 500
            else:
                LOGGER.info(
                    'Successfully send the course enrollment to xAPI for user: {username} for course: '
                    "{course_id}".format(
                        username=course_enrollment.user.username,
                        course_id=course_id))
                status = 200
            xapi_transmission, created = XAPILearnerDataTransmissionAudit.objects.get_or_create(
                user=course_enrollment.user,
                course_id=course_id,
                defaults={
                    'enterprise_course_enrollment_id':
                    EnterpriseCourseEnrollment.
                    get_enterprise_course_enrollment_id(
                        course_enrollment.user, course_id,
                        lrs_configuration.enterprise_customer),
                    'status':
                    status,
                    'error_message':
                    error_message
                })
            if created:
                LOGGER.info(
                    "Successfully created the XAPILearnerDataTransmissionAudit object with id: {id}, user: {username}"
                    " and course: {course_id}".format(
                        id=xapi_transmission.id,
                        username=xapi_transmission.user.username,
                        course_id=xapi_transmission.course_id))
Ejemplo n.º 3
0
    def test_send_course_enrollment_statement(self, mock_catalog_integration,
                                              *args):  # pylint: disable=unused-argument
        """
        Verify that send_course_enrollment_statement sends xAPI statement to LRS.
        """
        mock_integration_config = mock.Mock(enabled=True)
        mock_catalog_integration.current.return_value = mock_integration_config
        send_course_enrollment_statement(self.x_api_lrs_config,
                                         self.course_enrollment)

        self.x_api_client.lrs.save_statement.assert_called()  # pylint: disable=no-member
Ejemplo n.º 4
0
    def test_send_course_enrollment_statement_success(self, mock_get_user_social_auth, mock_xapi_client, *args):  # pylint: disable=unused-argument
        """
        Verify that send_course_enrollment_statement sends xAPI statement to LRS.
        """
        mock_get_user_social_auth.return_value = self.mock_social_auth
        mock_xapi_client.return_value.save_statement.return_value.response.status = 200

        send_course_enrollment_statement(
            self.x_api_lrs_config,
            self.user,
            self.course_overview,
            'course',
            {'status': 500, 'error_messages': None},
        )
Ejemplo n.º 5
0
    def test_send_course_enrollment_statement_client_error(self, mock_get_user_social_auth, mock_xapi_client, *args):  # pylint: disable=unused-argument
        """
        Verify that send_course_enrollment_statement sends xAPI statement to LRS.
        """
        mock_get_user_social_auth.return_value = self.mock_social_auth
        mock_xapi_client.return_value.save_statement.side_effect = ClientError('EnterpriseXAPIClient request failed.')

        send_course_enrollment_statement(
            self.x_api_lrs_config,
            self.user,
            self.course_overview,
            'course',
            {'status': 500, 'error_messages': None},
        )
Ejemplo n.º 6
0
    def test_send_course_enrollment_statement(self, mock_get_user_social_auth, *args):  # pylint: disable=unused-argument
        """
        Verify that send_course_enrollment_statement sends xAPI statement to LRS.
        """
        mock_get_user_social_auth.return_value = self.mock_social_auth

        send_course_enrollment_statement(
            self.x_api_lrs_config,
            self.user,
            self.course_overview,
            'course',
            {'status': 500, 'error_messages': None},
        )

        self.x_api_client.lrs.save_statement.assert_called()  # pylint: disable=no-member
Ejemplo n.º 7
0
    def send_xapi_statements(self, lrs_configuration, days):
        """
        Send xAPI analytics data of the enterprise learners to the given LRS.

        Arguments:
            lrs_configuration (XAPILRSConfiguration): Configuration object containing LRS configurations
                of the LRS where to send xAPI  learner analytics.
            days (int): Include course enrollment of this number of days.
        """
        for course_enrollment in self.get_course_enrollments(lrs_configuration.enterprise_customer, days):
            try:
                send_course_enrollment_statement(lrs_configuration, course_enrollment)
            except ClientError:
                LOGGER.exception(
                    'Client error while sending course enrollment to xAPI for'
                    ' enterprise customer {enterprise_customer}.'.format(
                        enterprise_customer=lrs_configuration.enterprise_customer.name
                    )
                )
    def transmit_enrollment_statement(lrs_configuration, user, course_overview,
                                      object_type):
        """
        Transmits an xAPI enrollment statement for the specified object type.  If successful,
        records a transmission audit record.
        """
        response_fields = {'status': 500, 'error_message': None}
        response_fields = send_course_enrollment_statement(
            lrs_configuration, user, course_overview, object_type,
            response_fields)

        return response_fields