def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.ccx = ccx = CustomCourseForEdX( course_id=self.course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) inject_field_overrides(iter_blocks(ccx.course), self.course, AdminFactory.create()) self.ccx_key = CCXLocator.from_course_locator(self.course.id, ccx.id) self.ccx_course = get_course_by_id(self.ccx_key, depth=None) def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() self.course.enable_ccx = True # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime( 2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=course) for _ in xrange(2)] sequentials = flatten([ [ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([ [ItemFactory.create(due=due, parent=sequential) for _ in xrange(2)] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals]) self.ccx = ccx = CustomCourseForEdX( course_id=course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None for block in iter_blocks(ccx.course): block._field_data = OverrideFieldData.wrap( # pylint: disable=protected-access AdminFactory.create(), course, block._field_data) # pylint: disable=protected-access def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): patcher = patch('student.models.tracker') self.mock_tracker = patcher.start() self.user = UserFactory.create() self.user.set_password('password') self.user.save() self.instructor = AdminFactory.create() self.cost = 40 self.coupon_code = 'abcde' self.reg_code = 'qwerty' self.percentage_discount = 10 self.course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course') self.course_key = self.course.id self.course_mode = CourseMode(course_id=self.course_key, mode_slug="honor", mode_display_name="honor cert", min_price=self.cost) self.course_mode.save() #Saving another testing course mode self.testing_cost = 20 self.testing_course = CourseFactory.create(org='edX', number='888', display_name='Testing Super Course') self.testing_course_mode = CourseMode(course_id=self.testing_course.id, mode_slug="honor", mode_display_name="testing honor cert", min_price=self.testing_cost) self.testing_course_mode.save() verified_course = CourseFactory.create(org='org', number='test', display_name='Test Course') self.verified_course_key = verified_course.id self.cart = Order.get_cart_for_user(self.user) self.addCleanup(patcher.stop)
def setUp(self): super(TestRenderMessageToString, self).setUp() coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=self.course.id, coach=coach) self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
def setUp(self): patcher = patch("student.models.tracker") self.mock_tracker = patcher.start() self.user = UserFactory.create() self.user.set_password("password") self.user.save() self.instructor = AdminFactory.create() self.cost = 40 self.coupon_code = "abcde" self.reg_code = "qwerty" self.percentage_discount = 10 self.course = CourseFactory.create(org="MITx", number="999", display_name="Robot Super Course") self.course_key = self.course.id self.course_mode = CourseMode( course_id=self.course_key, mode_slug="honor", mode_display_name="honor cert", min_price=self.cost ) self.course_mode.save() # Saving another testing course mode self.testing_cost = 20 self.testing_course = CourseFactory.create(org="edX", number="888", display_name="Testing Super Course") self.testing_course_mode = CourseMode( course_id=self.testing_course.id, mode_slug="honor", mode_display_name="testing honor cert", min_price=self.testing_cost, ) self.testing_course_mode.save() verified_course = CourseFactory.create(org="org", number="test", display_name="Test Course") self.verified_course_key = verified_course.id self.cart = Order.get_cart_for_user(self.user) self.addCleanup(patcher.stop)
def setUp(self): """ Set up tests """ super(TestCoachDashboard, self).setUp() self.course = course = CourseFactory.create() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime( 2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=course) for _ in xrange(2)] sequentials = flatten([ [ ItemFactory.create(parent=chapter) for _ in xrange(2) ] for chapter in chapters ]) verticals = flatten([ [ ItemFactory.create( due=due, parent=sequential, graded=True, format='Homework' ) for _ in xrange(2) ] for sequential in sequentials ]) blocks = flatten([ # pylint: disable=unused-variable [ ItemFactory.create(parent=vertical) for _ in xrange(2) ] for vertical in verticals ])
def setUp(self): super(DiscussionTabTestCase, self).setUp() self.course = CourseFactory.create() self.enrolled_user = UserFactory.create() self.staff_user = AdminFactory.create() CourseEnrollmentFactory.create(user=self.enrolled_user, course_id=self.course.id) self.unenrolled_user = UserFactory.create()
def test_patch_detail(self): """ Test for successful patch """ outbox = self.get_outbox() # create a new coach new_coach = AdminFactory.create() data = { 'max_students_allowed': 111, 'display_name': 'CCX Title', 'coach_email': new_coach.email } resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=self.auth) self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) self.assertEqual(ccx_from_db.max_student_enrollments_allowed, data['max_students_allowed']) self.assertEqual(ccx_from_db.display_name, data['display_name']) self.assertEqual(ccx_from_db.coach.email, data['coach_email']) # check that the coach user has coach role on the master course coach_role_on_master_course = CourseCcxCoachRole(self.master_course_key) self.assertTrue(coach_role_on_master_course.has_user(new_coach)) # check that the coach has been enrolled in the ccx ccx_course_object = courses.get_course_by_id(self.ccx_key) self.assertTrue( CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=new_coach).exists() ) # check that an email has been sent to the coach self.assertEqual(len(outbox), 1) self.assertIn(new_coach.email, outbox[0].recipients()) # pylint: disable=no-member
def setUpTestData(cls): """ Set up models for the whole TestCase. """ cls.user = UserFactory.create() # Create instructor account cls.coach = AdminFactory.create()
def setUp(self): super(TestGradebook, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i, item in enumerate(self.items): for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=user, course_id=self.course.id, module_state_key=item.location ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) )) self.assertEquals(self.response.status_code, 200)
def setUp(self): """ Set up tests """ super(TestInstructorDashboard, self).setUp() self.course = CourseFactory.create( grading_policy={"GRADE_CUTOFFS": {"A": 0.75, "B": 0.63, "C": 0.57, "D": 0.5}}, display_name='<script>alert("XSS")</script>' ) self.course_mode = CourseMode( course_id=self.course.id, mode_slug=CourseMode.DEFAULT_MODE_SLUG, mode_display_name=CourseMode.DEFAULT_MODE.name, min_price=40 ) self.course_info = CourseFactory.create( org="ACME", number="001", run="2017", name="How to defeat the Road Runner" ) self.course_mode.save() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': text_type(self.course.id)})
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create CCX role = CourseCcxCoachRole(self._course.id) role.add_users(coach) ccx = CcxFactory(course_id=self._course.id, coach=self.coach) # override course grading policy and make last section invisible to students override_field_for_ccx( ccx, self._course, "grading_policy", { "GRADER": [{"drop_count": 0, "min_count": 2, "short_label": "HW", "type": "Homework", "weight": 1}], "GRADE_CUTOFFS": {"Pass": 0.75}, }, ) override_field_for_ccx(ccx, self.sections[-1], "visible_to_staff_only", True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id) self.course = get_course_by_id(self.ccx_key, depth=None) setup_students_and_grades(self) self.client.login(username=coach.username, password="******") self.addCleanup(RequestCache.clear_request_cache)
def setUp(self): """Set up a course, coach, ccx and user""" super(TestGetCCXFromCCXLocator, self).setUp() self.course = CourseFactory.create() coach = self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach)
def setUp(self): super(TestGetProblemGradeDistribution, self).setUp() self.request_factory = RequestFactory() self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password='******') self.attempts = 3 self.course = CourseFactory.create( display_name=u"test course omega \u03a9", ) section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega \u03a9", ) self.users = [UserFactory.create(username="******" + str(__)) for __ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" self.item = ItemFactory.create( parent_location=unit.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}, display_name=u"test problem omega \u03a9 " + str(i) ) for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1 if i < j else 0.5, student=user, course_id=self.course.id, module_state_key=self.item.location, state=json.dumps({'attempts': self.attempts}), ) for j, user in enumerate(self.users): StudentModuleFactory.create( course_id=self.course.id, module_type='sequential', module_state_key=self.item.location, )
def setUp(self): super(TestGetProblemGradeDistribution, self).setUp() self.request_factory = RequestFactory() self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password='******') self.attempts = 3 self.users = [ UserFactory.create(username="******" + str(__)) for __ in xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i, item in enumerate(self.items): for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1 if i < j else 0.5, student=user, course_id=self.course.id, module_state_key=item.location, state=json.dumps({'attempts': self.attempts}), ) for j, user in enumerate(self.users): StudentModuleFactory.create( course_id=self.course.id, module_type='sequential', module_state_key=item.location, )
def setUp(self): """ Set up courses and enrollments. """ super(TestStudentViewsWithCCX, self).setUp() # Create a Draft Mongo and a Split Mongo course and enroll a student user in them. self.student_password = "******" self.student = UserFactory.create(username="******", password=self.student_password, is_staff=False) self.draft_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) self.split_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.split) CourseEnrollment.enroll(self.student, self.draft_course.id) CourseEnrollment.enroll(self.student, self.split_course.id) # Create a CCX coach. self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.split_course.id) role.add_users(self.coach) # Create a CCX course and enroll the user in it. self.ccx = CcxFactory(course_id=self.split_course.id, coach=self.coach) last_week = datetime.datetime.now(UTC()) - datetime.timedelta(days=7) override_field_for_ccx(self.ccx, self.split_course, 'start', last_week) # Required by self.ccx.has_started(). self.ccx_course_key = CCXLocator.from_course_locator(self.split_course.id, self.ccx.id) CourseEnrollment.enroll(self.student, self.ccx_course_key)
def _test_add_histogram(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') course = CourseFactory.create(org='test', number='313', display_name='histogram test') section = ItemFactory.create( parent_location=course.location, display_name='chapter hist', category='chapter') problem = ItemFactory.create( parent_location=section.location, display_name='problem hist 1', category='problem') problem.has_score = False # don't trip trying to retrieve db data late_problem = ItemFactory.create( parent_location=section.location, display_name='problem hist 2', category='problem') late_problem.start = datetime.datetime.now(UTC) + datetime.timedelta(days=32) late_problem.has_score = False problem_module = factories.get_test_xmodule_for_descriptor(problem) problem_module.get_html = xmodule_modifiers.add_histogram(lambda:'', problem_module, instructor) self.assertRegexpMatches( problem_module.get_html(), r'.*<font color=\'green\'>Not yet</font>.*') problem_module = factories.get_test_xmodule_for_descriptor(late_problem) problem_module.get_html = xmodule_modifiers.add_histogram(lambda: '', problem_module, instructor) self.assertRegexpMatches( problem_module.get_html(), r'.*<font color=\'red\'>Yes!</font>.*')
def setUp(self): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { "student_unenrolled": UserFactory.create(password=self.test_password), "student_enrolled": UserFactory.create(password=self.test_password), "student_enrolled_not_on_team": UserFactory.create(password=self.test_password), # This student is enrolled in both test courses and is a member of a team in each course, but is not on the # same team as student_enrolled. "student_enrolled_both_courses_other_team": UserFactory.create(password=self.test_password), "staff": AdminFactory.create(password=self.test_password), "course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password), } # 'solar team' is intentionally lower case to test case insensitivity in name ordering self.test_team_1 = CourseTeamFactory.create( name=u"sólar team", course_id=self.test_course_1.id, topic_id="topic_0" ) self.test_team_2 = CourseTeamFactory.create(name="Wind Team", course_id=self.test_course_1.id) self.test_team_3 = CourseTeamFactory.create(name="Nuclear Team", course_id=self.test_course_1.id) self.test_team_4 = CourseTeamFactory.create(name="Coal Team", course_id=self.test_course_1.id, is_active=False) self.test_team_5 = CourseTeamFactory.create(name="Another Team", course_id=self.test_course_2.id) for user, course in [ ("student_enrolled", self.test_course_1), ("student_enrolled_not_on_team", self.test_course_1), ("student_enrolled_both_courses_other_team", self.test_course_1), ("student_enrolled_both_courses_other_team", self.test_course_2), ]: CourseEnrollment.enroll(self.users[user], course.id, check_access=True) self.test_team_1.add_user(self.users["student_enrolled"]) self.test_team_3.add_user(self.users["student_enrolled_both_courses_other_team"]) self.test_team_5.add_user(self.users["student_enrolled_both_courses_other_team"])
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() self.course.enable_ccx = True # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime( 2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=course) for _ in xrange(2)] sequentials = flatten([ [ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([ [ItemFactory.create(due=due, parent=sequential) for _ in xrange(2)] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals]) self.ccx = ccx = CustomCourseForEdX( course_id=course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) inject_field_overrides(iter_blocks(ccx.course), course, AdminFactory.create()) def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): super(TeamAPITestCase, self).setUp() teams_configuration = { 'topics': [ { 'id': 'topic_{}'.format(i), 'name': name, 'description': 'Description for topic {}.'.format(i) } for i, name in enumerate([u'sólar power', 'Wind Power', 'Nuclear Power', 'Coal Power']) ] } self.topics_count = 4 self.test_course_1 = CourseFactory.create( org='TestX', course='TS101', display_name='Test Course', teams_configuration=teams_configuration ) self.test_course_2 = CourseFactory.create(org='MIT', course='6.002x', display_name='Circuits') self.users = { 'student_unenrolled': UserFactory.create(password=self.test_password), 'student_enrolled': UserFactory.create(password=self.test_password), 'student_enrolled_not_on_team': UserFactory.create(password=self.test_password), # This student is enrolled in both test courses and is a member of a team in each course, but is not on the # same team as student_enrolled. 'student_enrolled_both_courses_other_team': UserFactory.create(password=self.test_password), 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } # 'solar team' is intentionally lower case to test case insensitivity in name ordering self.test_team_1 = CourseTeamFactory.create( name=u'sólar team', course_id=self.test_course_1.id, topic_id='topic_0' ) self.test_team_2 = CourseTeamFactory.create(name='Wind Team', course_id=self.test_course_1.id) self.test_team_3 = CourseTeamFactory.create(name='Nuclear Team', course_id=self.test_course_1.id) self.test_team_4 = CourseTeamFactory.create(name='Coal Team', course_id=self.test_course_1.id, is_active=False) self.test_team_5 = CourseTeamFactory.create(name='Another Team', course_id=self.test_course_2.id) for user, course in [ ('student_enrolled', self.test_course_1), ('student_enrolled_not_on_team', self.test_course_1), ('student_enrolled_both_courses_other_team', self.test_course_1), ('student_enrolled_both_courses_other_team', self.test_course_2) ]: CourseEnrollment.enroll( self.users[user], course.id, check_access=True ) self.test_team_1.add_user(self.users['student_enrolled']) self.test_team_3.add_user(self.users['student_enrolled_both_courses_other_team']) self.test_team_5.add_user(self.users['student_enrolled_both_courses_other_team'])
def setUp(self): super(TestProctoringDashboardViews, self).setUp() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
def setUp(self): """Set up a course, coach, ccx and user""" super(TestGetMembershipTriplets, self).setUp() self.course = CourseFactory.create() coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
def setUp(self): self.instructor = AdminFactory.create() self.course = CourseFactory.create() self.client.login(username=self.instructor.username, password='******') self.students = [UserFactory() for _ in xrange(6)] for student in self.students: CourseEnrollment.enroll(student, self.course.id)
def setUp(self): """common setup for all tests""" super(TestCCX, self).setUp() self.course = course = CourseFactory.create() coach = AdminFactory.create() role = CourseCcxCoachRole(course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=course.id, coach=coach)
def setUp(self): self.course = CourseFactory.create() self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") # load initial content (since we don't run migrations as part of tests): call_command("loaddata", "course_email_template.json") self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id})
def setUp(self): super(TestGradebookVertical, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().request_cache = None modulestore().metadata_inheritance_cache_subsystem = None kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) chapter = ItemFactory.create( parent_location=self.course.location, category="sequential", ) section = ItemFactory.create( parent_location=chapter.location, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.8} ) ItemFactory.create( parent_location=chapter.location, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.2} ) self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=user, course_id=self.course.id, module_state_key=item.location ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) ))
def make_staff(self): """ create staff user """ staff = AdminFactory.create(password="******") role = CourseStaffRole(self.course.id) role.add_users(staff) return staff
def setUp(self): """ Log in as an instructor, and create a course/student to reset. """ instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.student = UserFactory.create(username='******', email='*****@*****.**') self.course = CourseFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
def make_instructor(self): """ create staff instructor """ instructor = AdminFactory.create(password="******") role = CourseInstructorRole(self.course.id) role.add_users(instructor) return instructor
def setUp(self): """ Set up tests """ super(TestCoachDashboard, self).setUp() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******")
def setUp(self): super(TestProctoringDashboardViews, self).setUp() self.course = CourseFactory.create() self.course.enable_proctored_exams = True # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") self.course = self.update_course(self.course, self.instructor.id) # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.proctoring_link = '<a href="" data-section="proctoring">Proctoring</a>' CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
def setUp(self): super(TestACEOptoutCourseEmails, self).setUp() course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(run='testcourse1', display_name=course_title) self.instructor = AdminFactory.create() self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) self.client.login(username=self.student.username, password="******") self._set_email_optout(False) self.policy = CourseEmailOptout()
def setUp(self): super(TestNewInstructorDashboardEmailViewMongoBacked, self).setUp() self.course = CourseFactory.create() # Create instructor account instructor = AdminFactory.create() self.client.login(username=instructor.username, password="******") # URL for instructor dash self.url = reverse( 'instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) # URL for email view self.email_link = '<a href="" data-section="send_email">Email</a>'
def test_sending_deprecated_id(self): course = CourseFactory.create() instructor = AdminFactory.create() self.request.user = instructor response = views.all_sequential_open_distrib(self.request, course.id.to_deprecated_string()) self.assertEqual('[]', response.content) response = views.all_problem_grade_distribution(self.request, course.id.to_deprecated_string()) self.assertEqual('[]', response.content) response = views.section_problem_grade_distrib(self.request, course.id.to_deprecated_string(), 'no section') self.assertEqual('{"error": "error"}', response.content)
def setUp(self): super(TestNewInstructorDashboardEmailViewXMLBacked, self).setUp() self.course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') # Create instructor account instructor = AdminFactory.create() self.client.login(username=instructor.username, password="******") # URL for instructor dash self.url = reverse( 'instructor_dashboard', kwargs={'course_id': self.course_key.to_deprecated_string()}) # URL for email view self.email_link = '<a href="" data-section="send_email">Email</a>'
def setUp(self): """ Set up tests """ super(CoachAccessTestCaseCCX, self).setUp() # Create ccx coach account self.coach = AdminFactory.create(password="******") self.client.login(username=self.coach.username, password="******") # assign role to coach role = CourseCcxCoachRole(self.course.id) role.add_users(self.coach) self.request_factory = RequestFactory()
def setUp(self): """ Creates a test course ID, mocks the runtime, and creates a fake storage engine for use in all tests """ super(StaffGradedAssignmentXblockTests, self).setUp() self.course = CourseFactory.create(org='foo', number='bar', display_name='baz') self.descriptor = ItemFactory(category="pure", parent=self.course) self.course_id = self.course.id self.instructor = StaffFactory.create(course_key=self.course_id) self.student_data = mock.Mock() self.staff = AdminFactory.create(password="******") self.runtime = self.make_runtime() self.scope_ids = self.make_scope_ids(self.runtime)
def setUp(self): course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(display_name=course_title) self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") # load initial content (since we don't run migrations as part of tests): call_command("loaddata", "course_email_template.json") self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.send_mail_url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.success_content = { 'course_id': self.course.id.to_deprecated_string(), 'success': True, }
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().request_cache = None modulestore().metadata_inheritance_cache_subsystem = None kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) chapter = ItemFactory.create( parent_location=self.course.location, category="sequential", ) section = ItemFactory.create( parent_location=chapter.location, category="sequential", metadata={'graded': True, 'format': 'Homework'} ) self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=user, course_id=self.course.id, module_state_key=item.location ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) ))
def setUp(self): super(TestGetEmailParamsCCX, self).setUp() self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(self.coach) self.ccx = CcxFactory(course_id=self.course.id, coach=self.coach) self.course_key = CCXLocator.from_course_locator( self.course.id, self.ccx.id) # Explicitly construct what we expect the course URLs to be site = settings.SITE_NAME self.course_url = u'https://{}/courses/{}/'.format( site, self.course_key) self.course_about_url = self.course_url + 'about' self.registration_url = u'https://{}/register'.format(site)
def setUp(self): super(TestBlocksView, self).setUp() # create and enroll user in the toy course self.user = UserFactory.create() self.admin_user = AdminFactory.create() self.client.login(username=self.user.username, password='******') CourseEnrollmentFactory.create(user=self.user, course_id=self.course_key) # default values for url and query_params self.url = reverse( 'blocks_in_block_tree', kwargs={'usage_key_string': str(self.course_usage_key)}) self.query_params = {'depth': 'all', 'username': self.user.username}
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') modulestore().request_cache = modulestore().metadata_inheritance_cache_subsystem = None course_data = {} if self.grading_policy is not None: course_data['grading_policy'] = self.grading_policy self.course = CourseFactory.create(data=course_data) chapter = ItemFactory.create( parent_location=self.course.location, template="i4x://edx/templates/sequential/Empty", ) section = ItemFactory.create( parent_location=chapter.location, template="i4x://edx/templates/sequential/Empty", metadata={'graded': True, 'format': 'Homework'} ) self.users = [ UserFactory.create(username='******' % i, email='*****@*****.**' % i) for i in xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT-1): template_name = "i4x://edx/templates/problem/Blank_Common_Problem" item = ItemFactory.create( parent_location=section.location, template=template_name, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) for j, user in enumerate(self.users): StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=user, course_id=self.course.id, module_state_key=Location(item.location).url() ) self.response = self.client.get(reverse('gradebook', args=(self.course.id,)))
def setUp(self): super(TestECommerceDashboardViews, self).setUp() self.course = CourseFactory.create() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") mode = CourseMode( course_id=self.course.id.to_deprecated_string(), mode_slug='honor', mode_display_name='honor', min_price=10, currency='usd' ) mode.save() # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.e_commerce_link = '<a href="" data-section="e-commerce">E-Commerce</a>' CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
def setUp(self): self.instructor = AdminFactory.create() self.course = CourseFactory.create() self.client.login(username=self.instructor.username, password='******') self.student = UserFactory() CourseEnrollment.enroll(self.student, self.course.id) self.problem_urlname = 'robot-some-problem-urlname' self.module_to_reset = StudentModule.objects.create( student=self.student, course_id=self.course.id, module_state_key=_msk_from_problem_urlname(self.course.id, self.problem_urlname), state=json.dumps({'attempts': 10}), )
def setUp(self): super(TestInstructorEnrollsStudent, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.users = [ UserFactory.create(username="******" % i, email="*****@*****.**" % i) for i in xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) # Empty the test outbox mail.outbox = []
def test_get_task_name(self, is_regeneration, expected): staff = AdminFactory.create() instructor_task = InstructorTaskFactory.create( task_input=json.dumps({}), requester=staff, task_key=Mock(), task_id=Mock(), ) certificate_generation_history = CertificateGenerationHistory( course_id=instructor_task.course_id, generated_by=staff, instructor_task=instructor_task, is_regeneration=is_regeneration, ) self.assertEqual(certificate_generation_history.get_task_name(), expected)
def setUp(self): """ Set up tests """ super(TestGetEmailParams, self).setUp() course = CourseFactory.create() coach = AdminFactory.create() role = CourseCcxCoachRole(course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=course.id, coach=coach) self.all_keys = [ 'site_name', 'course', 'course_url', 'registration_url', 'course_about_url', 'auto_enroll' ] self.url_keys = [k for k in self.all_keys if 'url' in k] self.course_keys = [k for k in self.url_keys if 'course' in k]
def setUp(self): """ Set up tests """ super(TestCCXModulestoreWrapper, self).setUp() self.user = UserFactory.create() # Create instructor account coach = AdminFactory.create() self.ccx = ccx = CustomCourseForEdX(course_id=self.course.id, display_name='Test CCX', coach=coach) ccx.save() self.ccx_locator = CCXLocator.from_course_locator( self.course.id, ccx.id) # pylint: disable=no-member
def setUp(self): """ Creates a test course ID, mocks the runtime, and creates a fake storage engine for use in all tests """ super(FreeformGradedAssignmentXblockTests, self).setUp() course = CourseFactory.create(org='foo', number='bar', display_name='baz') self.course_id = course.id self.runtime = mock.Mock(anonymous_student_id='MOCK') self.scope_ids = mock.Mock() tmp = tempfile.mkdtemp() patcher = mock.patch( "edx_fga.fga.default_storage", FileSystemStorage(tmp)) patcher.start() self.addCleanup(patcher.stop) self.staff = AdminFactory.create(password="******")
def setUp(self): """ Set up tests """ super(TestCCXModulestoreWrapper, self).setUp() self.course = course = CourseFactory.create() # Create instructor account coach = AdminFactory.create() # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) self.chapters = chapters = [ ItemFactory.create(start=start, parent=course) for _ in xrange(2) ] self.sequentials = sequentials = [ ItemFactory.create(parent=c) for _ in xrange(2) for c in chapters ] self.verticals = verticals = [ ItemFactory.create(due=due, parent=s, graded=True, format='Homework') for _ in xrange(2) for s in sequentials ] self.blocks = [ ItemFactory.create(parent=v) for _ in xrange(2) for v in verticals ] self.ccx = ccx = CustomCourseForEdX(course_id=course.id, display_name='Test CCX', coach=coach) ccx.save() self.ccx_locator = CCXLocator.from_course_locator(course.id, ccx.id) # pylint: disable=no-member
def setUp(self): """ Set up tests """ super(APIsTestCase, self).setUp() # Create instructor account self.instructor = AdminFactory.create() # create an instance of modulestore self.mstore = modulestore() # enable ccx self.course.enable_ccx = True # setup CCX connector self.course.ccx_connector = 'https://url.to.cxx.connector.mit.edu' # save the changes self.mstore.update_item(self.course, self.instructor.id) # create a configuration for the ccx connector: this must match the one in the course self.ccxcon_conf = CcxConFactory(url=self.course.ccx_connector)
def setUp(self): """ Set up tests """ super(TestSendCCXCoursePublished, self).setUp() course = self.course = CourseFactory.create(org="edX", course="999", display_name="Run 666") course2 = self.course2 = CourseFactory.create(org="edX", course="999a", display_name="Run 667") coach = AdminFactory.create() role = CourseCcxCoachRole(course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=course.id, coach=coach) self.ccx2 = CcxFactory(course_id=course.id, coach=coach) self.ccx3 = CcxFactory(course_id=course.id, coach=coach) self.ccx4 = CcxFactory(course_id=course2.id, coach=coach)
def setUp(self): """ Set up tests """ super(TestInstructorDashboard, self).setUp() self.course = CourseFactory.create() self.course_mode = CourseMode(course_id=self.course.id, mode_slug="honor", mode_display_name="honor cert", min_price=40) self.course_mode.save() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})
def setUp(self): super(TestOptoutCourseEmailsBySignal, self).setUp() self.course = CourseFactory.create(run='testcourse1', display_name="Test Course Title") self.instructor = AdminFactory.create() self.student = UserFactory.create() self.enrollment = CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) # load initial content (since we don't run migrations as part of tests): call_command("loaddata", "course_email_template.json") self.client.login(username=self.student.username, password="******") self.send_mail_url = reverse('send_email', kwargs={'course_id': text_type(self.course.id)}) self.success_content = { 'course_id': text_type(self.course.id), 'success': True, } BulkEmailFlag.objects.create(enabled=True, require_course_email_auth=False)
def test_submission_history_contents(self): # log into a staff account admin = AdminFactory.create() self.client.login(username=admin.username, password='******') usage_key = self.course_key.make_usage_key('problem', 'test-history') state_client = DjangoXBlockUserStateClient(admin) # store state via the UserStateClient state_client.set( username=admin.username, block_key=usage_key, state={'field_a': 'x', 'field_b': 'y'} ) set_score(admin.id, usage_key, 0, 3) state_client.set( username=admin.username, block_key=usage_key, state={'field_a': 'a', 'field_b': 'b'} ) set_score(admin.id, usage_key, 3, 3) url = reverse('submission_history', kwargs={ 'course_id': unicode(self.course_key), 'student_username': admin.username, 'location': unicode(usage_key), }) response = self.client.get(url) response_content = HTMLParser().unescape(response.content) # We have update the state 4 times: twice to change content, and twice # to set the scores. We'll check that the identifying content from each is # displayed (but not the order), and also the indexes assigned in the output # #1 - #4 self.assertIn('#1', response_content) self.assertIn(json.dumps({'field_a': 'a', 'field_b': 'b'}, sort_keys=True, indent=2), response_content) self.assertIn("Score: 0.0 / 3.0", response_content) self.assertIn(json.dumps({'field_a': 'x', 'field_b': 'y'}, sort_keys=True, indent=2), response_content) self.assertIn("Score: 3.0 / 3.0", response_content) self.assertIn('#4', response_content)
def setUp(self): """ Creates a test course ID, mocks the runtime, and creates a fake storage engine for use in all tests """ from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=import-error super(StaffGradedAssignmentXblockTests, self).setUp() course = CourseFactory.create(org='foo', number='bar', display_name='baz') self.course_id = course.id self.runtime = mock.Mock(anonymous_student_id='MOCK') self.scope_ids = mock.Mock() tmp = tempfile.mkdtemp() patcher = mock.patch("edx_sga.sga.default_storage", FileSystemStorage(tmp)) patcher.start() self.addCleanup(patcher.stop) self.staff = AdminFactory.create(password="******")
def get_email_params_ccx(self): """ Returns a dictionary of parameters used to render an email for CCX. """ coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = CcxFactory(course_id=self.course.id, coach=coach) self.course_key = CCXLocator.from_course_locator( self.course.id, self.ccx.id) email_params = get_email_params(self.course, True, course_key=self.course_key, display_name=self.ccx.display_name) email_params["email_address"] = "*****@*****.**" email_params["full_name"] = "Jean Reno" return email_params
def setUp(self): super(TestOptoutCourseEmails, self).setUp() course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(display_name=course_title) self.instructor = AdminFactory.create() self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) # load initial content (since we don't run migrations as part of tests): call_command("loaddata", "course_email_template.json") self.client.login(username=self.student.username, password="******") self.send_mail_url = reverse('send_email', kwargs={'course_id': self.course.id.to_deprecated_string()}) self.success_content = { 'course_id': self.course.id.to_deprecated_string(), 'success': True, } BulkEmailFlag.objects.create(enabled=True, require_course_email_auth=False)
def setUp(self): """ Set up tests """ super(TestInstructorDashboardPerformance, self).setUp() self.course = CourseFactory.create( grading_policy={"GRADE_CUTOFFS": {"A": 0.75, "B": 0.63, "C": 0.57, "D": 0.5}}, display_name='<script>alert("XSS")</script>', default_store=ModuleStoreEnum.Type.split ) self.course_mode = CourseMode( course_id=self.course.id, mode_slug=CourseMode.DEFAULT_MODE_SLUG, mode_display_name=CourseMode.DEFAULT_MODE.name, min_price=40 ) self.course_mode.save() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******")
def setUp(self): """ Set up tests """ super(TestInstructorDashboard, self).setUp() self.course = CourseFactory.create( grading_policy={"GRADE_CUTOFFS": {"A": 0.75, "B": 0.63, "C": 0.57, "D": 0.5}}, display_name='<script>alert("XSS")</script>' ) self.course_mode = CourseMode(course_id=self.course.id, mode_slug="honor", mode_display_name="honor cert", min_price=40) self.course_mode.save() # Create instructor account self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") # URL for instructor dash self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})