Skip to content

Commit

Permalink
Merge pull request #39 from ssciolla/issue-36-strip-whitespace
Browse files Browse the repository at this point in the history
Strip whitespace characters from Canvas login_id values (#36)
  • Loading branch information
ssciolla committed Aug 10, 2020
2 parents 575f87b + f5665d3 commit 8beb924
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pe/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
24 changes: 24 additions & 0 deletions test/api_fixtures/canvas_subs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": " [email protected] "
}
},
{
"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": "\t[email protected]\n"
}
}
],
"Potions_Validation_1": [
{
"id": 444444,
Expand Down
11 changes: 11 additions & 0 deletions test/test_orch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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, ['[email protected]', '[email protected]'])

def test_send_scores_when_successful(self):
"""
send_scores properly transmits data to M-Pathways API and updates all submission records.
Expand Down

0 comments on commit 8beb924

Please sign in to comment.