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 setUpTestData(cls): """ Set up models for the whole TestCase. """ cls.user = UserFactory.create() # Create instructor account cls.coach = AdminFactory.create()
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): """ Test case setup """ super(CourseGroupTest, self).setUp() self.global_admin = AdminFactory() self.creator = User.objects.create_user('testcreator', '*****@*****.**', 'foo') self.staff = User.objects.create_user('teststaff', '*****@*****.**', 'foo') self.course_key = CourseLocator('mitX', '101', 'test')
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): 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 setUp(self): super(CourseIdListViewTestCase, self).setUp() self.course = self.create_course() self.url = reverse('course-id-list') self.staff_user = self.create_user(username='******', is_staff=True) self.honor_user = self.create_user(username='******', is_staff=False) self.global_admin = AdminFactory()
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 test_post_permissions_staff(self): """ Verify staff users can create requests for any user. """ admin = AdminFactory(password=self.password) self.client.logout() self.client.login(username=admin.username, password=self.password) response = self.post_credit_request(self.user.username, self.eligibility.course.course_key) assert response.status_code == 200
def create_user_for_course(self, course, user_type=CourseUserType.ENROLLED): """ Create a test user for a course. """ if user_type is CourseUserType.ANONYMOUS: self.client.logout() return AnonymousUser() is_enrolled = user_type is CourseUserType.ENROLLED # Set up the test user if user_type is CourseUserType.UNENROLLED_STAFF: user = StaffFactory(course_key=course.id, password=self.TEST_PASSWORD) elif user_type is CourseUserType.GLOBAL_STAFF: user = AdminFactory(password=self.TEST_PASSWORD) elif user_type is CourseUserType.COURSE_INSTRUCTOR: user = InstructorFactory(course_key=course.id, password=self.TEST_PASSWORD) else: user = UserFactory(password=self.TEST_PASSWORD) self.client.login(username=user.username, password=self.TEST_PASSWORD) if is_enrolled: CourseEnrollment.enroll(user, course.id) return user
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): super().setUp() self.user = AdminFactory() login_success = self.client.login(username=self.user.username, password='******') self.assertTrue(login_success) self.view_url = reverse('maintenance:maintenance_index')
def setUp(self): super(CourseIdListViewTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = self.create_course() self.url = reverse('course-id-list') self.staff_user = self.create_user(username='******', is_staff=True) self.honor_user = self.create_user(username='******', is_staff=False) self.global_admin = AdminFactory()
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): super().setUp() self.admin = AdminFactory() self.user = UserFactory.create(password=self.TEST_PASSWORD) self.other_user = UserFactory.create(password=self.TEST_PASSWORD) self.setup_data(self.STORE_TYPE)
def _verify_cohort_settings_response(self, expected_response): """ Verify that the response was successful and matches the expected JSON payload. """ request = RequestFactory().get("dummy_url") request.user = AdminFactory() response = cohorting_settings(request, str(self.course.id)) assert 200 == response.status_code assert expected_response == json.loads(response.content.decode('utf-8'))
def setUp(self): """ Test case setup """ super().setUp() self.client = Client() user = AdminFactory() self.view_url = reverse('admin:enterprise_override_attributes') self.client.login(username=user.username, password=TEST_PASSWORD) self.users = [] for _ in range(3): self.users.append(UserFactory()) self.course = CourseRunFactory() self.course_id = self.course.get('key') # lint-amnesty, pylint: disable=no-member self.csv_data = [ [self.users[0].id, self.course_id, 'OP_4321'], [self.users[1].id, self.course_id, 'OP_8765'], [self.users[2].id, self.course_id, 'OP_2109'], ] self.csv_data_for_existing_attributes = [ [self.users[0].id, self.course_id, 'OP_1234'], [self.users[1].id, self.course_id, 'OP_5678'], [self.users[2].id, self.course_id, 'OP_9012'], ] for user in self.users: CourseEnrollmentFactory( course_id=self.course_id, user=user )
def setUp(self): super(TestMaintenanceIndex, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = AdminFactory() login_success = self.client.login(username=self.user.username, password='******') self.assertTrue(login_success) self.view_url = reverse('maintenance:maintenance_index')
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): 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 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 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): """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): 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): 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): 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): """ 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): """ Test case setup """ super().setUp() self.global_admin = AdminFactory() self.user = UserFactory.create(username='******', email='*****@*****.**', password='******') self.org = 'mitx' self.course_key = CourseLocator(self.org, '101', 'test')