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 test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ user = UserFactory.create() pre_requisite_course = CourseFactory.create( org='test_org', number='788', run='test_run' ) pre_requisite_courses = [unicode(pre_requisite_course.id)] course = CourseFactory.create( org='test_org', number='786', run='test_run', pre_requisite_courses=pre_requisite_courses ) set_prerequisite_courses(course.id, pre_requisite_courses) # user should not be able to load course even if enrolled CourseEnrollmentFactory(user=user, course_id=course.id) response = access._has_access_course(user, 'load', course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneAccessError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course(staff, 'load', course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course(user, 'load', course))
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ seed_milestone_relationship_types() user = UserFactory.create() pre_requisite_course = CourseFactory.create( org='test_org', number='788', run='test_run' ) pre_requisite_courses = [unicode(pre_requisite_course.id)] course = CourseFactory.create( org='test_org', number='786', run='test_run', pre_requisite_courses=pre_requisite_courses ) set_prerequisite_courses(course.id, pre_requisite_courses) #user should not be able to load course even if enrolled CourseEnrollmentFactory(user=user, course_id=course.id) self.assertFalse(access._has_access_course_desc(user, 'view_courseware_with_prerequisites', course)) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(staff, 'view_courseware_with_prerequisites', course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course_desc(user, 'view_courseware_with_prerequisites', course))
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ user = UserFactory.create() pre_requisite_course = CourseFactory.create(org='test_org', number='788', run='test_run') pre_requisite_courses = [six.text_type(pre_requisite_course.id)] course = CourseFactory.create( org='test_org', number='786', run='test_run', pre_requisite_courses=pre_requisite_courses) set_prerequisite_courses(course.id, pre_requisite_courses) # user should not be able to load course even if enrolled CourseEnrollmentFactory(user=user, course_id=course.id) response = access._has_access_course(user, 'load', course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneAccessError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course(staff, 'load', course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course(user, 'load', course))
def test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = SlashSeparatedCourseKey("edX", "test", "2012_Fall") staff = StaffFactory.create(course_key=course_id) course = Mock(id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT) self.assertTrue(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course)) # Now set visibility to just about page course = Mock( id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_ABOUT ) self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock( id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_NONE ) self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course)) self.assertFalse(access._has_access_course_desc(user, "see_about_page", course)) self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course)) self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course))
def test_access_on_course_with_pre_requisites(self): """ Test course access when a course has pre-requisite course yet to be completed """ seed_milestone_relationship_types() user = UserFactory.create() pre_requisite_course = CourseFactory.create(org="test_org", number="788", run="test_run") pre_requisite_courses = [unicode(pre_requisite_course.id)] course = CourseFactory.create( org="test_org", number="786", run="test_run", pre_requisite_courses=pre_requisite_courses ) set_prerequisite_courses(course.id, pre_requisite_courses) # user should not be able to load course even if enrolled CourseEnrollmentFactory(user=user, course_id=course.id) response = access._has_access_course_desc(user, "view_courseware_with_prerequisites", course) self.assertFalse(response) self.assertIsInstance(response, access_response.MilestoneError) # Staff can always access course staff = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(staff, "view_courseware_with_prerequisites", course)) # User should be able access after completing required course fulfill_course_milestone(pre_requisite_course.id, user) self.assertTrue(access._has_access_course_desc(user, "view_courseware_with_prerequisites", course))
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 test_courseware_page_access_with_staff_user_after_passing_entrance_exam(self): """ Test courseware access page after passing entrance exam but with staff user """ self.logout() staff_user = StaffFactory.create(course_key=self.course.id) self.login(staff_user.email, 'test') CourseEnrollmentFactory(user=staff_user, course_id=self.course.id) self._assert_chapter_loaded(self.course, self.chapter)
def setUp(self): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******', courses=[]) # Make this student a community TA. self.create_and_enroll_student(username='******') seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users['community_ta']) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username='******') # '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 [ ('staff', self.test_course_1), ('course_staff', self.test_course_1), ]: 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(RuntimeEnabledTestCase, self).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 test__has_access_course_desc_can_enroll(self): yesterday = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1) tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) # Non-staff can enroll if authenticated and specifically allowed for that course # even outside the open enrollment period user = UserFactory.create() course = Mock( enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", ) CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Staff can always enroll even outside the open enrollment period user = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Non-staff cannot enroll if it is between the start and end dates and invitation only # and not specifically allowed course = Mock( enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=True, ) user = UserFactory.create() self.assertFalse(access._has_access_course_desc(user, "enroll", course)) # Non-staff can enroll if it is between the start and end dates and not invitation only course = Mock( enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=False, ) self.assertTrue(access._has_access_course_desc(user, "enroll", course)) # Non-staff cannot enroll outside the open enrollment period if not specifically allowed course = Mock( enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), enrollment_domain="", invitation_only=False, ) self.assertFalse(access._has_access_course_desc(user, "enroll", course))
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): """ 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 test_runtime_user_is_staff(self, is_staff): course = CourseFactory.create(org='org', number='bar', display_name='baz') descriptor = ItemFactory(category="pure", parent=course) staff = StaffFactory.create(course_key=course.id) self.runtime, _ = render.get_module_system_for_user( staff if is_staff else User.objects.create(), self.student_data, descriptor, course.id, mock.Mock(), mock.Mock(), mock.Mock(), course=course ) block = self.make_one() assert block.runtime_user_is_staff() is is_staff
def test_runtime_user_is_staff(self, is_staff): course = CourseFactory.create(org='org', number='bar', display_name='baz') descriptor = ItemFactory(category="pure", parent=course) staff = StaffFactory.create(course_key=course.id) self.runtime, _ = render.get_module_system_for_user( staff if is_staff else User.objects.create(), self.student_data, descriptor, course.id, mock.Mock(), mock.Mock(), mock.Mock(), course=course ) block = self.make_one() assert block.runtime_user_is_staff() is is_staff
def test__has_access_course_desc_can_enroll(self): yesterday = datetime.datetime.now( pytz.utc) - datetime.timedelta(days=1) tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1) # Non-staff can enroll if authenticated and specifically allowed for that course # even outside the open enrollment period user = UserFactory.create() course = Mock(enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), enrollment_domain='') CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id) self.assertTrue(access._has_access_course_desc(user, 'enroll', course)) # Staff can always enroll even outside the open enrollment period user = StaffFactory.create(course_key=course.id) self.assertTrue(access._has_access_course_desc(user, 'enroll', course)) # Non-staff cannot enroll if it is between the start and end dates and invitation only # and not specifically allowed course = Mock(enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), enrollment_domain='', invitation_only=True) user = UserFactory.create() self.assertFalse(access._has_access_course_desc( user, 'enroll', course)) # Non-staff can enroll if it is between the start and end dates and not invitation only course = Mock(enrollment_start=yesterday, enrollment_end=tomorrow, id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), enrollment_domain='', invitation_only=False) self.assertTrue(access._has_access_course_desc(user, 'enroll', course)) # Non-staff cannot enroll outside the open enrollment period if not specifically allowed course = Mock(enrollment_start=tomorrow, enrollment_end=tomorrow, id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), enrollment_domain='', invitation_only=False) self.assertFalse(access._has_access_course_desc( user, 'enroll', course))
def setUp(self): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******', courses=[]) # Make this student a community TA. self.create_and_enroll_student(username='******') seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users['community_ta']) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username='******' ) # '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 [ ('staff', self.test_course_1), ('course_staff', self.test_course_1), ]: 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 test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = SlashSeparatedCourseKey('edX', 'test', '2012_Fall') staff = StaffFactory.create(course_key=course_id) course = Mock(id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT) self.assertTrue( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course)) # Now set visibility to just about page course = Mock(id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_ABOUT) self.assertFalse( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock(id=SlashSeparatedCourseKey('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_NONE) self.assertFalse( access._has_access_course_desc(user, 'see_in_catalog', course)) self.assertFalse( access._has_access_course_desc(user, 'see_about_page', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_in_catalog', course)) self.assertTrue( access._has_access_course_desc(staff, 'see_about_page', course))
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 test__catalog_visibility(self): """ Tests the catalog visibility tri-states """ user = UserFactory.create() course_id = CourseLocator('edX', 'test', '2012_Fall') staff = StaffFactory.create(course_key=course_id) course = Mock( id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT ) self.assertTrue(access._has_access_course(user, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course)) # Now set visibility to just about page course = Mock( id=CourseLocator('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_ABOUT ) self.assertFalse(access._has_access_course(user, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course)) # Now set visibility to none, which means neither in catalog nor about pages course = Mock( id=CourseLocator('edX', 'test', '2012_Fall'), catalog_visibility=CATALOG_VISIBILITY_NONE ) self.assertFalse(access._has_access_course(user, 'see_in_catalog', course)) self.assertFalse(access._has_access_course(user, 'see_about_page', course)) self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course)) self.assertTrue(access._has_access_course(staff, 'see_about_page', course))
def setUp(self): super(GroupAccessTestCase, self).setUp() 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): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { "staff": AdminFactory.create(password=self.test_password), "course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password), } self.create_and_enroll_student(username="******") self.create_and_enroll_student(username="******") self.create_and_enroll_student(username="******", courses=[]) # Make this student a community TA. self.create_and_enroll_student(username="******") seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users["community_ta"]) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username="******" ) # Make this student have a public profile self.create_and_enroll_student(courses=[self.test_course_2], username="******") profile = self.users["student_enrolled_public_profile"].profile profile.year_of_birth = 1970 profile.save() # This student is enrolled in the other course, but not yet a member of a team. This is to allow # course_2 to use a max_team_size of 1 without breaking other tests on course_1 self.create_and_enroll_student( courses=[self.test_course_2], username="******" ) with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid="teams.signals.course_team_post_save_callback", ): # '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) self.test_team_6 = CourseTeamFactory.create( name="Public Profile Team", course_id=self.test_course_2.id, topic_id="topic_6" ) self.test_team_7 = CourseTeamFactory.create( name="Search", description="queryable text", country="GS", language="to", course_id=self.test_course_2.id, topic_id="topic_7", ) self.test_team_name_id_map = { team.name: team for team in ( self.test_team_1, self.test_team_2, self.test_team_3, self.test_team_4, self.test_team_5, self.test_team_6, self.test_team_7, ) } for user, course in [("staff", self.test_course_1), ("course_staff", self.test_course_1)]: 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"]) self.test_team_6.add_user(self.users["student_enrolled_public_profile"])
def setUp(self): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******', courses=[]) # Make this student a community TA. self.create_and_enroll_student(username='******') seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users['community_ta']) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username='******') # Make this student have a public profile self.create_and_enroll_student( courses=[self.test_course_2], username='******') profile = self.users['student_enrolled_public_profile'].profile profile.year_of_birth = 1970 profile.save() # This student is enrolled in the other course, but not yet a member of a team. This is to allow # course_2 to use a max_team_size of 1 without breaking other tests on course_1 self.create_and_enroll_student( courses=[self.test_course_2], username='******') # '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) self.test_team_6 = CourseTeamFactory.create( name='Public Profile Team', course_id=self.test_course_2.id, topic_id='topic_6') self.test_team_name_id_map = { team.name: team for team in ( self.test_team_1, self.test_team_2, self.test_team_3, self.test_team_4, self.test_team_5, ) } for user, course in [('staff', self.test_course_1), ('course_staff', self.test_course_1)]: 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']) self.test_team_6.add_user( self.users['student_enrolled_public_profile'])
def setUp(self): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******', courses=[]) # Make this student a community TA. self.create_and_enroll_student(username='******') seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users['community_ta']) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username='******' ) # Make this student have a public profile self.create_and_enroll_student( courses=[self.test_course_2], username='******' ) profile = self.users['student_enrolled_public_profile'].profile profile.year_of_birth = 1970 profile.save() # This student is enrolled in the other course, but not yet a member of a team. This is to allow # course_2 to use a max_team_size of 1 without breaking other tests on course_1 self.create_and_enroll_student( courses=[self.test_course_2], username='******' ) with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid='teams.signals.course_team_post_save_callback' ): self.solar_team = CourseTeamFactory.create( name=u'Sólar team', course_id=self.test_course_1.id, topic_id='topic_0' ) self.wind_team = CourseTeamFactory.create(name='Wind Team', course_id=self.test_course_1.id) self.nuclear_team = CourseTeamFactory.create(name='Nuclear Team', course_id=self.test_course_1.id) self.another_team = CourseTeamFactory.create(name='Another Team', course_id=self.test_course_2.id) self.public_profile_team = CourseTeamFactory.create( name='Public Profile Team', course_id=self.test_course_2.id, topic_id='topic_6' ) self.search_team = CourseTeamFactory.create( name='Search', description='queryable text', country='GS', language='to', course_id=self.test_course_2.id, topic_id='topic_7' ) self.test_team_name_id_map = {team.name: team for team in ( self.solar_team, self.wind_team, self.nuclear_team, self.another_team, self.public_profile_team, self.search_team, )} for user, course in [('staff', self.test_course_1), ('course_staff', self.test_course_1)]: CourseEnrollment.enroll( self.users[user], course.id, check_access=True ) self.solar_team.add_user(self.users['student_enrolled']) self.nuclear_team.add_user(self.users['student_enrolled_both_courses_other_team']) self.another_team.add_user(self.users['student_enrolled_both_courses_other_team']) self.public_profile_team.add_user(self.users['student_enrolled_public_profile'])
def test_access_control(self): """ Test that only topics that a user has access to are returned. The ways in which a user may not have access are: * Module is visible to staff only * Module has a start date in the future * Module is accessible only to a group the user is not in Also, there is a case that ensures that a category with no accessible subcategories does not appear in the result. """ beta_tester = BetaTesterFactory.create(course_key=self.course.id) staff = StaffFactory.create(course_key=self.course.id) for user, group_idx in [(self.user, 0), (beta_tester, 1)]: cohort = CohortFactory.create( course_id=self.course.id, name=self.partition.groups[group_idx].name, users=[user] ) CourseUserGroupPartitionGroup.objects.create( course_user_group=cohort, partition_id=self.partition.id, group_id=self.partition.groups[group_idx].id ) self.make_discussion_module("courseware-1", "First", "Everybody") self.make_discussion_module( "courseware-2", "First", "Cohort A", group_access={self.partition.id: [self.partition.groups[0].id]} ) self.make_discussion_module( "courseware-3", "First", "Cohort B", group_access={self.partition.id: [self.partition.groups[1].id]} ) self.make_discussion_module("courseware-4", "Second", "Staff Only", visible_to_staff_only=True) self.make_discussion_module( "courseware-5", "Second", "Future Start Date", start=datetime.now(UTC) + timedelta(days=1) ) student_actual = self.get_course_topics() student_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-2", "Cohort A"), self.make_expected_tree("courseware-1", "Everybody"), ] ), ], "non_courseware_topics": [], } self.assertEqual(student_actual, student_expected) beta_actual = self.get_course_topics(beta_tester) beta_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-3", "Cohort B"), self.make_expected_tree("courseware-1", "Everybody"), ] ), self.make_expected_tree( None, "Second", [self.make_expected_tree("courseware-5", "Future Start Date")] ), ], "non_courseware_topics": [], } self.assertEqual(beta_actual, beta_expected) staff_actual = self.get_course_topics(staff) staff_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-2", "Cohort A"), self.make_expected_tree("courseware-3", "Cohort B"), self.make_expected_tree("courseware-1", "Everybody"), ] ), self.make_expected_tree( None, "Second", [ self.make_expected_tree("courseware-5", "Future Start Date"), self.make_expected_tree("courseware-4", "Staff Only"), ] ), ], "non_courseware_topics": [], } self.assertEqual(staff_actual, staff_expected)
def setUp(self): super(GroupAccessTestCase, self).setUp() 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): super(TeamAPITestCase, self).setUp() self.topics_count = 4 self.users = { 'staff': AdminFactory.create(password=self.test_password), 'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password) } self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******') self.create_and_enroll_student(username='******', courses=[]) # Make this student a community TA. self.create_and_enroll_student(username='******') seed_permissions_roles(self.test_course_1.id) community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id) community_ta_role.users.add(self.users['community_ta']) # 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. self.create_and_enroll_student( courses=[self.test_course_1, self.test_course_2], username='******' ) # Make this student have a public profile self.create_and_enroll_student( courses=[self.test_course_2], username='******' ) profile = self.users['student_enrolled_public_profile'].profile profile.year_of_birth = 1970 profile.save() # This student is enrolled in the other course, but not yet a member of a team. This is to allow # course_2 to use a max_team_size of 1 without breaking other tests on course_1 self.create_and_enroll_student( courses=[self.test_course_2], username='******' ) # '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) self.test_team_6 = CourseTeamFactory.create( name='Public Profile Team', course_id=self.test_course_2.id, topic_id='topic_6' ) self.test_team_name_id_map = {team.name: team for team in ( self.test_team_1, self.test_team_2, self.test_team_3, self.test_team_4, self.test_team_5, )} for user, course in [('staff', self.test_course_1), ('course_staff', self.test_course_1)]: 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']) self.test_team_6.add_user(self.users['student_enrolled_public_profile'])
def setUp(self): self.output = StringIO.StringIO() self.gzipfile = StringIO.StringIO() self.course = CourseFactory.create( display_name=self.COURSE_NAME, ) self.course.raw_grader = [{ 'drop_count': 0, 'min_count': 1, 'short_label': 'Final', 'type': 'Final Exam', 'weight': 1.0 }] self.course.grade_cutoffs = {'Pass': 0.1} self.students = [ UserFactory.create(username='******'), UserFactory.create(username='******'), UserFactory.create(username='******'), UserFactory.create(username='******'), UserFactory.create(username='******'), StaffFactory.create(username='******', course_key=self.course.id), InstructorFactory.create(username='******', course_key=self.course.id), ] UserStandingFactory.create( user=self.students[4], account_status=UserStanding.ACCOUNT_DISABLED, changed_by=self.students[6] ) for user in self.students: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) self.pgreport = ProgressReport(self.course.id) self.pgreport2 = ProgressReport(self.course.id, lambda state: state) self.chapter = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name="Week 1" ) self.chapter.save() self.section = ItemFactory.create( parent_location=self.chapter.location, category="sequential", display_name="Lesson 1" ) self.section.save() self.vertical = ItemFactory.create( parent_location=self.section.location, category="vertical", display_name="Unit1" ) self.vertical.save() self.html = ItemFactory.create( parent_location=self.vertical.location, category="html", data={'data': "<html>foobar</html>"} ) self.html.save() """ course.children = [week1.location.url(), week2.location.url(), week3.location.url()] """ from capa.tests.response_xml_factory import OptionResponseXMLFactory self.problem_xml = OptionResponseXMLFactory().build_xml( question_text='The correct answer is Correct', num_inputs=2, weight=2, options=['Correct', 'Incorrect'], correct_option='Correct' ) self.problems = [] for num in xrange(1, 3): self.problems.append(ItemFactory.create( parent_location=self.vertical.location, category='problem', display_name='problem_' + str(num), metadata={'graded': True, 'format': 'Final Exam'}, data=self.problem_xml )) self.problems[num - 1].save() for problem in self.problems: problem.correct_map = { unicode(problem.location) + "_2_1": { "hint": "", "hintmode": "", "correctness": "correct", "npoints": "", "msg": "", "queuestate": "" }, unicode(problem.location) + "_2_2": { "hint": "", "hintmode": "", "correctness": "incorrect", "npoints": "", "msg": "", "queuestate": "" } } problem.student_answers = { unicode(problem.location) + "_2_1": "Correct", unicode(problem.location) + "_2_2": "Incorrect" } problem.input_state = { unicode(problem.location) + "_2_1": {}, unicode(problem.location) + "_2_2": {} } self.course.save() patcher = patch('pgreport.views.logging') self.log_mock = patcher.start() self.addCleanup(patcher.stop) """
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='renewable') 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_4 = 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_4.add_user( self.users['student_enrolled_both_courses_other_team'])
def test_access_control(self): """ Test that only topics that a user has access to are returned. The ways in which a user may not have access are: * Module is visible to staff only * Module has a start date in the future * Module is accessible only to a group the user is not in Also, there is a case that ensures that a category with no accessible subcategories does not appear in the result. """ beta_tester = BetaTesterFactory.create(course_key=self.course.id) CourseEnrollmentFactory.create(user=beta_tester, course_id=self.course.id) staff = StaffFactory.create(course_key=self.course.id) for user, group_idx in [(self.user, 0), (beta_tester, 1)]: cohort = CohortFactory.create( course_id=self.course.id, name=self.partition.groups[group_idx].name, users=[user] ) CourseUserGroupPartitionGroup.objects.create( course_user_group=cohort, partition_id=self.partition.id, group_id=self.partition.groups[group_idx].id ) self.make_discussion_module("courseware-1", "First", "Everybody") self.make_discussion_module( "courseware-2", "First", "Cohort A", group_access={self.partition.id: [self.partition.groups[0].id]} ) self.make_discussion_module( "courseware-3", "First", "Cohort B", group_access={self.partition.id: [self.partition.groups[1].id]} ) self.make_discussion_module("courseware-4", "Second", "Staff Only", visible_to_staff_only=True) self.make_discussion_module( "courseware-5", "Second", "Future Start Date", start=datetime.now(UTC) + timedelta(days=1) ) student_actual = self.get_course_topics() student_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-2", "Cohort A"), self.make_expected_tree("courseware-1", "Everybody"), ] ), ], "non_courseware_topics": [ self.make_expected_tree("non-courseware-topic-id", "Test Topic"), ], } self.assertEqual(student_actual, student_expected) beta_actual = self.get_course_topics(beta_tester) beta_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-3", "Cohort B"), self.make_expected_tree("courseware-1", "Everybody"), ] ), self.make_expected_tree( None, "Second", [self.make_expected_tree("courseware-5", "Future Start Date")] ), ], "non_courseware_topics": [ self.make_expected_tree("non-courseware-topic-id", "Test Topic"), ], } self.assertEqual(beta_actual, beta_expected) staff_actual = self.get_course_topics(staff) staff_expected = { "courseware_topics": [ self.make_expected_tree( None, "First", [ self.make_expected_tree("courseware-2", "Cohort A"), self.make_expected_tree("courseware-3", "Cohort B"), self.make_expected_tree("courseware-1", "Everybody"), ] ), self.make_expected_tree( None, "Second", [ self.make_expected_tree("courseware-5", "Future Start Date"), self.make_expected_tree("courseware-4", "Staff Only"), ] ), ], "non_courseware_topics": [ self.make_expected_tree("non-courseware-topic-id", "Test Topic"), ], } self.assertEqual(staff_actual, staff_expected)