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')
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)
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)
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)
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()
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')
def test_compose_calendar_sync_email(self, is_update): """ Tests that attributes of the message are being filled correctly in compose_activation_email """ user = UserFactory() course_overview = CourseOverviewFactory() course_name = course_overview.display_name if is_update: calendar_sync_subject = 'Updates for Your {course} Schedule'.format(course=course_name) calendar_sync_headline = 'Update Your Calendar' calendar_sync_body = ('Your assignment due dates for {course} were recently adjusted. Update your calendar' 'with your new schedule to ensure that you stay on track!').format(course=course_name) else: calendar_sync_subject = 'Stay on Track' calendar_sync_headline = 'Mark Your Calendar' calendar_sync_body = ( 'Sticking to a schedule is the best way to ensure that you successfully complete your ' 'self-paced course. This schedule of assignment due dates for {course} will help you ' 'stay on track!'.format(course=course_name)) msg = compose_calendar_sync_email(user, course_overview, is_update) self.assertEqual(msg.context['calendar_sync_subject'], calendar_sync_subject) self.assertEqual(msg.context['calendar_sync_headline'], calendar_sync_headline) self.assertEqual(msg.context['calendar_sync_body'], calendar_sync_body) self.assertEqual(msg.recipient.username, user.username) self.assertEqual(msg.recipient.email_address, user.email)
def test_group_name_case_sensitive(self): uppercase_course_id = "ORG/COURSE/NAME" lowercase_course_id = uppercase_course_id.lower() uppercase_course_key = CourseKey.from_string(uppercase_course_id) lowercase_course_key = CourseKey.from_string(lowercase_course_id) role = "role" lowercase_user = UserFactory() CourseRole(role, lowercase_course_key).add_users(lowercase_user) uppercase_user = UserFactory() CourseRole(role, uppercase_course_key).add_users(uppercase_user) self.assertTrue(CourseRole(role, lowercase_course_key).has_user(lowercase_user)) self.assertFalse(CourseRole(role, uppercase_course_key).has_user(lowercase_user)) self.assertFalse(CourseRole(role, lowercase_course_key).has_user(uppercase_user)) self.assertTrue(CourseRole(role, uppercase_course_key).has_user(uppercase_user))
def setUp(self): """ Setup components used by each test.""" super().setUp() self.student = UserFactory() registration = Registration() registration.register(self.student) self.msg = compose_activation_email(self.student, registration)
def setUp(self): """ Setup components used by each test.""" super(SendActivationEmailTestCase, self).setUp() self.student = UserFactory() registration = Registration() registration.register(self.student) self.msg = compose_activation_email("http://www.example.com", self.student, registration)
def test_show_enrollment_data_for_prof_ed(self): # Create both "professional" (meaning professional + verification) # and "no-id-professional" (meaning professional without verification) # These should be aggregated for display purposes. users = [UserFactory() for _ in range(2)] CourseEnrollment.enroll(users[0], self.course.id, mode="professional") CourseEnrollment.enroll(users[1], self.course.id, mode="no-id-professional") response = self.client.get(self.url) # Check that the number of professional enrollments is two self.assertContains(response, '<th scope="row">Professional</th><td>2</td>')
def setUp(self): """ Add a user and a course """ super().setUp() # create and log in a staff user. self.user = UserFactory(is_staff=True) self.client = AjaxEnabledTestClient() self.client.login(username=self.user.username, password='******') # create a course via the view handler to create course self.course_key = self.store.make_course_key('Org_1', 'Course_1', 'Run_1') self._create_course_with_given_location(self.course_key)
def build_course(self): """ Build up a course tree with an html control """ self.global_staff = UserFactory(is_staff=True) self.course = CourseFactory.create( org='Elasticsearch', course='ES101', run='test_run', display_name='Elasticsearch test course', ) self.section = ItemFactory.create( parent=self.course, category='chapter', display_name='Test Section', ) self.subsection = ItemFactory.create( parent=self.section, category='sequential', display_name='Test Subsection', ) self.vertical = ItemFactory.create( parent=self.subsection, category='vertical', display_name='Test Unit', ) self.html = ItemFactory.create( parent=self.vertical, category='html', display_name='Test Html control', ) self.ghost_subsection = ItemFactory.create( parent=self.section, category='sequential', display_name=None, ) self.ghost_vertical = ItemFactory.create( parent=self.ghost_subsection, category='vertical', display_name=None, ) self.ghost_html = ItemFactory.create( parent=self.ghost_vertical, category='html', display_name='Ghost Html control', )
def test_access_student_progress_ccx(self): """ Assert that only a coach can see progress of student. """ ccx_locator = self.make_ccx() student = UserFactory() # Enroll user CourseEnrollment.enroll(student, ccx_locator) # Test for access of a coach resp = self.client.get(reverse('student_progress', args=[six.text_type(ccx_locator), student.id])) self.assertEqual(resp.status_code, 200) # Assert access of a student self.client.login(username=student.username, password='******') resp = self.client.get(reverse('student_progress', args=[six.text_type(ccx_locator), self.coach.id])) self.assertEqual(resp.status_code, 404)
def test_entrance_exam_gating(self): """ Unit Test: test_entrance_exam_gating """ # This user helps to cover a discovered bug in the milestone fulfillment logic chaos_user = UserFactory() locked_toc = self._return_table_of_contents() for toc_section in self.expected_locked_toc: assert toc_section in locked_toc # Set up the chaos user answer_entrance_exam_problem(self.course, self.request, self.problem_1, chaos_user) answer_entrance_exam_problem(self.course, self.request, self.problem_1) answer_entrance_exam_problem(self.course, self.request, self.problem_2) 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 case scaffolding """ super(EntranceExamTestCases, self).setUp() self.course = CourseFactory.create(metadata={ 'entrance_exam_enabled': True, }) with self.store.bulk_operations(self.course.id): self.chapter = ItemFactory.create(parent=self.course, display_name='Overview') self.welcome = ItemFactory.create(parent=self.chapter, display_name='Welcome') ItemFactory.create(parent=self.course, category='chapter', display_name="Week 1") self.chapter_subsection = ItemFactory.create( parent=self.chapter, category='sequential', display_name="Lesson 1") chapter_vertical = ItemFactory.create( parent=self.chapter_subsection, category='vertical', display_name='Lesson 1 Vertical - Unit 1') ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1") ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2") ItemFactory.create(category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor") self.entrance_exam = ItemFactory.create( parent=self.course, category="chapter", display_name="Entrance Exam Section - Chapter 1", is_entrance_exam=True, in_entrance_exam=True) self.exam_1 = ItemFactory.create( parent=self.entrance_exam, category='sequential', display_name="Exam Sequential - Subsection 1", graded=True, in_entrance_exam=True) subsection = ItemFactory.create( parent=self.exam_1, category='vertical', display_name='Exam Vertical - Unit 1') problem_xml = MultipleChoiceResponseXMLFactory().build_xml( question_text='The correct answer is Choice 3', choices=[False, False, True, False], choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']) self.problem_1 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 1", data=problem_xml) self.problem_2 = ItemFactory.create( parent=subsection, category="problem", display_name="Exam Problem - Problem 2") add_entrance_exam_milestone(self.course, self.entrance_exam) self.course.entrance_exam_enabled = True self.course.entrance_exam_minimum_score_pct = 0.50 self.course.entrance_exam_id = six.text_type( self.entrance_exam.scope_ids.usage_id) self.anonymous_user = AnonymousUserFactory() self.addCleanup(set_current_request, None) self.request = get_mock_request(UserFactory()) modulestore().update_item(self.course, self.request.user.id) self.client.login(username=self.request.user.username, password="******") CourseEnrollment.enroll(self.request.user, self.course.id) self.expected_locked_toc = ([{ 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1', }]) self.expected_unlocked_toc = ([{ 'active': False, 'sections': [{ 'url_name': u'Welcome', 'display_name': u'Welcome', 'graded': False, 'format': '', 'due': None, 'active': False }, { 'url_name': u'Lesson_1', 'display_name': u'Lesson 1', 'graded': False, 'format': '', 'due': None, 'active': False }], 'url_name': u'Overview', 'display_name': u'Overview', 'display_id': u'overview' }, { 'active': False, 'sections': [], 'url_name': u'Week_1', 'display_name': u'Week 1', 'display_id': u'week-1' }, { 'active': False, 'sections': [], 'url_name': u'Instructor', 'display_name': u'Instructor', 'display_id': u'instructor' }, { 'active': True, 'sections': [{ 'url_name': u'Exam_Sequential_-_Subsection_1', 'display_name': u'Exam Sequential - Subsection 1', 'graded': True, 'format': '', 'due': None, 'active': True }], 'url_name': u'Entrance_Exam_Section_-_Chapter_1', 'display_name': u'Entrance Exam Section - Chapter 1', 'display_id': u'entrance-exam-section-chapter-1' }])
def setUp(self): """ Setup components used by each test.""" super(SendCalendarSyncEmailTestCase, self).setUp() self.user = UserFactory() self.course_overview = CourseOverviewFactory() self.msg = compose_calendar_sync_email(self.user, self.course_overview)
def setUp(self): super().setUp() self.user = UserFactory()
def setUp(self): super(RoleCacheTestCase, self).setUp() self.user = UserFactory()
def setUp(self): super(GroupAccessTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments UserPartition.scheme_extensions = ExtensionManager.make_test_instance( [ Extension("memory", USER_PARTITION_SCHEME_NAMESPACE, MemoryUserPartitionScheme(), None), Extension("random", USER_PARTITION_SCHEME_NAMESPACE, MemoryUserPartitionScheme(), None) ], namespace=USER_PARTITION_SCHEME_NAMESPACE) self.cat_group = Group(10, 'cats') self.dog_group = Group(20, 'dogs') self.worm_group = Group(30, 'worms') self.animal_partition = UserPartition( 0, 'Pet Partition', 'which animal are you?', [self.cat_group, self.dog_group, self.worm_group], scheme=UserPartition.get_scheme("memory"), ) self.red_group = Group(1000, 'red') self.blue_group = Group(2000, 'blue') self.gray_group = Group(3000, 'gray') self.color_partition = UserPartition( 100, 'Color Partition', 'what color are you?', [self.red_group, self.blue_group, self.gray_group], scheme=UserPartition.get_scheme("memory"), ) self.course = CourseFactory.create( user_partitions=[self.animal_partition, self.color_partition], ) with self.store.bulk_operations(self.course.id, emit_signals=False): chapter = ItemFactory.create(category='chapter', parent=self.course) section = ItemFactory.create(category='sequential', parent=chapter) vertical = ItemFactory.create(category='vertical', parent=section) component = ItemFactory.create(category='problem', parent=vertical) self.chapter_location = chapter.location self.section_location = section.location self.vertical_location = vertical.location self.component_location = component.location self.red_cat = UserFactory() # student in red and cat groups self.set_user_group(self.red_cat, self.animal_partition, self.cat_group) self.set_user_group(self.red_cat, self.color_partition, self.red_group) self.blue_dog = UserFactory() # student in blue and dog groups self.set_user_group(self.blue_dog, self.animal_partition, self.dog_group) self.set_user_group(self.blue_dog, self.color_partition, self.blue_group) self.white_mouse = UserFactory() # student in no group self.gray_worm = UserFactory() # student in deleted group self.set_user_group(self.gray_worm, self.animal_partition, self.worm_group) self.set_user_group(self.gray_worm, self.color_partition, self.gray_group) # delete the gray/worm groups from the partitions now so we can test scenarios # for user whose group is missing. self.animal_partition.groups.pop() self.color_partition.groups.pop() # add a staff user, whose access will be unconditional in spite of group access. self.staff = StaffFactory.create(course_key=self.course.id)
def setUp(self): """ Setup components used by each test.""" super(SendActivationEmailTestCase, self).setUp() self.student = UserFactory()
def setUp(self): super(RoleCacheTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory()