示例#1
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')
示例#2
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]'
示例#3
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
        ]
示例#4
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')
示例#5
0
 def setUp(self):
     super(UserRoleTestCase, self).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(TestCourseRegistrationCodeStatus, self).setUp()
        CourseModeFactory.create(course_id=self.course.id, min_price=50)
        self.instructor = InstructorFactory(course_key=self.course.id)
        self.client.login(username=self.instructor.username, password='******')
        CourseSalesAdminRole(self.course.id).add_users(self.instructor)

        # create testing invoice
        self.sale_invoice = Invoice.objects.create(
            total_amount=1234.32,
            company_name='Test1',
            company_contact_name='TestName',
            company_contact_email='*****@*****.**',
            recipient_name='Testw',
            recipient_email='*****@*****.**',
            customer_reference_number='2Fwe23S',
            internal_reference="A",
            course_id=self.course.id,
            is_valid=True)
        self.invoice_item = CourseRegistrationCodeInvoiceItem.objects.create(
            invoice=self.sale_invoice,
            qty=1,
            unit_price=1234.32,
            course_id=self.course.id)
        self.lookup_code_url = reverse(
            'look_up_registration_code',
            kwargs={'course_id': text_type(self.course.id)})

        self.registration_code_detail_url = reverse(
            'registration_code_details',
            kwargs={'course_id': text_type(self.course.id)})

        url = reverse('generate_registration_codes',
                      kwargs={'course_id': text_type(self.course.id)})

        data = {
            'total_registration_codes': 12,
            'company_name': 'Test Group',
            'company_contact_name': '*****@*****.**',
            'company_contact_email': '*****@*****.**',
            'unit_price': 122.45,
            'recipient_name': 'Test123',
            'recipient_email': '*****@*****.**',
            'address_line_1': 'Portland Street',
            'address_line_2': '',
            'address_line_3': '',
            'city': '',
            'state': '',
            'zip': '',
            'country': '',
            'customer_reference_number': '123A23F',
            'internal_reference': '',
            'invoice': ''
        }

        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 200, response.content)
示例#7
0
 def setUp(self):
     super(RolesTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     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)
示例#8
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)
示例#9
0
    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 = u"Финансовое программирование и политика, часть 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
        self.assertEqual(len(encoded_unexpected_from_addr), 318)
        # escaping it brings it over that limit
        self.assertEqual(len(escaped_encoded_unexpected_from_addr), 324)
        # when not escaped or encoded, it's well below 320 characters
        self.assertEqual(len(unexpected_from_addr), 137)

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

        self.assertEqual(len(mail.outbox), 1)
        from_email = mail.outbox[0].from_email

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

        self.assertEqual(from_email, expected_from_addr)
        self.assertEqual(len(from_email), 61)
示例#10
0
 def setUp(self):
     super(CohortHandlerTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course_staff_user = StaffFactory(
         username="******",
         course_key=self.course.id
     )
     self.course_instructor_user = InstructorFactory(
         username='******',
         course_key=self.course.id
     )
示例#11
0
文件: test_views.py 项目: saadow123/1
 def setUp(self):
     super(CohortHandlerTestCase, self).setUp()
     self.course_staff_user = StaffFactory(
         username="******",
         course_key=self.course.id
     )
     self.course_instructor_user = InstructorFactory(
         username='******',
         course_key=self.course.id
     )
示例#12
0
 def setUp(self):
     super(AccessTestCase, self).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()
示例#13
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,
     )
示例#14
0
    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)
        ]
示例#15
0
    def setUp(self):
        """Test setup."""
        super(TestWikiAccessMiddleware, self).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'})
        self.course_math101_instructor = InstructorFactory(course_key=self.course_math101.id, username='******', password='******')
        self.wiki_math101 = URLPath.create_article(self.wiki, 'math101', title='math101')

        self.client = Client()
        self.client.login(username='******', password='******')
    def setUp(self):
        super(TestInstructorAPIEnrollmentEmailLocalization, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        # 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')
    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')
示例#18
0
 def setUp(self):
     """
     Fixtures.
     """
     super(TestCourseSaleRecordsAnalyticsBasic, self).setUp()
     self.course = CourseFactory.create()
     self.cost = 40
     self.course_mode = CourseMode(course_id=self.course.id,
                                   mode_slug="honor",
                                   mode_display_name="honor cert",
                                   min_price=self.cost)
     self.course_mode.save()
     self.instructor = InstructorFactory(course_key=self.course.id)
     self.client.login(username=self.instructor.username, password='******')
示例#19
0
 def setUpClass(cls):
     super().setUpClass()
     cls.course_key = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
     cls.other_course_key = CourseKey.from_string(
         'course-v1:edX+ToyX_Other_Course+Toy_Course')
     cls.course = cls.create_course_from_course_key(cls.course_key)
     cls.other_course = cls.create_course_from_course_key(
         cls.other_course_key)
     cls.password = '******'
     cls.student = UserFactory.create(username='******',
                                      password=cls.password)
     cls.global_staff = GlobalStaffFactory(username='******',
                                           password=cls.password)
     cls.course_instructor = InstructorFactory(
         username='******',
         password=cls.password,
         course_key=cls.course.id,
     )
     cls.other_course_instructor = InstructorFactory(
         username='******',
         password=cls.password,
         course_key=cls.other_course.id,
     )
    def setUp(self):
        super(TestViewAuth, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        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)
示例#21
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
         )
示例#22
0
 def setUp(self):
     super(TestAnalyticsBasic, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     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":
             u"edX expert {}".format(user.id),
             "company":
             u"Open edX Inc {}".format(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)
示例#23
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': six.text_type(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
    def setUp(self):
        """Test setup."""
        super(TestComprehensiveTheming, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.wiki = get_or_create_root()

        self.course_math101 = CourseFactory.create(
            org='edx',
            number='math101',
            display_name='2014',
            metadata={'use_unique_wiki_id': 'false'})
        self.course_math101_instructor = InstructorFactory(
            course_key=self.course_math101.id,
            username='******',
            password='******')
        self.wiki_math101 = URLPath.create_article(self.wiki,
                                                   'math101',
                                                   title='math101')

        self.client = Client()
        self.client.login(username='******', password='******')
示例#25
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': six.text_type(self.course.id)})
        response = self.client.post(url, {
            'unique_student_identifier': student.email,
        })
        self.assertEqual(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)
        self.assertEqual(len(course_tab_list), 4)
示例#26
0
    def setUp(self):
        """
        Fixtures.
        """
        super(TestCourseRegistrationCodeAnalyticsBasic, self).setUp()
        self.course = CourseFactory.create()
        self.instructor = InstructorFactory(course_key=self.course.id)
        self.client.login(username=self.instructor.username, password='******')
        CourseSalesAdminRole(self.course.id).add_users(self.instructor)

        # Create a paid course mode.
        mode = CourseModeFactory.create(course_id=self.course.id, min_price=1)

        url = reverse('generate_registration_codes',
                      kwargs={'course_id': text_type(self.course.id)})

        data = {
            'total_registration_codes': 12,
            'company_name': 'Test Group',
            'unit_price': 122.45,
            'company_contact_name': 'TestName',
            'company_contact_email': '*****@*****.**',
            'recipient_name': 'Test123',
            'recipient_email': '*****@*****.**',
            'address_line_1': 'Portland Street',
            'address_line_2': '',
            'address_line_3': '',
            'city': '',
            'state': '',
            'zip': '',
            'country': '',
            'customer_reference_number': '123A23F',
            'internal_reference': '',
            'invoice': ''
        }

        response = self.client.post(url, data, **{'HTTP_HOST': 'localhost'})
        self.assertEqual(response.status_code, 200, response.content)