Commit 78bbaa02 by Diana Huang

Add in human-readable text for error messages.

LMS-1133
parent df20a102
...@@ -534,10 +534,14 @@ class SoftwareSecurePhotoVerification(PhotoVerification): ...@@ -534,10 +534,14 @@ class SoftwareSecurePhotoVerification(PhotoVerification):
Returns a list of error messages Returns a list of error messages
""" """
# Translates the category names into something more human readable # Translates the category names and messages into something more human readable
category_dict = { message_dict = {
"photoIdReasons": _("Photo ID Issues: "), ("photoIdReasons", "Not provided"): _("No photo ID was provided."),
"generalReasons": u"" ("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: try:
...@@ -546,13 +550,15 @@ class SoftwareSecurePhotoVerification(PhotoVerification): ...@@ -546,13 +550,15 @@ class SoftwareSecurePhotoVerification(PhotoVerification):
msg = [] msg = []
for category in msg_dict: for category in msg_dict:
# translate the category into a human-readable name # find the messages associated with this category
category_name = category_dict[category] category_msgs = msg_dict[category]
msg.append(category_name + u", ".join(msg_dict[category])) for category_msg in category_msgs:
msg.append(message_dict[(category, category_msg)])
return u", ".join(msg) return u", ".join(msg)
except (ValueError, KeyError): except (ValueError, KeyError):
# if we can't parse the message as JSON or the category doesn't # if we can't parse the message as JSON or the category doesn't
# match one of our known categories, show a generic error # 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.") return _("There was an error verifying your ID photos.")
def image_url(self, name): def image_url(self, name):
......
...@@ -331,7 +331,7 @@ class TestPhotoVerification(TestCase): ...@@ -331,7 +331,7 @@ class TestPhotoVerification(TestCase):
attempt2.save() attempt2.save()
status = SoftwareSecurePhotoVerification.user_status(user) 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): def test_parse_error_msg_success(self):
user = UserFactory.create() user = UserFactory.create()
...@@ -339,7 +339,7 @@ class TestPhotoVerification(TestCase): ...@@ -339,7 +339,7 @@ class TestPhotoVerification(TestCase):
attempt.status = 'denied' attempt.status = 'denied'
attempt.error_msg = '[{"photoIdReasons": ["Not provided"]}]' attempt.error_msg = '[{"photoIdReasons": ["Not provided"]}]'
parsed_error_msg = attempt.parse_error_msg() 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): def test_parse_error_msg_failure(self):
user = UserFactory.create() user = UserFactory.create()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment