Beispiel #1
0
    def setUp(self):
        super(CourseOverviewAccessTestCase, self).setUp()

        today = datetime.datetime.now(pytz.UTC)
        last_week = today - datetime.timedelta(days=7)
        next_week = today + datetime.timedelta(days=7)

        self.course_default = CourseFactory.create()
        self.course_started = CourseFactory.create(start=last_week)
        self.course_not_started = CourseFactory.create(start=next_week,
                                                       days_early_for_beta=10)
        self.course_staff_only = CourseFactory.create(
            visible_to_staff_only=True)
        self.course_mobile_available = CourseFactory.create(
            mobile_available=True)
        self.course_with_pre_requisite = CourseFactory.create(
            pre_requisite_courses=[str(self.course_started.id)])
        self.course_with_pre_requisites = CourseFactory.create(
            pre_requisite_courses=[
                str(self.course_started.id),
                str(self.course_not_started.id)
            ])

        self.user_normal = UserFactory.create()
        self.user_beta_tester = BetaTesterFactory.create(
            course_key=self.course_not_started.id)
        self.user_completed_pre_requisite = UserFactory.create()
        fulfill_course_milestone(self.course_started.id,
                                 self.user_completed_pre_requisite)
        self.user_staff = UserFactory.create(is_staff=True)
        self.user_anonymous = AnonymousUserFactory.create()
Beispiel #2
0
    def test_instructor_tab(self):
        """
        Verify that the instructor tab appears for staff only.
        """
        def has_instructor_tab(user, course):
            """Returns true if the "Instructor" tab is shown."""
            tabs = get_course_tab_list(user, course)
            return len([tab for tab in tabs if tab.name == 'Instructor']) == 1

        assert has_instructor_tab(self.instructor, self.course)

        staff = StaffFactory(course_key=self.course.id)
        assert has_instructor_tab(staff, self.course)

        student = UserFactory.create()
        assert not has_instructor_tab(student, self.course)

        researcher = UserFactory.create()
        CourseAccessRoleFactory(
            course_id=self.course.id,
            user=researcher,
            role='data_researcher',
            org=self.course.id.org
        )
        assert has_instructor_tab(researcher, self.course)

        org_researcher = UserFactory.create()
        CourseAccessRoleFactory(
            course_id=None,
            user=org_researcher,
            role='data_researcher',
            org=self.course.id.org
        )
        assert has_instructor_tab(org_researcher, self.course)
Beispiel #3
0
    def setUp(self):
        super().setUp()

        self.initialize_course()
        self.student = UserFactory.create(username="******",
                                          email="*****@*****.**")
        self.instructor = UserFactory.create(username="******",
                                             email="*****@*****.**")
Beispiel #4
0
    def test_access_on_course_with_pre_requisites(self):
        """
        Test course access when a course has pre-requisite course yet to be completed
        """
        user = UserFactory.create()

        pre_requisite_course = CourseFactory.create(org='test_org',
                                                    number='788',
                                                    run='test_run')

        pre_requisite_courses = [six.text_type(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='test_org',
            number='786',
            run='test_run',
            pre_requisite_courses=pre_requisite_courses)
        set_prerequisite_courses(course.id, pre_requisite_courses)

        # user should not be able to load course even if enrolled
        CourseEnrollmentFactory(user=user, course_id=course.id)
        response = access._has_access_course(user, 'load', course)
        self.assertFalse(response)
        self.assertIsInstance(response, access_response.MilestoneAccessError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(staff, 'load', course))

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        self.assertTrue(access._has_access_course(user, 'load', course))
Beispiel #5
0
    def test_courseware_page_unfulfilled_prereqs(self):
        """
        Test courseware access when a course has pre-requisite course yet to be completed
        """
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='900',
            run='test_run',
        )

        pre_requisite_courses = [six.text_type(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='edX',
            course='1000',
            run='test_run',
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        test_password = '******'
        user = UserFactory.create()
        user.set_password(test_password)
        user.save()
        self.login(user.email, test_password)
        CourseEnrollmentFactory(user=user, course_id=course.id)

        url = reverse('courseware', args=[six.text_type(course.id)])
        response = self.client.get(url)
        self.assertRedirects(response, reverse('dashboard'))
        self.assertEqual(response.status_code, 302)

        fulfill_course_milestone(pre_requisite_course.id, user)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Beispiel #6
0
    def test__catalog_visibility(self):
        """
        Tests the catalog visibility tri-states
        """
        user = UserFactory.create()
        course_id = CourseLocator('edX', 'test', '2012_Fall')
        staff = StaffFactory.create(course_key=course_id)

        course = Mock(id=course_id,
                      catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT)
        assert access._has_access_course(user, 'see_in_catalog', course)
        assert access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)

        # Now set visibility to just about page
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_ABOUT)
        assert not access._has_access_course(user, 'see_in_catalog', course)
        assert access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)

        # Now set visibility to none, which means neither in catalog nor about pages
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_NONE)
        assert not access._has_access_course(user, 'see_in_catalog', course)
        assert not access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)
Beispiel #7
0
 def setUp(self):
     """
     Creating pre-requisites for the test cases.
     """
     super(TestUserStateService, self).setUp()
     self.user = UserFactory.create()
     self.course = CourseFactory.create()
     chapter = ItemFactory.create(
         category='chapter',
         parent=self.course,
         display_name='Test Chapter'
     )
     sequential = ItemFactory.create(
         category='sequential',
         parent=chapter,
         display_name='Test Sequential'
     )
     vertical = ItemFactory.create(
         category='vertical',
         parent=sequential,
         display_name='Test Vertical'
     )
     self.problem = ItemFactory.create(
         category='problem',
         parent=vertical,
         display_name='Test Problem'
     )
Beispiel #8
0
    def setUp(self):
        freezer = freeze_time(self.now)
        freezer.start()
        self.addCleanup(freezer.stop)

        super(CourseProgressApiViewTest, self).setUp()

        self.student = UserFactory(password=USER_PASSWORD)
        self.instructor_user = InstructorFactory(course_key=self.course.id,
                                                 password=USER_PASSWORD)
        self.staff_user = UserFactory(password=USER_PASSWORD, is_staff=True)

        self.enrollment = CourseEnrollmentFactory.create(
            user=self.student, course_id=self.course.id)

        self.namespaced_url = 'navoica_api:v1:progress:detail'

        # create a configuration for django-oauth-toolkit (DOT)
        dot_app_user = UserFactory.create(password=USER_PASSWORD)
        dot_app = dot_models.Application.objects.create(
            name='test app',
            user=dot_app_user,
            client_type='confidential',
            authorization_grant_type='authorization-code',
            redirect_uris='http://localhost:8079/complete/edxorg/')
        self.dot_access_token = dot_models.AccessToken.objects.create(
            user=self.student,
            application=dot_app,
            expires=datetime.utcnow() + timedelta(weeks=1),
            scope='read write',
            token='16MGyP3OaQYHmpT1lK7Q6MMNAZsjwF')
Beispiel #9
0
    def test_total_credit_cart_sales_amount(self):
        """
        Test to check the total amount for all the credit card purchases.
        """
        student = UserFactory.create()
        self.client.login(username=student.username, password="******")
        student_cart = Order.get_cart_for_user(student)
        item = self.add_course_to_user_cart(student_cart, self.course.id)
        resp = self.client.post(reverse('shoppingcart.views.update_user_cart'),
                                {
                                    'ItemId': item.id,
                                    'qty': 4
                                })
        self.assertEqual(resp.status_code, 200)
        student_cart.purchase()

        self.client.login(username=self.instructor.username, password="******")
        CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
        single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(
            self.course.id)
        bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(
            self.course.id)
        total_amount = single_purchase_total + bulk_purchase_total
        response = self.client.get(self.url)
        self.assertContains(
            response, '{currency}{amount}'.format(currency='$',
                                                  amount=total_amount))
Beispiel #10
0
    def test__has_access_course_can_enroll(self):
        yesterday = datetime.datetime.now(
            pytz.utc) - datetime.timedelta(days=1)
        tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)

        # Non-staff can enroll if authenticated and specifically allowed for that course
        # even outside the open enrollment period
        user = UserFactory.create()
        course = Mock(enrollment_start=tomorrow,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='')
        CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Staff can always enroll even outside the open enrollment period
        user = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Non-staff cannot enroll if it is between the start and end dates and invitation only
        # and not specifically allowed
        course = Mock(enrollment_start=yesterday,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=True)
        user = UserFactory.create()
        self.assertFalse(access._has_access_course(user, 'enroll', course))

        # Non-staff can enroll if it is between the start and end dates and not invitation only
        course = Mock(enrollment_start=yesterday,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=False)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Non-staff cannot enroll outside the open enrollment period if not specifically allowed
        course = Mock(enrollment_start=tomorrow,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=False)
        self.assertFalse(access._has_access_course(user, 'enroll', course))
Beispiel #11
0
 def test_spoc_gradebook_pages(self):
     for i in range(2):
         username = "******" % i
         student = UserFactory.create(username=username)
         CourseEnrollmentFactory.create(user=student,
                                        course_id=self.course.id)
     url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id})
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     # Max number of student per page is one.  Patched setting MAX_STUDENTS_PER_PAGE_GRADE_BOOK = 1
     self.assertEqual(len(response.mako_context['students']), 1)
Beispiel #12
0
    def setUp(self):
        freezer = freeze_time(self.now)
        freezer.start()
        self.addCleanup(freezer.stop)

        super(CertificatesListViewTest, self).setUp()

        self.student = UserFactory(password=USER_PASSWORD)
        self.instructor = InstructorFactory(course_key=self.course.id,
                                            password=USER_PASSWORD)
        self.second_instructor = InstructorFactory(
            course_key=self.second_course.id, password=USER_PASSWORD)
        self.staff_user = UserFactory(password=USER_PASSWORD, is_staff=True)

        self.enrollment = CourseEnrollmentFactory.create(
            user=self.student, course_id=self.course.id)

        self.second_enrollment = CourseEnrollmentFactory.create(
            user=self.student, course_id=self.second_course.id)

        self.certificate = GeneratedCertificateFactory(
            user=self.student,
            course_id=self.course.id,
            download_url=self.DOWNLOAD_URL,
            status=CertificateStatuses.downloadable,
            created_date=self.CREATED_DATE,
            grade=0.98,
        )

        self.second_certificate = GeneratedCertificateFactory(
            user=self.student,
            course_id=self.second_course.id,
            download_url=self.DOWNLOAD_URL,
            status=CertificateStatuses.downloadable,
            created_date=self.CREATED_DATE,
            grade=0.95,
        )

        self.namespaced_url = 'navoica_api:v1:certificates:list'

        # create a configuration for django-oauth-toolkit (DOT)
        dot_app_user = UserFactory.create(password=USER_PASSWORD)
        dot_app = dot_models.Application.objects.create(
            name='test app',
            user=dot_app_user,
            client_type='confidential',
            authorization_grant_type='authorization-code',
            redirect_uris='http://localhost:8079/complete/edxorg/')
        self.dot_access_token = dot_models.AccessToken.objects.create(
            user=self.staff_user,
            application=dot_app,
            expires=datetime.utcnow() + timedelta(weeks=1),
            scope='read write',
            token='16MGyP3OaQYHmpT1lK7Q6MMNAZsjwF')
Beispiel #13
0
 def setUp(self):
     super(MobileAPITestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course = CourseFactory.create(
         mobile_available=True,
         static_asset_path="needed_for_split",
         end=datetime.datetime.now(pytz.UTC),
         certificate_available_date=datetime.datetime.now(pytz.UTC))
     self.user = UserFactory.create()
     self.password = '******'
     self.username = self.user.username
     self.api_version = API_V1
     IgnoreMobileAvailableFlagConfig(enabled=False).save()
Beispiel #14
0
    def test_other_user(self):
        # login and enroll as the test user
        self.login_and_enroll()
        self.logout()

        # login and enroll as another user
        other = UserFactory.create()
        self.client.login(username=other.username, password='******')
        self.enroll()
        self.logout()

        # now login and call the API as the test user
        self.login()
        self.api_response(expected_response_code=403, username=other.username)
Beispiel #15
0
 def setUp(self):
     super(MobileAPITestCase, self).setUp()
     self.course = CourseFactory.create(
         mobile_available=True,
         static_asset_path="needed_for_split",
         # Custom change: course end date is set to a future date to fulfill custom added feature flag
         # ALLOW_STUDENT_STATE_UPDATES_ON_CLOSED_COURSE
         end=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=1),
         certificate_available_date=datetime.datetime.now(pytz.UTC)
     )
     self.user = UserFactory.create()
     self.password = '******'
     self.username = self.user.username
     self.api_version = API_V1
     IgnoreMobileAvailableFlagConfig(enabled=False).save()
 def test_data_download_only(self):
     """
     Verify that only the data download tab is visible for data researchers.
     """
     user = UserFactory.create()
     CourseAccessRoleFactory(course_id=self.course.id,
                             user=user,
                             role='data_researcher',
                             org=self.course.id.org)
     self.client.login(username=user.username, password="******")
     response = self.client.get(self.url)
     matches = re.findall(
         rb'<li class="nav-item"><button type="button" class="btn-link .*" data-section=".*">.*',
         response.content)
     assert len(matches) == 1
Beispiel #17
0
    def test_instructor_tab(self):
        """
        Verify that the instructor tab appears for staff only.
        """
        def has_instructor_tab(user, course):
            """Returns true if the "Instructor" tab is shown."""
            tabs = get_course_tab_list(user, course)
            return len([tab for tab in tabs if tab.name == 'Instructor']) == 1

        self.assertTrue(has_instructor_tab(self.instructor, self.course))

        staff = StaffFactory(course_key=self.course.id)
        self.assertTrue(has_instructor_tab(staff, self.course))

        student = UserFactory.create()
        self.assertFalse(has_instructor_tab(student, self.course))
 def test_data_download(self, access_role, can_access):
     """
     Verify that the Data Download tab only shows up for certain roles
     """
     download_section = '<li class="nav-item"><button type="button" class="btn-link data_download" '\
                        'data-section="data_download">Data Download</button></li>'
     user = UserFactory.create(is_staff=access_role == 'global_staff')
     CourseAccessRoleFactory(course_id=self.course.id,
                             user=user,
                             role=access_role,
                             org=self.course.id.org)
     self.client.login(username=user.username, password="******")
     response = self.client.get(self.url)
     if can_access:
         self.assertContains(response, download_section)
     else:
         self.assertNotContains(response, download_section)
Beispiel #19
0
    def setUp(self):
        super(InstructorTaskModuleSubmitTest, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.initialize_course()
        self.student = UserFactory.create(username="******", email="*****@*****.**")
        self.instructor = UserFactory.create(username="******", email="*****@*****.**")
Beispiel #20
0
    def test_spoc_gradebook_mongo_calls(self):
        """
        Test that the MongoDB cache is used in API to return grades
        """
        # prepare course structure
        course = ItemFactory.create(
            parent_location=self.course.location,
            category="course",
            display_name="Test course",
        )

        students = []
        for i in range(20):
            username = "******" % i
            student = UserFactory.create(username=username)
            CourseEnrollmentFactory.create(user=student,
                                           course_id=self.course.id)
            students.append(student)

        chapter = ItemFactory.create(
            parent=course,
            category='chapter',
            display_name="Chapter",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
        )
        sequential = ItemFactory.create(
            parent=chapter,
            category='sequential',
            display_name="Lesson",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
            metadata={
                'graded': True,
                'format': 'Homework'
            },
        )
        vertical = ItemFactory.create(
            parent=sequential,
            category='vertical',
            display_name='Subsection',
            publish_item=True,
            start=datetime.datetime(2015, 4, 1, tzinfo=UTC),
        )
        for i in range(10):
            problem = ItemFactory.create(
                category="problem",
                parent=vertical,
                display_name=u"A Problem Block %d" % i,
                weight=1,
                publish_item=False,
                metadata={'rerandomize': 'always'},
            )
            for j in students:
                grade = i % 2
                StudentModuleFactory.create(grade=grade,
                                            max_grade=1,
                                            student=j,
                                            course_id=self.course.id,
                                            module_state_key=problem.location)

        # check MongoDB calls count
        url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id})
        with check_mongo_calls(9):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)