Exemple #1
0
    def test_course_specific_login_and_reg(self, domain):
        """
        Tests that the correct course specific login and registration urls work for shib
        """
        course = CourseFactory.create(
            org='MITx',
            number='999',
            display_name='Robot Super Course',
            user_id=self.test_user_id,
        )

        # Test for cases where course is found
        # set domains

        # temporarily set the branch to draft-preferred so we can update the course
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                       course.id):
            course.enrollment_domain = domain
            self.store.update_item(course, self.test_user_id)

        # setting location to test that GET params get passed through
        login_request = self.request_factory.get(
            '/course_specific_login/MITx/999/Robot_Super_Course' +
            '?course_id=MITx/999/Robot_Super_Course' +
            '&enrollment_action=enroll')
        _reg_request = self.request_factory.get(
            '/course_specific_register/MITx/999/Robot_Super_Course' +
            '?course_id=MITx/999/course/Robot_Super_Course' +
            '&enrollment_action=enroll')

        login_response = course_specific_login(login_request,
                                               'MITx/999/Robot_Super_Course')
        reg_response = course_specific_register(login_request,
                                                'MITx/999/Robot_Super_Course')

        if domain and "shib" in domain:
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(
                login_response['Location'],
                reverse('shib-login') +
                '?course_id=MITx/999/Robot_Super_Course' +
                '&enrollment_action=enroll')
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(
                reg_response['Location'],
                reverse('shib-login') +
                '?course_id=MITx/999/Robot_Super_Course' +
                '&enrollment_action=enroll')
        else:
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(
                login_response['Location'],
                reverse('signin_user') +
                '?course_id=MITx/999/Robot_Super_Course' +
                '&enrollment_action=enroll')
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(
                reg_response['Location'],
                reverse('register_user') +
                '?course_id=MITx/999/Robot_Super_Course' +
                '&enrollment_action=enroll')

        # Now test for non-existent course
        # setting location to test that GET params get passed through
        login_request = self.request_factory.get(
            '/course_specific_login/DNE/DNE/DNE' + '?course_id=DNE/DNE/DNE' +
            '&enrollment_action=enroll')
        _reg_request = self.request_factory.get(
            '/course_specific_register/DNE/DNE/DNE' +
            '?course_id=DNE/DNE/DNE/Robot_Super_Course' +
            '&enrollment_action=enroll')

        login_response = course_specific_login(login_request, 'DNE/DNE/DNE')
        reg_response = course_specific_register(login_request, 'DNE/DNE/DNE')

        self.assertIsInstance(login_response, HttpResponseRedirect)
        self.assertEqual(
            login_response['Location'],
            reverse('signin_user') + '?course_id=DNE/DNE/DNE' +
            '&enrollment_action=enroll')
        self.assertIsInstance(login_response, HttpResponseRedirect)
        self.assertEqual(
            reg_response['Location'],
            reverse('register_user') + '?course_id=DNE/DNE/DNE' +
            '&enrollment_action=enroll')
Exemple #2
0
    def test_course_specific_login_and_reg(self, domain):
        """
        Tests that the correct course specific login and registration urls work for shib
        """
        course = CourseFactory.create(
            org='MITx',
            number='999',
            display_name='Robot Super Course',
            user_id=self.test_user_id,
        )

        # Test for cases where course is found
        # set domains

        # temporarily set the branch to draft-preferred so we can update the course
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, course.id):
            course.enrollment_domain = domain
            self.store.update_item(course, self.test_user_id)

        # setting location to test that GET params get passed through
        login_request = self.request_factory.get('/course_specific_login/MITx/999/Robot_Super_Course' +
                                                 '?course_id=MITx/999/Robot_Super_Course' +
                                                 '&enrollment_action=enroll')
        _reg_request = self.request_factory.get('/course_specific_register/MITx/999/Robot_Super_Course' +
                                                '?course_id=MITx/999/course/Robot_Super_Course' +
                                                '&enrollment_action=enroll')

        login_response = course_specific_login(login_request, 'MITx/999/Robot_Super_Course')
        reg_response = course_specific_register(login_request, 'MITx/999/Robot_Super_Course')

        if domain and "shib" in domain:
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(login_response['Location'],
                             reverse('shib-login') +
                             '?course_id=MITx/999/Robot_Super_Course' +
                             '&enrollment_action=enroll')
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(reg_response['Location'],
                             reverse('shib-login') +
                             '?course_id=MITx/999/Robot_Super_Course' +
                             '&enrollment_action=enroll')
        else:
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(login_response['Location'],
                             reverse('signin_user') +
                             '?course_id=MITx/999/Robot_Super_Course' +
                             '&enrollment_action=enroll')
            self.assertIsInstance(login_response, HttpResponseRedirect)
            self.assertEqual(reg_response['Location'],
                             reverse('register_user') +
                             '?course_id=MITx/999/Robot_Super_Course' +
                             '&enrollment_action=enroll')

        # Now test for non-existent course
        # setting location to test that GET params get passed through
        login_request = self.request_factory.get('/course_specific_login/DNE/DNE/DNE' +
                                                 '?course_id=DNE/DNE/DNE' +
                                                 '&enrollment_action=enroll')
        _reg_request = self.request_factory.get('/course_specific_register/DNE/DNE/DNE' +
                                                '?course_id=DNE/DNE/DNE/Robot_Super_Course' +
                                                '&enrollment_action=enroll')

        login_response = course_specific_login(login_request, 'DNE/DNE/DNE')
        reg_response = course_specific_register(login_request, 'DNE/DNE/DNE')

        self.assertIsInstance(login_response, HttpResponseRedirect)
        self.assertEqual(login_response['Location'],
                         reverse('signin_user') +
                         '?course_id=DNE/DNE/DNE' +
                         '&enrollment_action=enroll')
        self.assertIsInstance(login_response, HttpResponseRedirect)
        self.assertEqual(reg_response['Location'],
                         reverse('register_user') +
                         '?course_id=DNE/DNE/DNE' +
                         '&enrollment_action=enroll')