コード例 #1
0
    def test_is_user_staff_or_instructor(self):
        """
        Verify the correct value is returned for users with different access levels.
        """
        course_id_string = str(self.course.id)
        global_staff_user = GlobalStaffFactory.create()
        staff_user = StaffFactory.create(course_key=self.course_run_key)
        instructor = InstructorFactory.create(course_key=self.course_run_key)

        different_course = CourseFactory.create()
        instructor_different_course = InstructorFactory.create(
            course_key=different_course.id)

        assert is_user_staff_or_instructor_in_course(instructor,
                                                     course_id_string)
        assert is_user_staff_or_instructor_in_course(global_staff_user,
                                                     self.course_run_key)
        assert is_user_staff_or_instructor_in_course(staff_user,
                                                     self.course_run_key)
        assert is_user_staff_or_instructor_in_course(instructor,
                                                     self.course_run_key)
        assert not is_user_staff_or_instructor_in_course(
            self.user, self.course_run_key)
        assert not is_user_staff_or_instructor_in_course(
            instructor_different_course, self.course_run_key)
コード例 #2
0
 def setUp(self):
     super().setUp()
     self.course1 = CourseFactory()
     self.course2 = CourseFactory()
     self.global_staff = GlobalStaffFactory(username="******")
     self.instructor_course1 = InstructorFactory.create(
         course_key=self.course1.id, username="******")
     self.instructor_course2 = InstructorFactory.create(
         course_key=self.course2.id, username="******")
     self.staff = StaffFactory.create(course_key=self.course1.id,
                                      username="******")
     self.user = UserFactory(username="******")
コード例 #3
0
 def setUp(self):
     super().setUp()
     self.course = CourseFactory.create()
     self.instructor = InstructorFactory(course_key=self.course.id)
     self.target = [BulkEmailTargetChoices.SEND_TO_MYSELF]
     self.subject = "email subject"
     self.html_message = "<p>test message</p>"
コード例 #4
0
ファイル: django_utils.py プロジェクト: uetuluk/edx-platform
    def create_user_for_course(self,
                               course,
                               user_type=CourseUserType.ENROLLED):
        """
        Create a test user for a course.
        """
        if user_type is CourseUserType.ANONYMOUS:
            self.client.logout()
            return AnonymousUser()

        is_enrolled = user_type is CourseUserType.ENROLLED

        # Set up the test user
        if user_type is CourseUserType.UNENROLLED_STAFF:
            user = StaffFactory(course_key=course.id,
                                password=self.TEST_PASSWORD)
        elif user_type is CourseUserType.GLOBAL_STAFF:
            user = AdminFactory(password=self.TEST_PASSWORD)
        elif user_type is CourseUserType.COURSE_INSTRUCTOR:
            user = InstructorFactory(course_key=course.id,
                                     password=self.TEST_PASSWORD)
        else:
            user = UserFactory(password=self.TEST_PASSWORD)

        self.client.login(username=user.username, password=self.TEST_PASSWORD)

        if is_enrolled:
            CourseEnrollment.enroll(user, course.id)

        return user
コード例 #5
0
 def setUp(self):
     super().setUp()
     self.course_key = CourseLocator('edX', 'toy', '2012_Fall')
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course_key)
コード例 #6
0
 def setUp(self):
     super().setUp()
     self.course_key = CourseKey.from_string('edX/toy/2012_Fall')
     self.course_loc = self.course_key.make_usage_key('course', '2012_Fall')
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course_key)
コード例 #7
0
    def create_staff_for_course(self, course):
        """Creates and returns users with instructor and staff access to course."""

        return [
            InstructorFactory(course_key=course.id
                              ),  # Creates instructor_org/number/run role name
            StaffFactory(course_key=course.id
                         ),  # Creates staff_org/number/run role name
        ]
コード例 #8
0
ファイル: test_email.py プロジェクト: uetuluk/edx-platform
    def test_long_course_display_name(self):
        """
        This test tests that courses with exorbitantly large display names
        can still send emails, since it appears that 320 appears to be the
        character length limit of from emails for Amazon SES.
        """
        test_email = {
            'action': 'Send email',
            'send_to': '["myself", "staff", "learners"]',
            'subject': 'test subject for self',
            'message': 'test message for self'
        }

        # make display_name that's longer than 320 characters when encoded
        # to ascii and escaped, but shorter than 320 unicode characters
        long_name = "Финансовое программирование и политика, часть 1: макроэкономические счета и анализ"

        course = CourseFactory.create(
            display_name=long_name,
            org="IMF",
            number="FPP.1x",
            run="2016",
        )
        instructor = InstructorFactory(course_key=course.id)

        unexpected_from_addr = _get_source_address(course.id,
                                                   course.display_name,
                                                   course_language=None,
                                                   truncate=False)
        __, encoded_unexpected_from_addr = forbid_multi_line_headers(
            "from", unexpected_from_addr, 'utf-8')
        escaped_encoded_unexpected_from_addr = escape(
            encoded_unexpected_from_addr)

        # it's shorter than 320 characters when just encoded
        assert len(encoded_unexpected_from_addr) == 318
        # escaping it brings it over that limit
        assert len(escaped_encoded_unexpected_from_addr) == 324
        # when not escaped or encoded, it's well below 320 characters
        assert len(unexpected_from_addr) == 137

        self.login_as_user(instructor)
        send_mail_url = reverse('send_email',
                                kwargs={'course_id': str(course.id)})
        response = self.client.post(send_mail_url, test_email)
        assert json.loads(response.content.decode('utf-8'))['success']

        assert len(mail.outbox) == 1
        from_email = mail.outbox[0].from_email

        expected_from_addr = (
            '"{course_name}" Course Staff <{course_name}[email protected]>'
        ).format(course_name=course.id.course)

        assert from_email == expected_from_addr
        assert len(from_email) == 61
コード例 #9
0
 def setUp(self):
     super().setUp()
     self.course_key = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
     self.other_course_key = CourseKey.from_string('course-v1:edX+ToyX_Other_Course+Toy_Course')
     self.course = self.create_course_from_course_key(self.course_key)
     self.other_course = self.create_course_from_course_key(self.other_course_key)
     self.password = '******'
     self.student = UserFactory.create(username='******', password=self.password)
     self.global_staff = GlobalStaffFactory(username='******', password=self.password)
     self.course_instructor = InstructorFactory(
         username='******',
         password=self.password,
         course_key=self.course.id,
     )
     self.other_course_instructor = InstructorFactory(
         username='******',
         password=self.password,
         course_key=self.other_course.id,
     )
コード例 #10
0
ファイル: test_access.py プロジェクト: uetuluk/edx-platform
 def setUp(self):
     super().setUp()
     self.course = CourseFactory.create(org='edX', course='toy', run='test_run')
     self.anonymous_user = AnonymousUserFactory()
     self.beta_user = BetaTesterFactory(course_key=self.course.id)
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course.id)
     self.course_instructor = InstructorFactory(course_key=self.course.id)
     self.staff = GlobalStaffFactory()
    def setUp(self):
        super().setUp()

        # Platform language is English, instructor's language is Chinese,
        # student's language is Esperanto, so the emails should all be sent in
        # Esperanto.
        self.instructor = InstructorFactory(course_key=self.course.id)
        set_user_preference(self.instructor, LANGUAGE_KEY, 'zh-cn')
        self.client.login(username=self.instructor.username, password='******')

        self.student = UserFactory.create()
        set_user_preference(self.student, LANGUAGE_KEY, 'eo')
コード例 #12
0
ファイル: test_email.py プロジェクト: uetuluk/edx-platform
    def create_staff_and_instructor(self):
        """
        Creates one instructor and several course staff for self.course. Assigns
        them to self.instructor (single user) and self.staff (list of users),
        respectively.
        """
        self.instructor = InstructorFactory(course_key=self.course.id)

        self.staff = [
            StaffFactory(course_key=self.course.id)
            for __ in range(STAFF_COUNT)
        ]
コード例 #13
0
    def setUp(self):
        """Test setup."""
        super().setUp()

        self.wiki = get_or_create_root()

        self.course_math101 = CourseFactory.create(org='edx', number='math101', display_name='2014', metadata={'use_unique_wiki_id': 'false'})  # lint-amnesty, pylint: disable=line-too-long
        self.course_math101_instructor = InstructorFactory(course_key=self.course_math101.id, username='******', password='******')  # lint-amnesty, pylint: disable=line-too-long
        self.wiki_math101 = URLPath.create_article(self.wiki, 'math101', title='math101')

        self.client = Client()
        self.client.login(username='******', password='******')
コード例 #14
0
    def setUp(self):
        super().setUp()

        self.course = CourseFactory.create(number='999',
                                           display_name='Robot_Super_Course')
        self.courseware_chapter = ItemFactory.create(display_name='courseware')
        self.overview_chapter = ItemFactory.create(
            parent_location=self.course.location,
            display_name='Super Overview')
        self.welcome_section = ItemFactory.create(
            parent_location=self.overview_chapter.location,
            display_name='Super Welcome')
        self.welcome_unit = ItemFactory.create(
            parent_location=self.welcome_section.location,
            display_name='Super Unit')
        self.course = modulestore().get_course(self.course.id)

        self.test_course = CourseFactory.create(org=self.course.id.org)
        self.other_org_course = CourseFactory.create(org='Other_Org_Course')
        self.sub_courseware_chapter = ItemFactory.create(
            parent_location=self.test_course.location,
            display_name='courseware')
        self.sub_overview_chapter = ItemFactory.create(
            parent_location=self.sub_courseware_chapter.location,
            display_name='Overview')
        self.sub_welcome_section = ItemFactory.create(
            parent_location=self.sub_overview_chapter.location,
            display_name='Welcome')
        self.sub_welcome_unit = ItemFactory.create(
            parent_location=self.sub_welcome_section.location,
            display_name='New Unit')
        self.test_course = modulestore().get_course(self.test_course.id)

        self.global_staff_user = GlobalStaffFactory()
        self.unenrolled_user = UserFactory(last_name="Unenrolled")

        self.enrolled_user = UserFactory(last_name="Enrolled")
        CourseEnrollmentFactory(user=self.enrolled_user,
                                course_id=self.course.id)
        CourseEnrollmentFactory(user=self.enrolled_user,
                                course_id=self.test_course.id)

        self.staff_user = StaffFactory(course_key=self.course.id)
        self.instructor_user = InstructorFactory(course_key=self.course.id)
        self.org_staff_user = OrgStaffFactory(course_key=self.course.id)
        self.org_instructor_user = OrgInstructorFactory(
            course_key=self.course.id)
コード例 #15
0
    def test_enrolled_students_features_keys_cohorted(self):
        course = CourseFactory.create(org="test",
                                      course="course1",
                                      display_name="run1")
        course.cohort_config = {
            'cohorted': True,
            'auto_cohort': True,
            'auto_cohort_groups': ['cohort']
        }
        self.store.update_item(course, self.instructor.id)
        cohorted_students = [UserFactory.create() for _ in range(10)]
        cohort = CohortFactory.create(name='cohort',
                                      course_id=course.id,
                                      users=cohorted_students)
        cohorted_usernames = [
            student.username for student in cohorted_students
        ]
        non_cohorted_student = UserFactory.create()
        for student in cohorted_students:
            cohort.users.add(student)
            CourseEnrollment.enroll(student, course.id)
        CourseEnrollment.enroll(non_cohorted_student, course.id)
        instructor = InstructorFactory(course_key=course.id)
        self.client.login(username=instructor.username, password='******')

        query_features = ('username', 'cohort')
        # There should be a constant of 2 SQL queries when calling
        # enrolled_students_features.  The first query comes from the call to
        # User.objects.filter(...), and the second comes from
        # prefetch_related('course_groups').
        with self.assertNumQueries(2):
            userreports = enrolled_students_features(course.id, query_features)
        assert len([
            r for r in userreports if r['username'] in cohorted_usernames
        ]) == len(cohorted_students)
        assert len([
            r for r in userreports
            if r['username'] == non_cohorted_student.username
        ]) == 1
        for report in userreports:
            assert set(report.keys()) == set(query_features)
            if report['username'] in cohorted_usernames:
                assert report['cohort'] == cohort.name
            else:
                assert report['cohort'] == '[unassigned]'
コード例 #16
0
 def setUp(self):
     super().setUp()
     self.course_key = self.store.make_course_key('robot', 'course', 'id')
     self.users = tuple(UserFactory() for _ in range(30))
     self.ces = tuple(
         CourseEnrollment.enroll(user, self.course_key)
         for user in self.users)
     self.instructor = InstructorFactory(course_key=self.course_key)
     for user in self.users:
         user.profile.meta = json.dumps({
             "position":
             f"edX expert {user.id}",
             "company":
             f"Open edX Inc {user.id}",
         })
         user.profile.save()
     self.students_who_may_enroll = list(
         self.users) + [UserFactory() for _ in range(5)]
     for student in self.students_who_may_enroll:
         CourseEnrollmentAllowed.objects.create(email=student.email,
                                                course_id=self.course_key)
コード例 #17
0
    def test_skip_entrance_exam_gating(self):
        """
        Tests gating is disabled if skip entrance exam is set for a user.
        """
        # make sure toc is locked before allowing user to skip entrance exam
        locked_toc = self._return_table_of_contents()
        for toc_section in self.expected_locked_toc:
            assert toc_section in locked_toc

        # hit skip entrance exam api in instructor app
        instructor = InstructorFactory(course_key=self.course.id)
        self.client.login(username=instructor.username, password='******')
        url = reverse('mark_student_can_skip_entrance_exam', kwargs={'course_id': str(self.course.id)})
        response = self.client.post(url, {
            'unique_student_identifier': self.request.user.email,
        })
        assert response.status_code == 200

        unlocked_toc = self._return_table_of_contents()
        for toc_section in self.expected_unlocked_toc:
            assert toc_section in unlocked_toc
コード例 #18
0
    def test_get_course_tabs_list_skipped_entrance_exam(self):
        """
        Tests tab list is not limited if user is allowed to skip entrance exam.
        """
        #create a user
        student = UserFactory()
        # login as instructor hit skip entrance exam api in instructor app
        instructor = InstructorFactory(course_key=self.course.id)
        self.client.logout()
        self.client.login(username=instructor.username, password='******')

        url = reverse('mark_student_can_skip_entrance_exam', kwargs={'course_id': str(self.course.id)})
        response = self.client.post(url, {
            'unique_student_identifier': student.email,
        })
        assert response.status_code == 200

        # log in again as student
        self.client.logout()
        self.login(self.email, self.password)
        course_tab_list = get_course_tab_list(self.user, self.course)
        assert len(course_tab_list) == 4