Commit 69886290 by Eric Fischer

Merge pull request #9322 from edx/efischer/tnl3061-rc-branch

Validating team size on join, server-side
parents 1b08d940 fc6930a5
......@@ -140,7 +140,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',
......@@ -182,6 +183,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',
......@@ -935,6 +943,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):
......
......@@ -51,7 +51,6 @@ from .serializers import (
)
from .errors import AlreadyOnTeamInCourse, NotEnrolledInCourseForTeam
TEAM_MEMBERSHIPS_PER_PAGE = 2
TOPICS_PER_PAGE = 12
......@@ -889,6 +888,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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment