def test_order_by_team_count_secondary(self): """ Ensure that the secondary sort (alphabetical) when primary sort is team_count works across pagination boundaries. """ with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid='teams.signals.course_team_post_save_callback' ): # Add 2 teams to "Wind Power", which previously had no teams. CourseTeamFactory.create( name=u'Wind Team 1', course_id=self.test_course_1.id, topic_id='topic_1' ) CourseTeamFactory.create( name=u'Wind Team 2', course_id=self.test_course_1.id, topic_id='topic_1' ) topics = self.get_topics_list(data={ 'course_id': self.test_course_1.id, 'page_size': 2, 'page': 1, 'order_by': 'team_count' }) self.assertEqual(["Wind Power", u'Sólar power'], [topic['name'] for topic in topics['results']]) topics = self.get_topics_list(data={ 'course_id': self.test_course_1.id, 'page_size': 2, 'page': 2, 'order_by': 'team_count' }) self.assertEqual(["Coal Power", "Nuclear Power"], [topic['name'] for topic in topics['results']])
def test_order_by(self, field, status, names): # Make "Solar team" the most recently active team. # The CourseTeamFactory sets the last_activity_at to a fixed time (in the past), so all of the # other teams have the same last_activity_at. with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid='teams.signals.course_team_post_save_callback' ): solar_team = self.test_team_name_id_map[u'Sólar team'] solar_team.last_activity_at = datetime.utcnow().replace(tzinfo=pytz.utc) solar_team.save() data = {'order_by': field} if field else {} self.verify_names(data, status, names)
def test_order_by(self, field, status, names, expected_ordering): with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid="teams.signals.course_team_post_save_callback", ): # Add 2 teams to "Nuclear Power", which previously had no teams. CourseTeamFactory.create(name=u"Nuclear Team 1", course_id=self.test_course_1.id, topic_id="topic_2") CourseTeamFactory.create(name=u"Nuclear Team 2", course_id=self.test_course_1.id, topic_id="topic_2") data = {"course_id": self.test_course_1.id} if field: data["order_by"] = field topics = self.get_topics_list(status, data) if status == 200: self.assertEqual(names, [topic["name"] for topic in topics["results"]]) self.assertEqual(topics["sort_order"], expected_ordering)
def test_order_by(self, field, status, names, expected_ordering): with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid='teams.signals.course_team_post_save_callback' ): # Add 2 teams to "Nuclear Power", which previously had no teams. CourseTeamFactory.create( name=u'Nuclear Team 1', course_id=self.test_course_1.id, topic_id='topic_2' ) CourseTeamFactory.create( name=u'Nuclear Team 2', course_id=self.test_course_1.id, topic_id='topic_2' ) data = {'course_id': self.test_course_1.id} if field: data['order_by'] = field topics = self.get_topics_list(status, data) if status == 200: self.assertEqual(names, [topic['name'] for topic in topics['results']]) self.assertEqual(topics['sort_order'], expected_ordering)
def test_order_by_team_count_secondary(self): """ Ensure that the secondary sort (alphabetical) when primary sort is team_count works across pagination boundaries. """ with skip_signal( post_save, receiver=course_team_post_save_callback, sender=CourseTeam, dispatch_uid="teams.signals.course_team_post_save_callback", ): # Add 2 teams to "Wind Power", which previously had no teams. CourseTeamFactory.create(name=u"Wind Team 1", course_id=self.test_course_1.id, topic_id="topic_1") CourseTeamFactory.create(name=u"Wind Team 2", course_id=self.test_course_1.id, topic_id="topic_1") topics = self.get_topics_list( data={"course_id": self.test_course_1.id, "page_size": 2, "page": 1, "order_by": "team_count"} ) self.assertEqual(["Wind Power", u"sólar power"], [topic["name"] for topic in topics["results"]]) topics = self.get_topics_list( data={"course_id": self.test_course_1.id, "page_size": 2, "page": 2, "order_by": "team_count"} ) self.assertEqual(["Coal Power", "Nuclear Power"], [topic["name"] for topic in topics["results"]])
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 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"])