Skip to content

Commit

Permalink
Merge pull request #129 from muselesscreator/external_submissions
Browse files Browse the repository at this point in the history
add get_teammates_with_submissions_from_other_teams
  • Loading branch information
muselesscreator authored Aug 21, 2020
2 parents b2aa629 + 5e09ecc commit 98793cf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
2 changes: 1 addition & 1 deletion submissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" API for creating submissions and scores. """
__version__ = '3.2.1'
__version__ = '3.2.2'
51 changes: 42 additions & 9 deletions submissions/team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ def create_submission_for_team(
'item_type': item_type
}

students_with_team_submissions = {student_item.student_id for student_item in StudentItem.objects.filter(
submission__team_submission__isnull=False
).exclude(
submission__team_submission__team_id=team_id
).filter(
student_id__in=team_member_ids,
course_id=course_id,
item_id=item_id
)}
students_with_team_submissions = {
submission['student_id'] for submission in get_teammates_with_submissions_from_other_teams(
course_id,
item_id,
team_id,
team_member_ids
)
}
for team_member_id in team_member_ids:
if team_member_id in students_with_team_submissions:
continue
Expand Down Expand Up @@ -192,6 +191,40 @@ def _log_team_submission(team_submission_data):
)


def get_teammates_with_submissions_from_other_teams(
course_id,
item_id,
team_id,
team_member_ids,
):
"""
This api function returns a list of dicts for students on this team that have submitted
a response to the given item under another team.
Parameters:
- course_id (str): the course id for which we are checking for submissions
- item_id (str): the item id for which we are checking for submissions
- team_id (str): the team_id of the team for which we are making the query
- team_member_ids (list of str): a list of the anonymous user ids associated with all members of the team
Returns:
list(dict): [{ 'student_id', 'team_id' }]
"""
items = StudentItem.objects.filter(
submission__team_submission__isnull=False
).exclude(
submission__team_submission__team_id=team_id
).filter(
student_id__in=team_member_ids,
course_id=course_id,
item_id=item_id
).values("student_id", "submission__team_submission__team_id")
return [{
'student_id': item['student_id'],
'team_id': item['submission__team_submission__team_id']
} for item in items]


def get_team_submission(team_submission_uuid):
"""
Returns a single, serialized, team submission for the given key.
Expand Down
41 changes: 41 additions & 0 deletions submissions/tests/test_team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,47 @@ def test_create_submission_for_team_error_creating_individual_submission(self, m
self.assertEqual(TeamSubmission.objects.count(), 0)
self.assertEqual(Submission.objects.count(), 0)

def test_get_teammates_with_submissions_from_other_teams(self):
# Make a team submission with default users, under TEAM_1
self._make_team_submission(
attempt_number=1,
course_id=COURSE_ID,
item_id=ITEM_1_ID,
team_id=TEAM_1_ID,
status=None,
create_submissions=True
)
# Check against TEAM_2 with 2 additional user IDs added (that don't have a submission)
team_ids = [
self.anonymous_user_id_map[student] for student in [
self.user_1, self.user_2, self.user_3, self.user_4
]
] + ['55555555555555', '666666666666666666']

with self.assertNumQueries(1):
external_submissions = team_api.get_teammates_with_submissions_from_other_teams(
COURSE_ID,
ITEM_1_ID,
TEAM_2_ID,
team_ids
)

# Should get 1 entry for each of the default users
self.assertEqual(len(external_submissions), 4)

def check_submission(submission, user):
self.assertEqual(
submission,
{
'student_id': self.anonymous_user_id_map[user],
'team_id': TEAM_1_ID
}
)
check_submission(external_submissions[0], self.user_1)
check_submission(external_submissions[1], self.user_2)
check_submission(external_submissions[2], self.user_3)
check_submission(external_submissions[3], self.user_4)

def test_get_team_submission(self):
"""
Test that calling team_api.get_team_submission returns the expected team submission
Expand Down

0 comments on commit 98793cf

Please sign in to comment.