From 9d4e55d0287db43a2e35e8fe715b3f7c6a6ba0b1 Mon Sep 17 00:00:00 2001 From: hollal Date: Fri, 25 Aug 2017 16:01:27 +0900 Subject: [PATCH 1/3] Raise value error to avoid unknown error in server --- fbmq/payload.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fbmq/payload.py b/fbmq/payload.py index f565416..b1ac2c2 100644 --- a/fbmq/payload.py +++ b/fbmq/payload.py @@ -40,6 +40,8 @@ class Message(object): def __init__(self, text=None, attachment=None, quick_replies=None, metadata=None): if text is not None and attachment is not None: raise ValueError('Please set only one parameter "text" or "attachment"') + if not isinstance(quick_replies, list): + raise ValueError('quick_replies type must be "list"') self.text = text self.attachment = attachment From a6c579853e05717a10bf7b9ae4bd5a47046fb720 Mon Sep 17 00:00:00 2001 From: hollal Date: Tue, 29 Aug 2017 11:31:01 +0900 Subject: [PATCH 2/3] add unittest --- tests/test_payload.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_payload.py b/tests/test_payload.py index f2d71f4..3a93d31 100644 --- a/tests/test_payload.py +++ b/tests/test_payload.py @@ -28,6 +28,8 @@ def test_receipt(self): def test_message(self): with self.assertRaises(Exception): m = Payload.Message(text="hello", attachment=Attachment.Image('img')) + with self.assertRaises(ValueError): + m = Payload.Message(text="hello", quick_replies=Payload.QuickReply(title='Yes', payload='PICK_YES')) m = Payload.Message(text="hello", metadata="METADATA", quick_replies=[{'title': 'Yes', 'payload': 'PICK_YES'}]) self.assertEquals('{"attachment": null, "metadata": "METADATA", ' From 0912ca8ba11fb850252caf9c053c598711ddd6fb Mon Sep 17 00:00:00 2001 From: hollal Date: Wed, 30 Aug 2017 13:00:40 +0900 Subject: [PATCH 3/3] handle when quick_replies is None --- fbmq/payload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbmq/payload.py b/fbmq/payload.py index b1ac2c2..22627c5 100644 --- a/fbmq/payload.py +++ b/fbmq/payload.py @@ -40,7 +40,7 @@ class Message(object): def __init__(self, text=None, attachment=None, quick_replies=None, metadata=None): if text is not None and attachment is not None: raise ValueError('Please set only one parameter "text" or "attachment"') - if not isinstance(quick_replies, list): + if not isinstance(quick_replies, list) and quick_replies is not None: raise ValueError('quick_replies type must be "list"') self.text = text