Exemple #1
0
 def setUp(self):
     email = '*****@*****.**'
     course_id = 'course-v1:edX+DemoX+DemoCourse'
     pending_link = PendingEnterpriseCustomerUserFactory(user_email=email)
     self.enrollment = PendingEnrollmentFactory(user=pending_link, course_id=course_id)
     self.user = UserFactory(email=email)
     super(TestPendingEnrollment, self).setUp()
Exemple #2
0
class TestPendingEnrollment(unittest.TestCase):
    """
    Test for pending enrollment
    """
    def setUp(self):
        email = '*****@*****.**'
        course_id = 'course-v1:edX+DemoX+DemoCourse'
        pending_link = PendingEnterpriseCustomerUserFactory(user_email=email)
        self.enrollment = PendingEnrollmentFactory(user=pending_link, course_id=course_id)
        self.user = UserFactory(email=email)
        super(TestPendingEnrollment, self).setUp()

    @ddt.data(
        str, repr
    )
    def test_string_conversion(self, method):
        """
        Test conversion to string.
        """
        expected_str = '<PendingEnrollment for email [email protected] in course with ID course-v1:edX+DemoX+DemoCourse>'
        assert expected_str == method(self.enrollment)

    @mock.patch('enterprise.lms_api.CourseKey')
    @mock.patch('enterprise.lms_api.CourseEnrollment')
    def test_complete_enrollment(self, mock_course_enrollment, mock_course_key):
        mock_course_key.from_string.return_value = None
        mock_course_enrollment.enroll.return_value = None
        self.enrollment.complete_enrollment()  # pylint: disable=no-member
        mock_course_enrollment.enroll.assert_called_once_with(self.user, None, mode='audit', check_access=True)
        mock_course_key.from_string.assert_called_once_with(self.enrollment.course_id)
Exemple #3
0
    def test_handle_user_post_save_with_pending_course_enrollment(
            self, mock_course_enrollment, mock_course_key):
        mock_course_key.from_string.return_value = None
        mock_course_enrollment.enroll.return_value = None
        email = "*****@*****.**"
        user = UserFactory(id=1, email=email)
        pending_link = PendingEnterpriseCustomerUserFactory(user_email=email)
        pending_enrollment = PendingEnrollmentFactory(user=pending_link)

        assert len(EnterpriseCustomerUser.objects.filter(
            user_id=user.id)) == 0, "Precondition check: no links exists"
        assert len(PendingEnterpriseCustomerUser.objects.filter(user_email=email)) == 1, \
            "Precondition check: pending link exists"
        assert len(PendingEnrollment.objects.filter(
            user=pending_link)) == 1, 'Check that only one enrollment exists.'

        parameters = {'instance': user, "created": False}
        handle_user_post_save(mock.Mock(), **parameters)
        assert len(PendingEnterpriseCustomerUser.objects.all()) == 0
        assert len(
            EnterpriseCustomerUser.objects.filter(
                enterprise_customer=pending_link.enterprise_customer,
                user_id=user.id)) == 1
        assert len(PendingEnrollment.objects.all()) == 0
        assert len(EnterpriseCourseEnrollment.objects.all()) == 1
        mock_course_enrollment.enroll.assert_called_once_with(
            user, None, mode='audit', check_access=True)
        mock_course_key.from_string.assert_called_once_with(
            pending_enrollment.course_id)
Exemple #4
0
    def test_handle_user_post_save_with_pending_course_enrollment(self, mock_course_enrollment, mock_track_enrollment):
        mock_course_enrollment.enroll.return_value = None
        email = "*****@*****.**"
        user = UserFactory(id=1, email=email)
        pending_link = PendingEnterpriseCustomerUserFactory(user_email=email)
        course_id = 'course-v1:edX+DemoX+Demo_Course'
        PendingEnrollmentFactory(user=pending_link, course_id=course_id)

        assert EnterpriseCustomerUser.objects.filter(user_id=user.id).count() == 0, "Precondition check: no links exist"
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=email).count() == 1, \
            "Precondition check: pending link exists"
        assert PendingEnrollment.objects.filter(user=pending_link).count() == 1, \
            'Precondition check: only one enrollment exists.'

        parameters = {'instance': user, "created": False}
        handle_user_post_save(mock.Mock(), **parameters)
        assert PendingEnterpriseCustomerUser.objects.count() == 0
        assert EnterpriseCustomerUser.objects.filter(
            enterprise_customer=pending_link.enterprise_customer, user_id=user.id
        ).count() == 1
        assert PendingEnrollment.objects.count() == 0
        assert EnterpriseCourseEnrollment.objects.count() == 1
        mock_course_enrollment.enroll.assert_called_once_with(
            user, CourseKey.from_string(course_id), mode='audit', check_access=True
        )
        mock_track_enrollment.assert_called_once_with('pending-admin-enrollment', user.id, course_id)
    def test_handle_user_post_save_with_pending_course_enrollment(
            self,
            mock_course_enrollment,
            mock_track_enrollment,
            mock_track_event  # pylint: disable=unused-argument
    ):
        mock_course_enrollment.enroll.return_value = None
        email = "*****@*****.**"
        user = UserFactory(id=1, email=email)
        pending_link = PendingEnterpriseCustomerUserFactory(user_email=email)
        pending_link.enterprise_customer.enable_autocohorting = True
        pending_link.enterprise_customer.save()
        course_id = 'course-v1:edX+DemoX+Demo_Course'
        PendingEnrollmentFactory(user=pending_link,
                                 course_id=course_id,
                                 cohort_name=u'test_cohort')

        assert EnterpriseCustomerUser.objects.filter(
            user_id=user.id).count() == 0, "Precondition check: no links exist"
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=email).count() == 1, \
            "Precondition check: pending link exists"
        assert PendingEnrollment.objects.filter(user=pending_link).count() == 1, \
            'Precondition check: only one enrollment exists.'

        mock_course_enrollment.return_value = mock.Mock(
            get_course_enrollment=mock.Mock(
                side_effect=[None, {
                    'is_active': False,
                    'mode': 'verified'
                }]),
            enroll_user_in_course=mock.Mock())
        parameters = {'instance': user, "created": False}
        with transaction.atomic():
            handle_user_post_save(mock.Mock(), **parameters)
        assert PendingEnterpriseCustomerUser.objects.count() == 0
        assert EnterpriseCustomerUser.objects.filter(
            enterprise_customer=pending_link.enterprise_customer,
            user_id=user.id).count() == 1
        assert PendingEnrollment.objects.count() == 0
        assert EnterpriseCourseEnrollment.objects.count() == 1
        mock_course_enrollment.return_value.enroll_user_in_course.assert_called_once_with(
            user.username, course_id, 'audit', cohort=u'test_cohort')
        mock_track_enrollment.assert_called_once_with(
            'pending-admin-enrollment', user.id, course_id)