def test_jsonex(self):
        """ Test de/coding messages """
        ### OutgoingMessage
        om_in = OutgoingMessage('+123', 'Test', '+987', 'fwd')
        om_in.options(allow_reply=True)
        # Encode, Decode
        j = jsonex_dumps(om_in)
        om_out = jsonex_loads(j)
        """ :type om_out: OutgoingMessage """
        # Check
        self.assertEqual(om_out.dst, '123')
        self.assertEqual(om_out.src, om_in.src)
        self.assertEqual(om_out.body, om_in.body)
        self.assertEqual(om_out.provider, om_in.provider)
        self.assertEqual(om_out.meta, None)
        self.assertEqual(om_out.provider_options.allow_reply, om_in.provider_options.allow_reply)
        self.assertEqual(om_out.provider_params, {})

        ### IncomingMessage
        im_in = IncomingMessage('+123', 'Test', 'abc123def', '+987', datetime(2019,1,1,15,0,0,875), {'a':1})
        # Encode, Decode
        j = jsonex_dumps(im_in)
        im_out = jsonex_loads(j)
        """ :type im_out: IncomingMessage """
        # Check
        self.assertEqual(im_out.src, im_in.src)
        self.assertEqual(im_out.body, im_in.body)
        self.assertEqual(im_out.msgid, im_in.msgid)
        self.assertEqual(im_out.dst, im_in.dst)
        self.assertEqual(im_out.rtime, im_in.rtime)
        self.assertEqual(im_out.meta, im_in.meta)
    def test_jsonex(self):
        """ Test de/coding messages """
        ### OutgoingMessage
        om_in = OutgoingMessage('+123', 'Test', '+987', 'fwd')
        om_in.options(allow_reply=True)
        # Encode, Decode
        j = jsonex_dumps(om_in)
        om_out = jsonex_loads(j)
        """ :type om_out: OutgoingMessage """
        # Check
        self.assertEqual(om_out.dst, '123')
        self.assertEqual(om_out.src, om_in.src)
        self.assertEqual(om_out.body, om_in.body)
        self.assertEqual(om_out.provider, om_in.provider)
        self.assertEqual(om_out.meta, None)
        self.assertEqual(om_out.provider_options.allow_reply,
                         om_in.provider_options.allow_reply)
        self.assertEqual(om_out.provider_params, {})

        ### IncomingMessage
        im_in = IncomingMessage('+123', 'Test', 'abc123def', '+987',
                                datetime(2019, 1, 1, 15, 0, 0, 875), {'a': 1})
        # Encode, Decode
        j = jsonex_dumps(im_in)
        im_out = jsonex_loads(j)
        """ :type im_out: IncomingMessage """
        # Check
        self.assertEqual(im_out.src, im_in.src)
        self.assertEqual(im_out.body, im_in.body)
        self.assertEqual(im_out.msgid, im_in.msgid)
        self.assertEqual(im_out.dst, im_in.dst)
        self.assertEqual(im_out.rtime, im_in.rtime)
        self.assertEqual(im_out.meta, im_in.meta)
Exemple #3
0
    def test_senderId(self):
        gw = self.gw

        self._mock_response(200)  # OK
        message = OutgoingMessage('+123456', 'hey', provider='main')
        message.options(senderId='Fake sender')
        gw.send(message)
        request = self.requests.pop()
        self.assertEqual('Fake sender', request['SND'])