Skip to content

Commit

Permalink
Merge pull request conbus#47 from Hultner/master
Browse files Browse the repository at this point in the history
Made phone_number optional
  • Loading branch information
Anton Nayshtut authored Dec 31, 2017
2 parents c5b40e8 + af565ee commit ad704b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion fbmq/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion tests/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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,
Expand All @@ -57,3 +69,4 @@ def test_payload(self):

self.assertTrue(p.__eq__(p))
self.assertTrue(p.__eq__(utils.to_json(p)))

0 comments on commit ad704b0

Please sign in to comment.