def setUp(self): """ Set up tests """ super().setUp() self.ccx = ccx = CustomCourseForEdX(course_id=self.course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('lms.djangoapps.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_all_namespaces) 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 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) assert resp.status_code == status.HTTP_204_NO_CONTENT ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) assert ccx_from_db.max_student_enrollments_allowed == data['max_students_allowed'] assert ccx_from_db.display_name == data['display_name'] assert 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) assert coach_role_on_master_course.has_user(new_coach) # check that the coach has been enrolled in the ccx ccx_course_object = get_course_by_id(self.ccx_key) assert CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=new_coach).exists() # check that an email has been sent to the coach assert len(outbox) == 1 assert new_coach.email in outbox[0].recipients()
def setUp(self): """ Set up courses and enrollments. """ super().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 setUp(self): super(TestGlobalAnnouncements, self).setUp() self.client = Client() self.admin = AdminFactory.create(email='*****@*****.**', username='******', password='******') self.client.login(username=self.admin.username, password='******')
def setUp(self): """ Set up tests """ super().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': str(self.course.id)})
def setUpTestData(cls): # lint-amnesty, pylint: disable=super-method-not-called """ Set up models for the whole TestCase. """ cls.user = UserFactory.create() # Create instructor account cls.coach = AdminFactory.create()
def setUp(self): """Set up a course, coach, ccx and user""" super(TestGetCCXFromCCXLocator, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = CourseFactory.create() coach = self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach)
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().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): super(TestGlobalAnnouncements, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.client = Client() self.admin = AdminFactory.create(email='*****@*****.**', username='******', password='******') self.client.login(username=self.admin.username, password='******')
def setUp(self): """ Set up tests """ super().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 a course, coach, ccx and user""" super().setUp() self.course = CourseFactory.create() coach = self.coach = AdminFactory.create() role = CourseCcxCoachRole(self.course.id) role.add_users(coach)
def setUp(self): """common setup for all tests""" super(TestCCX, self).setUp() self.course = CourseFactory.create() 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)
def setUp(self): super(TestRenderMessageToString, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments 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): """common setup for all tests""" super(TestCCX, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = CourseFactory.create() 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)
def setUp(self): """ Create user and login. """ super().setUp() self.staff_usr = AdminFactory.create() self.non_staff_usr = UserFactory.create() self.client = Client()
def setUp(self): """ Create user and login. """ super(ContentStoreToyCourseTest, self).setUp() self.staff_usr = AdminFactory.create() self.non_staff_usr = UserFactory.create() self.client = Client()
def setUp(self): super(TestAnnouncementsViews, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.admin = AdminFactory.create(email='*****@*****.**', username='******', password='******') self.client.login(username=self.admin.username, password='******') self.non_staff_user = UserFactory.create(email='*****@*****.**', username='******', password='******')
def setUp(self): super().setUp() self.admin = AdminFactory.create(email='*****@*****.**', username='******', password='******') self.client.login(username=self.admin.username, password='******') self.non_staff_user = UserFactory.create(email='*****@*****.**', username='******', password='******')
def setUp(self): """ Create user and login. """ super(ContentStoreToyCourseTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.staff_usr = AdminFactory.create() self.non_staff_usr = UserFactory.create() self.client = Client()
def setUp(self): super(TestNewInstructorDashboardEmailViewXMLBacked, self).setUp() # 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': text_type(self.course_key)}) # URL for email view self.email_link = '<button type="button" class="btn-link send_email" data-section="send_email">Email</button>'
def setUp(self): super().setUp() self.track_function = make_track_function(HttpRequest()) self.student_data = Mock() self.course = self.import_test_course() self.descriptor = ItemFactory(category="pure", parent=self.course) self.course_id = self.course.id self.instructor = StaffFactory.create(course_key=self.course_id) self.runtime = self.make_runtime() self.runtime.error_tracker = None self.staff = AdminFactory.create() self.course.bind_for_student(self.runtime, self.instructor)
def setUp(self): """ Set up tests """ super(TestSendCCXCoursePublished, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments 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(CoachAccessTestCaseCCX, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # 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): super(TestACEOptoutCourseEmails, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments 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): """ Set up tests """ super().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): 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 test_get_task_name(self, is_regeneration, expected): staff = AdminFactory.create() instructor_task = InstructorTaskFactory.create( task_input=json.dumps({}), requester=staff, task_key='', task_id='', ) certificate_generation_history = CertificateGenerationHistory( course_id=instructor_task.course_id, generated_by=staff, instructor_task=instructor_task, is_regeneration=is_regeneration, ) assert certificate_generation_history.get_task_name() == expected
def setUp(self): super().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): """ 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)