def mkmsg_fail(self, message, reason, failure_code=FailureMessage.FC_UNSPECIFIED): return FailureMessage( timestamp=UTCNearNow(), failure_code=failure_code, message=message, reason=reason, )
def mkmsg_ack(self, user_message_id='1', sent_message_id='abc', transport_metadata=None): if transport_metadata is None: transport_metadata = {} return TransportEvent( event_id=RegexMatcher(r'^[0-9a-fA-F]{32}$'), event_type='ack', user_message_id=user_message_id, sent_message_id=sent_message_id, timestamp=UTCNearNow(), transport_name=self.transport_name, transport_metadata=transport_metadata, )
def mkmsg_delivery(self, status='delivered', user_message_id='abc', transport_metadata=None): if transport_metadata is None: transport_metadata = {} return TransportEvent( event_id=RegexMatcher(r'^[0-9a-fA-F]{32}$'), event_type='delivery_report', transport_name=self.transport_name, user_message_id=user_message_id, delivery_status=status, to_addr='+41791234567', timestamp=UTCNearNow(), transport_metadata=transport_metadata, )
def mkmsg_fail(self, user_message_id='1', failure_level='', failure_code=0, failure_reason='', transport_metadata={}): if transport_metadata is None: transport_metadata = {} return TransportEvent( event_id=RegexMatcher(r'^[0-9a-fA-F]{32}$'), event_type='delivery_report', delivery_status='failed', failure_level=failure_level, failure_code=failure_code, failure_reason=failure_reason, user_message_id=user_message_id, timestamp=UTCNearNow(), transport_name=self.transport_name, transport_metadata=transport_metadata)
def test_transport_user_message_defaults(self): msg = TransportUserMessage( to_addr='+27831234567', from_addr='12345', transport_name='sphex', transport_type='sms', transport_metadata={}, ) self.assertEqual('user_message', msg['message_type']) self.assertEqual('sms', msg['transport_type']) self.assertEqual(RegexMatcher(r'^[0-9a-fA-F]{32}$'), msg['message_id']) self.assertEqual('20110921', msg['message_version']) self.assertEqual(None, msg['content']) self.assertEqual('sphex', msg['transport_name']) self.assertEqual({}, msg['transport_metadata']) self.assertEqual(UTCNearNow(), msg['timestamp']) self.assertEqual('+27831234567', msg['to_addr']) self.assertEqual('12345', msg['from_addr'])
def test_transport_user_message_basic(self): msg = TransportUserMessage( message_id='abc', to_addr='+27831234567', from_addr='12345', content='heya', transport_name='sphex', transport_type='sms', transport_metadata={}, ) self.assertEqual('user_message', msg['message_type']) self.assertEqual('sms', msg['transport_type']) self.assertEqual('abc', msg['message_id']) self.assertEqual('20110921', msg['message_version']) self.assertEqual('heya', msg['content']) self.assertEqual('sphex', msg['transport_name']) self.assertEqual({}, msg['transport_metadata']) self.assertEqual(UTCNearNow(), msg['timestamp']) self.assertEqual('+27831234567', msg['to_addr']) self.assertEqual('12345', msg['from_addr'])
def mkmsg_in(self, content='Hello World', from_addr='41791234567', session_event=TransportUserMessage.SESSION_NONE, message_id='abc', transport_type=None, transport_metadata=None): if transport_type is None: transport_type = self.transport_type if transport_metadata is None: transport_metadata = {} return TransportUserMessage( from_addr='+41791234567', to_addr='9292', group=None, message_id=message_id, transport_name=self.transport_name, transport_type=transport_type, transport_metadata=transport_metadata, content=content, session_event=session_event, timestamp=UTCNearNow())
def test_transport_message(self): msg = TransportMessage(message_type='foo', ) self.assertEqual('foo', msg['message_type']) self.assertEqual('20110921', msg['message_version']) self.assertEqual(UTCNearNow(), msg['timestamp'])
def test_transport_message_fields(self): msg = self.make_message() self.assertEqual('20110921', msg['message_version']) self.assertEqual(UTCNearNow(), msg['timestamp'])