From 13e5b45815ff451776e5e44540abee9a2b34846f Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Thu, 6 Sep 2012 15:53:26 -0400 Subject: [PATCH] Return a JSON error on an invalid zephyr type. (imported from commit 2207464c368666715caf550f32136de45ea37142) --- zephyr/tests.py | 8 ++++++++ zephyr/views.py | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/zephyr/tests.py b/zephyr/tests.py index e5e0934c92..f4737219e6 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -330,3 +330,11 @@ class ZephyrPOSTTest(AuthedTestCase): "new_zephyr": "Test message", "recipient": "nonexistent"}) 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") diff --git a/zephyr/views.py b/zephyr/views.py index 5b73d684a8..823579c638 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -210,8 +210,7 @@ def zephyr_backend(request, sender): recipient_user_profile = UserProfile.objects.get(user=recipient_user) recipient = Recipient.objects.get(type_id=recipient_user_profile.id, type="personal") else: - # Do something smarter here - raise + return json_error("Invalid zephyr type") new_zephyr = Zephyr() new_zephyr.sender = UserProfile.objects.get(user=sender)