From 78bbaa02b88a3f5d4b2704452ef8933b6d52092c Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Tue, 29 Oct 2013 14:55:45 -0400 Subject: [PATCH] Add in human-readable text for error messages. LMS-1133 --- lms/djangoapps/verify_student/models.py | 20 ++++++++++++------- .../verify_student/tests/test_models.py | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 17cffa4ead..f4466dbc85 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -534,10 +534,14 @@ class SoftwareSecurePhotoVerification(PhotoVerification): Returns a list of error messages """ - # Translates the category names into something more human readable - category_dict = { - "photoIdReasons": _("Photo ID Issues: "), - "generalReasons": u"" + # Translates the category names and messages into something more human readable + message_dict = { + ("photoIdReasons", "Not provided"): _("No photo ID was provided."), + ("photoIdReasons", "Text not clear"): _("The text in your photo ID image was not clear."), + ("generalReasons", "Name mismatch"): _("The name associated with your account and the name on your ID do not match."), + ("generalReasons", "Expected name missing"): _("We were unable to send your name along with your photo."), + ("userPhotoReasons", "Image not clear"): _("The image of your face was not clear."), + ("userPhotoReasons", "Face out of view"): _("Your face was not in view for your face photo"), } try: @@ -546,13 +550,15 @@ class SoftwareSecurePhotoVerification(PhotoVerification): msg = [] for category in msg_dict: - # translate the category into a human-readable name - category_name = category_dict[category] - msg.append(category_name + u", ".join(msg_dict[category])) + # find the messages associated with this category + category_msgs = msg_dict[category] + for category_msg in category_msgs: + msg.append(message_dict[(category, category_msg)]) return u", ".join(msg) except (ValueError, KeyError): # if we can't parse the message as JSON or the category doesn't # match one of our known categories, show a generic error + log.error('PhotoVerification: Error parsing this error message: %s', self.error_msg) return _("There was an error verifying your ID photos.") def image_url(self, name): diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index dcaa9cade9..e497c2d46c 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -331,7 +331,7 @@ class TestPhotoVerification(TestCase): attempt2.save() status = SoftwareSecurePhotoVerification.user_status(user) - self.assertEquals(status, (attempt2.status, "Photo ID Issues: Not provided")) + self.assertEquals(status, (attempt2.status, "No photo ID was provided.")) def test_parse_error_msg_success(self): user = UserFactory.create() @@ -339,7 +339,7 @@ class TestPhotoVerification(TestCase): attempt.status = 'denied' attempt.error_msg = '[{"photoIdReasons": ["Not provided"]}]' parsed_error_msg = attempt.parse_error_msg() - self.assertEquals("Photo ID Issues: Not provided", parsed_error_msg) + self.assertEquals("No photo ID was provided.", parsed_error_msg) def test_parse_error_msg_failure(self): user = UserFactory.create()