Return a JSON error on an invalid zephyr type.

(imported from commit 2207464c368666715caf550f32136de45ea37142)
This commit is contained in:
Jessica McKellar 2012-09-06 15:53:26 -04:00
parent b235b8bc31
commit 13e5b45815
2 changed files with 9 additions and 2 deletions

View File

@ -330,3 +330,11 @@ class ZephyrPOSTTest(AuthedTestCase):
"new_zephyr": "Test message", "new_zephyr": "Test message",
"recipient": "nonexistent"}) "recipient": "nonexistent"})
self.assert_json_error(result, "Invalid username") self.assert_json_error(result, "Invalid username")
def test_invalid_type(self):
"""
Sending a zephyr of unknown type returns error JSON.
"""
self.login("hamlet", "hamlet")
result = self.client.post("/zephyr/", {"type": "invalid type"})
self.assert_json_error(result, "Invalid zephyr type")

View File

@ -210,8 +210,7 @@ def zephyr_backend(request, sender):
recipient_user_profile = UserProfile.objects.get(user=recipient_user) recipient_user_profile = UserProfile.objects.get(user=recipient_user)
recipient = Recipient.objects.get(type_id=recipient_user_profile.id, type="personal") recipient = Recipient.objects.get(type_id=recipient_user_profile.id, type="personal")
else: else:
# Do something smarter here return json_error("Invalid zephyr type")
raise
new_zephyr = Zephyr() new_zephyr = Zephyr()
new_zephyr.sender = UserProfile.objects.get(user=sender) new_zephyr.sender = UserProfile.objects.get(user=sender)