Пример #1
0
 def test_scoped_within_course(self):
     """Verify that team count is scoped within a course."""
     duplicate_topic = self.course.teamsets[0].cleaned_data
     second_course = CourseFactory.create(teams_configuration=TeamsConfig({
         "max_team_size":
         10,
         "topics": [duplicate_topic]
     }), )
     CourseTeamFactory.create(course_id=self.course.id,
                              topic_id=duplicate_topic[u'id'])
     CourseTeamFactory.create(course_id=second_course.id,
                              topic_id=duplicate_topic[u'id'])
     with self.assertNumQueries(1):
         serializer = TopicSerializer(
             self.course.teamsets[0].cleaned_data,
             context={'course_id': self.course.id},
         )
         self.assertEqual(
             serializer.data, {
                 u'name': u'Tøpic',
                 u'description': u'The bést topic!',
                 u'id': u'0',
                 u'team_count': 1,
                 u'type': u'open'
             })
Пример #2
0
 def test_scoped_within_course(self):
     """Verify that team count is scoped within a course."""
     duplicate_topic = self.course.teamsets[0].cleaned_data
     second_course = CourseFactory.create(teams_configuration=TeamsConfig({
         "max_team_size":
         10,
         "topics": [duplicate_topic]
     }), )
     CourseTeamFactory.create(course_id=self.course.id,
                              topic_id=duplicate_topic['id'])
     CourseTeamFactory.create(course_id=second_course.id,
                              topic_id=duplicate_topic['id'])
     with self.assertNumQueries(
             3):  # 2 split modulestore MySQL queries, 1 for Teams
         serializer = TopicSerializer(
             self.course.teamsets[0].cleaned_data,
             context={'course_id': self.course.id},
         )
         assert serializer.data == {
             'name': 'Tøpic',
             'description': 'The bést topic!',
             'id': '0',
             'team_count': 1,
             'type': 'open',
             'max_team_size': None
         }
Пример #3
0
 def test_topic_with_no_team_count(self):
     """
     Verifies that the `TopicSerializer` correctly displays a topic with a
     team count of 0, and that it only takes one SQL query.
     """
     with self.assertNumQueries(1):
         serializer = TopicSerializer(
             self.course.teamsets[0].cleaned_data,
             context={'course_id': self.course.id},
         )
         self.assertEqual(
             serializer.data,
             {u'name': u'Tøpic', u'description': u'The bést topic!', u'id': u'0', u'team_count': 0, u'type': u'open'}
         )
Пример #4
0
 def test_topic_with_team_count(self):
     """
     Verifies that the `TopicSerializer` correctly displays a topic with a
     positive team count, and that it only takes one SQL query.
     """
     CourseTeamFactory.create(course_id=self.course.id,
                              topic_id=self.course.teams_topics[0]['id'])
     with self.assertNumQueries(1):
         serializer = TopicSerializer(self.course.teams_topics[0],
                                      context={'course_id': self.course.id})
         self.assertEqual(
             serializer.data, {
                 u'name': u'Tøpic',
                 u'description': u'The bést topic!',
                 u'id': u'0',
                 u'team_count': 1
             })
Пример #5
0
 def test_topic_with_no_team_count(self):
     """
     Verifies that the `TopicSerializer` correctly displays a topic with a
     team count of 0, and that it takes a known number of SQL queries.
     """
     with self.assertNumQueries(2):
         serializer = TopicSerializer(
             self.course.teamsets[0].cleaned_data,
             context={'course_id': self.course.id},
         )
         assert serializer.data == {
             'name': 'Tøpic',
             'description': 'The bést topic!',
             'id': '0',
             'team_count': 0,
             'type': 'open',
             'max_team_size': None
         }
Пример #6
0
 def test_topic_with_team_count(self):
     """
     Verifies that the `TopicSerializer` correctly displays a topic with a
     positive team count, and that it takes a known number of SQL queries.
     """
     CourseTeamFactory.create(course_id=self.course.id,
                              topic_id=self.course.teamsets[0].teamset_id)
     with self.assertNumQueries(2):
         serializer = TopicSerializer(
             self.course.teamsets[0].cleaned_data,
             context={'course_id': self.course.id},
         )
         self.assertEqual(
             serializer.data, {
                 u'name': u'Tøpic',
                 u'description': u'The bést topic!',
                 u'id': u'0',
                 u'team_count': 1,
                 u'type': u'open',
                 u'max_team_size': None
             })