From a19702ad17c5545f1dd6531e36d116830f17634f Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Wed, 19 Aug 2020 14:21:14 -0400 Subject: [PATCH 1/6] add get_submissions_from_other_teams --- submissions/team_api.py | 51 ++++++++++++++++++++++++------ submissions/tests/test_team_api.py | 38 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/submissions/team_api.py b/submissions/team_api.py index 0898b26..4c13761 100644 --- a/submissions/team_api.py +++ b/submissions/team_api.py @@ -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_submissions_from_other_teams( + team_member_ids, + team_id, + item_id, + course_id + ) + ] for team_member_id in team_member_ids: if team_member_id in students_with_team_submissions: continue @@ -192,6 +191,40 @@ def _log_team_submission(team_submission_data): ) +def get_submissions_from_other_teams( + team_member_ids, + team_id, + item_id, + course_id, +): + """ + This api function returns a list of objects for students on this team that have submitted + a response to the given item under another team. + + Parameters: + - team_member_ids (list of str): a list of the anonymous user ids associated with all members of the team + - team_id (str): the team_id for the team for which we are making the submission + - item_id (str): the item id for this team submission + - course_id (str): the course id for this team submission + + Returns: + set: { '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. diff --git a/submissions/tests/test_team_api.py b/submissions/tests/test_team_api.py index d3f8da9..1170716 100644 --- a/submissions/tests/test_team_api.py +++ b/submissions/tests/test_team_api.py @@ -261,6 +261,44 @@ 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_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'] + external_submissions = team_api.get_submissions_from_other_teams( + team_ids, + TEAM_2_ID, + ITEM_1_ID, + COURSE_ID + ) + + # 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 From 5f50975e17cc0e129c734ea5cd5c5b05ab74d36c Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Thu, 20 Aug 2020 11:56:56 -0400 Subject: [PATCH 2/6] quality --- submissions/tests/test_team_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/submissions/tests/test_team_api.py b/submissions/tests/test_team_api.py index 1170716..3516064 100644 --- a/submissions/tests/test_team_api.py +++ b/submissions/tests/test_team_api.py @@ -286,6 +286,7 @@ def test_get_submissions_from_other_teams(self): # Should get 1 entry for each of the default users self.assertEqual(len(external_submissions), 4) + def check_submission(submission, user): self.assertEqual( submission, From d148668b9ab09a615c3f2ebd8dc289bfbac6c1e4 Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Fri, 21 Aug 2020 10:27:10 -0400 Subject: [PATCH 3/6] update test, function name, args, and docstring for PR review --- submissions/team_api.py | 26 +++++++++++++------------- submissions/tests/test_team_api.py | 16 +++++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/submissions/team_api.py b/submissions/team_api.py index 4c13761..fa948c4 100644 --- a/submissions/team_api.py +++ b/submissions/team_api.py @@ -139,11 +139,11 @@ def create_submission_for_team( } students_with_team_submissions = [ - submission['student_id'] for submission in get_submissions_from_other_teams( - team_member_ids, - team_id, + submission['student_id'] for submission in get_teammates_with_submissions_from_other_teams( + course_id, item_id, - course_id + team_id, + team_member_ids ) ] for team_member_id in team_member_ids: @@ -191,24 +191,24 @@ def _log_team_submission(team_submission_data): ) -def get_submissions_from_other_teams( - team_member_ids, - team_id, - item_id, +def get_teammates_with_submissions_from_other_teams( course_id, + item_id, + team_id, + team_member_ids, ): """ - This api function returns a list of objects for students on this team that have submitted + 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 - - team_id (str): the team_id for the team for which we are making the submission - - item_id (str): the item id for this team submission - - course_id (str): the course id for this team submission Returns: - set: { 'student_id', 'team_id' } + (dict): { 'student_id', 'team_id' } """ items = StudentItem.objects.filter( submission__team_submission__isnull=False diff --git a/submissions/tests/test_team_api.py b/submissions/tests/test_team_api.py index 3516064..746fdec 100644 --- a/submissions/tests/test_team_api.py +++ b/submissions/tests/test_team_api.py @@ -261,7 +261,7 @@ 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_submissions_from_other_teams(self): + 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, @@ -277,12 +277,14 @@ def test_get_submissions_from_other_teams(self): self.user_1, self.user_2, self.user_3, self.user_4 ] ] + ['55555555555555', '666666666666666666'] - external_submissions = team_api.get_submissions_from_other_teams( - team_ids, - TEAM_2_ID, - ITEM_1_ID, - COURSE_ID - ) + + 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) From 69b70d3f50320103c8b64a7728d768081052e9f5 Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Fri, 21 Aug 2020 10:41:09 -0400 Subject: [PATCH 4/6] version 3.2.2 --- submissions/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submissions/__init__.py b/submissions/__init__.py index cce9126..50d8344 100644 --- a/submissions/__init__.py +++ b/submissions/__init__.py @@ -1,2 +1,2 @@ """ API for creating submissions and scores. """ -__version__ = '3.2.1' +__version__ = '3.2.2' From b0854695639ff673fc130547438eda1eee27a4cd Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Fri, 21 Aug 2020 10:56:41 -0400 Subject: [PATCH 5/6] add set logic back around query in create_submission_for_team --- submissions/team_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/submissions/team_api.py b/submissions/team_api.py index fa948c4..e51eb7b 100644 --- a/submissions/team_api.py +++ b/submissions/team_api.py @@ -138,14 +138,14 @@ def create_submission_for_team( 'item_type': item_type } - students_with_team_submissions = [ + 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 From 5e09ecc5c46d1e9306ff29b898454699d6553bb6 Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Fri, 21 Aug 2020 11:21:37 -0400 Subject: [PATCH 6/6] update docstring --- submissions/team_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submissions/team_api.py b/submissions/team_api.py index e51eb7b..60b60e1 100644 --- a/submissions/team_api.py +++ b/submissions/team_api.py @@ -208,7 +208,7 @@ def get_teammates_with_submissions_from_other_teams( - team_member_ids (list of str): a list of the anonymous user ids associated with all members of the team Returns: - (dict): { 'student_id', 'team_id' } + list(dict): [{ 'student_id', 'team_id' }] """ items = StudentItem.objects.filter( submission__team_submission__isnull=False