Пример #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['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
         }
Пример #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[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'
             })
Пример #3
0
    def test_load_course_teams(self):
        """
        Loading course teams should get the users by team with only 2 queries
        1 for teams, 1 for user count
        """
        for _ in range(4):
            CourseTeamFactory.create(course_id=self.course.id)

        with self.assertNumQueries(2):
            self.import_manager.load_course_teams()
Пример #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_load_course_teams(self):
        """
        Lodaing course teams shold get the users by team with only 2 queries
        1 for teams, 1 for user count
        """
        team1 = CourseTeamFactory.create(course_id=self.course.id)
        team2 = CourseTeamFactory.create(course_id=self.course.id)
        team3 = CourseTeamFactory.create(course_id=self.course.id)
        team4 = CourseTeamFactory.create(course_id=self.course.id)

        with self.assertNumQueries(2):
            self.import_manager.load_course_teams()
Пример #6
0
 def test_scoped_within_course(self):
     """Verify that team counts are scoped within a course."""
     teams_per_topic = 10
     first_course_topics = self.setup_topics(num_topics=self.NUM_TOPICS, teams_per_topic=teams_per_topic)
     duplicate_topic = first_course_topics[0]
     second_course = CourseFactory.create(
         teams_configuration={
             "max_team_size": 10,
             "topics": [duplicate_topic]
         }
     )
     CourseTeamFactory.create(course_id=second_course.id, topic_id=duplicate_topic[u'id'])
     self.assert_serializer_output(first_course_topics, num_teams_per_topic=teams_per_topic, num_queries=1)
Пример #7
0
 def test_scoped_within_course(self):
     """Verify that team counts are scoped within a course."""
     teams_per_topic = 10
     first_course_topics = self.setup_topics(num_topics=self.NUM_TOPICS, teams_per_topic=teams_per_topic)
     duplicate_topic = first_course_topics[0]
     second_course = CourseFactory.create(
         teams_configuration=TeamsConfig({
             "max_team_size": 10,
             "topics": [duplicate_topic]
         }),
     )
     CourseTeamFactory.create(course_id=second_course.id, topic_id=duplicate_topic[u'id'])
     self.assert_serializer_output(first_course_topics, num_teams_per_topic=teams_per_topic, num_queries=1)
Пример #8
0
 def setup_topics(self, num_topics=5, teams_per_topic=0):
     """
     Helper method to set up topics on the course.  Returns a list of
     created topics.
     """
     self.course.teams_configuration['topics'] = []
     topics = [
         {u'name': u'Tøpic {}'.format(i), u'description': u'The bést topic! {}'.format(i), u'id': unicode(i)}
         for i in xrange(num_topics)
     ]
     for i in xrange(num_topics):
         topic_id = unicode(i)
         self.course.teams_configuration['topics'].append(topics[i])
         for _ in xrange(teams_per_topic):
             CourseTeamFactory.create(course_id=self.course.id, topic_id=topic_id)
     return topics
Пример #9
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
             })
Пример #10
0
 def test_scoped_within_course(self):
     """Verify that team count is scoped within a course."""
     duplicate_topic = self.course.teams_topics[0]
     second_course = CourseFactory.create(
         teams_configuration={
             "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.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}
         )
Пример #11
0
 def setUp(self):
     super(MembershipSerializerTestCase, self).setUp()
     self.team = CourseTeamFactory.create(
         course_id=self.course.id,
         topic_id=self.course.teamsets[0].teamset_id,
     )
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
     self.team_membership = CourseTeamMembershipFactory.create(team=self.team, user=self.user)
Пример #12
0
 def setUp(self):
     super(MembershipSerializerTestCase, self).setUp()
     self.team = CourseTeamFactory.create(
         course_id=self.course.id,
         topic_id=self.course.teams_topics[0]['id']
     )
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
     self.team_membership = CourseTeamMembershipFactory.create(team=self.team, user=self.user)
Пример #13
0
 def setup_topics(self, num_topics=5, teams_per_topic=0):
     """
     Helper method to set up topics on the course.  Returns a list of
     created topics.
     """
     self.course.teams_configuration['topics'] = []
     topics = [{
         u'name': u'Tøpic {}'.format(i),
         u'description': u'The bést topic! {}'.format(i),
         u'id': unicode(i)
     } for i in xrange(num_topics)]
     for i in xrange(num_topics):
         topic_id = unicode(i)
         self.course.teams_configuration['topics'].append(topics[i])
         for _ in xrange(teams_per_topic):
             CourseTeamFactory.create(course_id=self.course.id,
                                      topic_id=topic_id)
     return topics
Пример #14
0
 def setUp(self):
     super(TeamsServiceTests, self).setUp()
     self.course_run = CourseRunFactory.create()
     self.course_key = self.course_run['key']
     self.team = CourseTeamFactory.create(course_id=self.course_key)
     self.service = TeamsService()
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course_key)
     self.team.add_user(self.user)
Пример #15
0
 def setUp(self):
     super(TeamsServiceTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course_run = CourseRunFactory.create()
     self.course_key = self.course_run['key']
     self.team = CourseTeamFactory.create(course_id=self.course_key)
     self.service = TeamsService()
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user,
                                    course_id=self.course_key)
     self.team.add_user(self.user)
Пример #16
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},
         )
         assert serializer.data == {
             'name': 'Tøpic',
             'description': 'The bést topic!',
             'id': '0',
             'team_count': 1,
             'type': 'open',
             'max_team_size': None
         }
Пример #17
0
 def setUp(self):
     super(MembershipSerializerTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.team = CourseTeamFactory.create(
         course_id=self.course.id,
         topic_id=self.course.teamsets[0].teamset_id,
     )
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user,
                                    course_id=self.course.id)
     self.team_membership = CourseTeamMembershipFactory.create(
         team=self.team, user=self.user)
Пример #18
0
 def setup_topics(self, num_topics=5, teams_per_topic=0):
     """
     Helper method to set up topics on the course.  Returns a list of
     created topics.
     """
     topics = [{
         u'name': u'Tøpic {}'.format(i),
         u'description': u'The bést topic! {}'.format(i),
         u'id': six.text_type(i)
     } for i in six.moves.range(num_topics)]
     for topic in topics:
         for _ in six.moves.range(teams_per_topic):
             CourseTeamFactory.create(course_id=self.course.id,
                                      topic_id=topic['id'])
     self.course.teams_configuration = TeamsConfig({
         'max_team_size':
         self.course.teams_configuration.default_max_team_size,
         'topics':
         topics,
     })
     return topics
Пример #19
0
    def setup_team(self):
        """ Set up a team with teammates and StudentModules """
        # Make users
        self.teammate_a = UserFactory()
        self.teammate_b = UserFactory()
        # This teammate has never opened the assignment so they don't have a state
        self.lazy_teammate = UserFactory()

        # Enroll users in course, so we can add them to the team with add_user
        CourseEnrollment.enroll(self.user, self.course_key)
        CourseEnrollment.enroll(self.teammate_a, self.course_key)
        CourseEnrollment.enroll(self.teammate_b, self.course_key)
        CourseEnrollment.enroll(self.lazy_teammate, self.course_key)

        # Make team
        self.team = CourseTeamFactory.create(
            course_id=self.course_key,
            topic_id=self.team_enabled_ora.selected_teamset_id)
        # Add users to team
        self.team.add_user(self.user)
        self.team.add_user(self.teammate_a)
        self.team.add_user(self.teammate_b)
        self.team.add_user(self.lazy_teammate)

        # Create student modules for everyone but lazy_student
        self.team_state_dict = {
            'attempts':
            1,
            'saved_files_descriptions': ['summary', 'proposal', 'diagrams'],
            'saved_files_sizes': [1364677, 958418],
            'saved_files_names':
            ['case_study_abstract.txt', 'design_prop.pdf', 'diagram1.png']
        }
        team_state = json.dumps(self.team_state_dict)

        StudentModule.objects.create(
            student=self.user,
            course_id=self.course_key,
            module_state_key=self.team_enabled_ora.location,
            state=team_state,
        )
        StudentModule.objects.create(
            student=self.teammate_a,
            course_id=self.course_key,
            module_state_key=self.team_enabled_ora.location,
            state=team_state,
        )
        StudentModule.objects.create(
            student=self.teammate_b,
            course_id=self.course_key,
            module_state_key=self.team_enabled_ora.location,
            state=team_state,
        )
Пример #20
0
    def test_get_team_names(self):
        """
        get_team_names will return a dict mapping the team id to the team name for all teams in the given teamset
        """
        additional_teams = [
            CourseTeamFactory.create(course_id=self.course_key,
                                     topic_id=self.team.topic_id)
            for _ in range(3)
        ]

        result = self.service.get_team_names(self.course_key,
                                             self.team.topic_id)

        assert result == {
            self.team.team_id: self.team.name,
            additional_teams[0].team_id: additional_teams[0].name,
            additional_teams[1].team_id: additional_teams[1].name,
            additional_teams[2].team_id: additional_teams[2].name,
        }
Пример #21
0
 def setUp(self):
     super(TeamsServiceTests, self).setUp()
     self.course_run = CourseRunFactory.create()
     self.team = CourseTeamFactory.create(course_id=self.course_run['key'])
     self.service = TeamsService()