From af565eebab24539182b1aed1c57945b578df3f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Hultne=CC=81r?= Date: Fri, 29 Dec 2017 14:15:50 +0100 Subject: [PATCH] Made phone_number optional Added tests for full test coverage of fbmq/payload.py --- fbmq/payload.py | 3 ++- tests/test_page.py | 8 ++++---- tests/test_payload.py | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fbmq/payload.py b/fbmq/payload.py index 22627c5..f02cd83 100644 --- a/fbmq/payload.py +++ b/fbmq/payload.py @@ -28,7 +28,8 @@ def __eq__(self, other): class Recipient(object): def __init__(self, id=None, phone_number=None): self.id = id - self.phone_number = phone_number + if phone_number is not None: + self.phone_number = phone_number class Message(object): diff --git a/tests/test_page.py b/tests/test_page.py index 468fe48..12c9c51 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -90,25 +90,25 @@ def test_send(self): '[{"content_type": "text", "payload": "YES", "title": "Yes"}], ' '"text": "hello world"},' ' "notification_type": null, ' - '"recipient": {"id": 12345, "phone_number": null}, ' + '"recipient": {"id": 12345}, ' '"sender_action": null}', callback=1) def test_typingon(self): self.page.typing_on(1004) self.page._send.assert_called_once_with('{"message": null, "notification_type": null, ' - '"recipient": {"id": 1004, "phone_number": null}, ' + '"recipient": {"id": 1004}, ' '"sender_action": "typing_on"}') def test_typingoff(self): self.page.typing_off(1004) self.page._send.assert_called_once_with('{"message": null, "notification_type": null, ' - '"recipient": {"id": 1004, "phone_number": null}, ' + '"recipient": {"id": 1004}, ' '"sender_action": "typing_off"}') def test_markseen(self): self.page.mark_seen(1004) self.page._send.assert_called_once_with('{"message": null, "notification_type": null, ' - '"recipient": {"id": 1004, "phone_number": null}, ' + '"recipient": {"id": 1004}, ' '"sender_action": "mark_seen"}') def test_handle_webhook_errors(self): diff --git a/tests/test_payload.py b/tests/test_payload.py index 3a93d31..133ceec 100644 --- a/tests/test_payload.py +++ b/tests/test_payload.py @@ -22,6 +22,10 @@ def test_quick_reply_shortcut(self): self.assertEquals(None, Payload.Message.convert_shortcut_quick_reply(None)) def test_receipt(self): + q = Payload.Recipient(id=123456) + self.assertEquals('{"id": 123456}', utils.to_json(q)) + + def test_receipt_with_phone(self): q = Payload.Recipient(id=123456, phone_number='+8210') self.assertEquals('{"id": 123456, "phone_number": "+8210"}', utils.to_json(q)) @@ -42,7 +46,15 @@ def test_payload(self): quick_replies=[{'title': 'Yes', 'payload': 'PICK_YES'}]) with self.assertRaises(ValueError): - Payload.Payload(recipient=recipient, message=message, sender_action='NEW_ACTION') + Payload.Payload(recipient=recipient, + message=message, + sender_action='NEW_ACTION') + + with self.assertRaises(ValueError): + Payload.Payload(recipient=recipient, + message=message, + sender_action='typing_off', + notification_type='NEW_NOTIFICATION_TYPE') p = Payload.Payload(recipient=recipient, message=message, @@ -57,3 +69,4 @@ def test_payload(self): self.assertTrue(p.__eq__(p)) self.assertTrue(p.__eq__(utils.to_json(p))) +