Skip to content

Commit

Permalink
EDUCATOR-5210 (#128)
Browse files Browse the repository at this point in the history
* EDUCATOR-5210 - don't create submissions for learners that already had a team submissions

* EDUCATOR-5210 - import order fix

* EDUCATOR-5210 - CRs

* EDUCATOR-5210 - CRs 2

* EDUCATOR-5210 - CRs 3
  • Loading branch information
Andytr1 authored Aug 18, 2020
1 parent d34d96c commit b2aa629
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 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.0'
__version__ = '3.2.1'
14 changes: 13 additions & 1 deletion submissions/team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_submission_for_team(
"""
This api function:
1. Creates a `TeamSubmission` record, and
2. Creates `Submission` records for every member of the team by calling api.create_submission()
2. Creates `Submission` records for ONLY those team members that don't have any past submissions
This means that the ORA `SubmissionMixin` must first collect all of the files of the submitting user
and the team into the `answer` dict.
Expand Down Expand Up @@ -137,7 +137,19 @@ def create_submission_for_team(
'item_id': item_id,
'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
)}
for team_member_id in team_member_ids:
if team_member_id in students_with_team_submissions:
continue
team_member_student_item_dict = dict(base_student_item_dict)
team_member_student_item_dict['student_id'] = team_member_id
_api.create_submission(
Expand Down
45 changes: 34 additions & 11 deletions submissions/tests/test_team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,46 @@ def test_create_submission_for_team_existing_individual_submission(self):
"""
Test for calling create_submission_for_team when a user somehow already has
an existing active submission for the item.
For normal Submissions, if a submission exists and we create another one, the second
will increment the first's attempt_number. However, for team submissions, we currently
pass the attempt_number from team_api.create_submission to api.create_submission, so
all created individual submissions will have the same attempt_number
This can happen if a user was on a team that submitted and then is reassigned to a team
that didn't have a submission and is submitting.
Expected outcome: submission is created because the previous submission was not team based
"""
user_3_item = self._get_or_create_student_item(self.anonymous_user_id_map[self.user_3])
SubmissionFactory.create(student_item=user_3_item)
team_submission_data = self._call_create_submission_for_team_with_default_args()
self.assertEqual(team_submission_data['attempt_number'], 1)
submissions = Submission.objects.select_related(
submission_student_ids = [sub.student_item.student_id for sub in Submission.objects.select_related(
'student_item'
).filter(
uuid__in=team_submission_data['submission_uuids']
).all()
for submission in submissions:
self.assertEqual(submission.attempt_number, 1)
).filter(uuid__in=team_submission_data['submission_uuids']).all()]
self.assertIn(user_3_item.student_id, submission_student_ids)

def test_create_submission_for_team_after_reassignment(self):
"""
Call create_submission twice to simulate attempting a submission of a learner(s) that was reassigned to a
different team.
Expected outcome: No submissions created.
"""
self._call_create_submission_for_team_with_default_args()
# To simulate reassignment, call create_submission with a different team id.
# no new submissions should be created as a result of this call. Therefore, the total number of submission
# models is 4 (see self.student_ids).
team_api.create_submission_for_team(
COURSE_ID,
ITEM_1_ID,
TEAM_2_ID,
self.user_1.id,
[self.anonymous_user_id_map[self.user_1], '55555555555555555555555555555555',
'66666666666666666666666666666666'],
ANSWER
)
ids = [sub.student_item.student_id for sub in Submission.objects.select_related('student_item').all()]
# We simulated reassignment by using a different team id in the call to create_submission. Therefore, 6
# submissions should exist: 4 from the first call and 2 from the second call. We would not createa
# submission for user_1 in the second call because she already has a submission from the first call.
self.assertEqual(6, len(ids))
# this assert checks that there is one and only one (no duplicate - which would indicate a double submission)
# student id
self.assertEqual(len(ids), len(set(ids)))

@mock.patch('submissions.api._log_submission')
def test_create_submission_for_team_error_creating_individual_submission(self, mocked_log_submission):
Expand Down

0 comments on commit b2aa629

Please sign in to comment.