From 8f6e954cfe6e1e5d721ebec40af7ac278c596384 Mon Sep 17 00:00:00 2001 From: Sam Sciolla Date: Mon, 10 Aug 2020 11:56:55 -0400 Subject: [PATCH 1/2] Add strip call on login_id in create_sub_records crosswalk --- pe/orchestration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pe/orchestration.py b/pe/orchestration.py index b3f1fd5..67db7ed 100644 --- a/pe/orchestration.py +++ b/pe/orchestration.py @@ -127,7 +127,7 @@ def create_sub_records(self, sub_dicts: List[Dict[str, Any]]) -> None: submission_id=sub_dict['id'], attempt_num=sub_dict['attempt'], exam=self.exam, - student_uniqname=sub_dict['user']['login_id'], + student_uniqname=sub_dict['user']['login_id'].strip(), submitted_timestamp=sub_dict['submitted_at'], graded_timestamp=sub_dict['graded_at'], score=sub_dict['score'], From f5665d39ffea440065621e9364a9f3ce04f6446e Mon Sep 17 00:00:00 2001 From: Sam Sciolla Date: Mon, 10 Aug 2020 11:57:54 -0400 Subject: [PATCH 2/2] Add fixtures and unit test for login_id whitespace stripping --- test/api_fixtures/canvas_subs.json | 24 ++++++++++++++++++++++++ test/test_orch.py | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/test/api_fixtures/canvas_subs.json b/test/api_fixtures/canvas_subs.json index 185c0c2..02a4229 100644 --- a/test/api_fixtures/canvas_subs.json +++ b/test/api_fixtures/canvas_subs.json @@ -25,6 +25,30 @@ } } ], + "Potions_Placement_3": [ + { + "id": 123461, + "attempt": 1, + "score": 450.0, + "submitted_at": "2020-06-15T21:00:00Z", + "assignment_id": 111112, + "graded_at": "2020-06-15T21:30:00Z", + "user": { + "login_id": " visitor_one@magicking.edu " + } + }, + { + "id": 123462, + "attempt": 1, + "score": 375.0, + "submitted_at": "2020-06-16T01:15:00Z", + "assignment_id": 111112, + "graded_at": "2020-06-16T12:01:00Z", + "user": { + "login_id": "\tvisitor_two@magicking.edu\n" + } + } + ], "Potions_Validation_1": [ { "id": 444444, diff --git a/test/test_orch.py b/test/test_orch.py index 07ac375..87c14ff 100644 --- a/test/test_orch.py +++ b/test/test_orch.py @@ -45,6 +45,7 @@ def setUp(self): self.canvas_potions_val_subs: List[Dict[str, Any]] = canvas_subs_dict['Potions_Validation_1'] self.canvas_dada_place_subs_one: List[Dict[str, Any]] = canvas_subs_dict['DADA_Placement_1'] self.canvas_dada_place_subs_two: List[Dict[str, Any]] = canvas_subs_dict['DADA_Placement_2'] + self.canvas_potions_place_subs_three: List[Dict[str, Any]] = canvas_subs_dict['Potions_Placement_3'] with open(os.path.join(API_FIXTURES_DIR, 'mpathways_resp_data.json'), 'r') as mpathways_resp_data_file: self.mpathways_resp_data: List[Dict[str, Any]] = json.loads(mpathways_resp_data_file.read()) @@ -217,6 +218,16 @@ def test_create_sub_records_with_null_submitted_timestamp_and_attempt_num(self): } ) + def test_create_sub_records_strips_whitespace_in_login_id(self): + """create_sub_records strips leading and trailing whitespace characters from Canvas login_ids.""" + potions_place_exam: Exam = Exam.objects.get(id=1) + some_orca: ScoresOrchestration = ScoresOrchestration(self.api_handler, potions_place_exam) + some_orca.create_sub_records(self.canvas_potions_place_subs_three) + + latest_two_subs: List[Submission] = list(Submission.objects.filter(exam=potions_place_exam).order_by('-id'))[:2] + uniqnames: List[str] = [sub.student_uniqname for sub in latest_two_subs] + self.assertEqual(uniqnames, ['visitor_two@magicking.edu', 'visitor_one@magicking.edu']) + def test_send_scores_when_successful(self): """ send_scores properly transmits data to M-Pathways API and updates all submission records.