diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 4ff69caaf1..df5d4a866d 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -143,7 +143,8 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): 'name': 'Public Profiles', 'description': 'Description for topic 6.' }, - ] + ], + 'max_team_size': 1 } cls.test_course_2 = CourseFactory.create( org='MIT', @@ -185,6 +186,13 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): 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='student_enrolled_other_course_not_on_team' + ) + # 'solar team' is intentionally lower case to test case insensitivity in name ordering self.test_team_1 = CourseTeamFactory.create( name=u'sólar team', @@ -956,6 +964,14 @@ class TestCreateMembershipAPI(TeamAPITestCase): ) self.assertIn('not enrolled', json.loads(response.content)['developer_message']) + def test_over_max_team_size_in_course_2(self): + response = self.post_create_membership( + 400, + self.build_membership_data('student_enrolled_other_course_not_on_team', self.test_team_5), + user='student_enrolled_other_course_not_on_team' + ) + self.assertIn('full', json.loads(response.content)['developer_message']) + @ddt.ddt class TestDetailMembershipAPI(TeamAPITestCase): diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index 4dcc7e45de..9e5c113983 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -914,6 +914,13 @@ class MembershipListView(ExpandableFieldViewMixin, GenericAPIView): except User.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) + course_module = modulestore().get_course(team.course_id) + if course_module.teams_max_size is not None and team.users.count() >= course_module.teams_max_size: + return Response( + build_api_error(ugettext_noop("This team is already full.")), + status=status.HTTP_400_BAD_REQUEST + ) + try: membership = team.add_user(user) except AlreadyOnTeamInCourse: