def test_message(self):
        with self.assertRaises(Exception):
            m = Payload.Message(text="hello", attachment=Attachment.Image('img'))

        m = Payload.Message(text="hello", metadata="METADATA", quick_replies=[{'title': 'Yes', 'payload': 'PICK_YES'}])
        self.assertEquals('{"attachment": null, "metadata": "METADATA", '
                          '"quick_replies": [{"content_type": "text", "payload": "PICK_YES", "title": "Yes"}], '
                          '"text": "hello"}', utils.to_json(m))
예제 #2
0
    def test_payload(self):
        recipient = Payload.Recipient(id=123456, phone_number='+8210')
        message = Payload.Message(text="hello", metadata="METADATA",
                                  quick_replies=[{'title': 'Yes', 'payload': 'PICK_YES'}])

        with self.assertRaises(ValueError):
            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,
                            sender_action='typing_off',
                            notification_type='REGULAR')

        self.assertEquals(
            '{"message": {"attachment": null, "metadata": "METADATA", "quick_replies": '
            '[{"content_type": "text", "payload": "PICK_YES", "title": "Yes"}], "text": "hello"},'
            ' "notification_type": "REGULAR", "recipient": {"id": 123456, "phone_number": "+8210"},'
            ' "sender_action": "typing_off"}', utils.to_json(p))

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