def mk_msg(self, to_addr, tag=None, from_addr="12345"): msg = TransportUserMessage( to_addr=to_addr, from_addr=from_addr, transport_name="dummy_endpoint", transport_type="dummy_transport_type" ) if tag is not None: TaggingMiddleware.add_tag_to_msg(msg, tag) return msg
def mk_msg(self, to_addr, tag=None, from_addr="12345"): msg = TransportUserMessage(to_addr=to_addr, from_addr=from_addr, transport_name="dummy_connector", transport_type="dummy_transport_type") if tag is not None: TaggingMiddleware.add_tag_to_msg(msg, tag) return msg
def test_handle_inbound_with_tag(self): mw = yield self.setup_middleware() batch_id = yield self.store.batch_start([("pool", "tag")]) msg = self.mk_msg() TaggingMiddleware.add_tag_to_msg(msg, ["pool", "tag"]) response = yield mw.handle_inbound(msg, "dummy_connector") self.assertEqual(response, msg) yield self.assert_inbound_stored(msg, batch_id)
def test_handle_inbound_with_tag(self): mw = yield self.setup_middleware() batch_id = yield self.store.batch_start([("pool", "tag")]) msg = self.mk_msg() TaggingMiddleware.add_tag_to_msg(msg, ["pool", "tag"]) response = yield mw.handle_inbound(msg, "dummy_connector") self.assertEqual(response, msg) yield self.assert_inbound_stored(msg, batch_id)
def test_handle_inbound_with_tag(self): batch_id = self.store.batch_start([("pool", "tag")]) msg = self.mk_msg() msg_id = msg['message_id'] TaggingMiddleware.add_tag_to_msg(msg, ["pool", "tag"]) response = self.mw.handle_inbound(msg, "dummy_endpoint") self.assertTrue(isinstance(response, TransportUserMessage)) self.assertEqual(self.store.get_inbound_message(msg_id), msg) self.assertEqual(self.store.batch_messages(batch_id), []) self.assertEqual(self.store.batch_replies(batch_id), [msg_id])
def test_handle_inbound_with_tag(self): batch_id = self.store.batch_start([("pool", "tag")]) msg = self.mk_msg() msg_id = msg['message_id'] TaggingMiddleware.add_tag_to_msg(msg, ["pool", "tag"]) response = self.mw.handle_inbound(msg, "dummy_endpoint") self.assertTrue(isinstance(response, TransportUserMessage)) self.assertEqual(self.store.get_inbound_message(msg_id), msg) self.assertEqual(self.store.batch_messages(batch_id), []) self.assertEqual(self.store.batch_replies(batch_id), [msg_id])
def send_keyword(self, mw, word, expected_response): msg = self.mw_helper.make_inbound( word, to_addr='*****@*****.**', from_addr='*****@*****.**') TaggingMiddleware.add_tag_to_msg(msg, ("pool", "tag1")) yield mw.handle_inbound(msg, 'dummy_endpoint') expected_response = dict(expected_response, tag={'tag': ['pool', 'tag1']}) # MessageMetadataHelper can add 'go' metadata and we want to ignore it. if 'go' in msg['helper_metadata']: expected_response['go'] = msg['helper_metadata']['go'] self.assertEqual(msg['helper_metadata'], expected_response)
def send_keyword(self, mw, word, expected_response): msg = self.mw_helper.make_inbound(word, to_addr='*****@*****.**', from_addr='*****@*****.**') TaggingMiddleware.add_tag_to_msg(msg, ("pool", "tag1")) yield mw.handle_inbound(msg, 'dummy_endpoint') expected_response = dict(expected_response, tag={'tag': ['pool', 'tag1']}) # MessageMetadataHelper can add 'go' metadata and we want to ignore it. if 'go' in msg['helper_metadata']: expected_response['go'] = msg['helper_metadata']['go'] self.assertEqual(msg['helper_metadata'], expected_response)
def mk_msg(self, to_addr, from_addr, session_event=SESSION_NEW, session_start=None, session_end=None, tag=None, transport_name='dummy_transport'): msg = TransportUserMessage( to_addr=to_addr, from_addr=from_addr, transport_name=transport_name, transport_type="dummy_transport_type", session_event=session_event) if tag is not None: TaggingMiddleware.add_tag_to_msg(msg, tag) if session_start is not None: self._set_metadata(msg, 'session_start', session_start) if session_end is not None: self._set_metadata(msg, 'session_end', session_end) return msg
def mk_msg(self, to_addr, from_addr, session_event=SESSION_NEW, session_start=None, session_end=None, tag=None, transport_name='dummy_transport'): msg = TransportUserMessage(to_addr=to_addr, from_addr=from_addr, transport_name=transport_name, transport_type="dummy_transport_type", session_event=session_event) if tag is not None: TaggingMiddleware.add_tag_to_msg(msg, tag) if session_start is not None: self._set_metadata(msg, 'session_start', session_start) if session_end is not None: self._set_metadata(msg, 'session_end', session_end) return msg
def set_conversation_tag(self, msg, conversation): # TOOD: Move into AppWorkerTestCase once it's working tag = (conversation.delivery_tag_pool, conversation.delivery_tag) TaggingMiddleware.add_tag_to_msg(msg, tag) return msg
def test_add_tag_to_msg(self): msg = self.mk_msg("123456") TaggingMiddleware.add_tag_to_msg(msg, ('pool', 'mytag')) self.assertEqual(msg['helper_metadata']['tag'], { 'tag': ['pool', 'mytag'], })
def set_conversation_tag(self, msg, conversation): # TOOD: Move into AppWorkerTestCase once it's working tag = (conversation.delivery_tag_pool, conversation.delivery_tag) TaggingMiddleware.add_tag_to_msg(msg, tag) return msg
def set_tag(self, tag): TaggingMiddleware.add_tag_to_msg(self.message, tag) self.tag = TaggingMiddleware.map_msg_to_tag(self.message)
def test_add_tag_to_msg(self): msg = self.mk_msg("123456") TaggingMiddleware.add_tag_to_msg(msg, ("pool", "mytag")) self.assertEqual(msg["helper_metadata"]["tag"], {"tag": ["pool", "mytag"]})
def set_tag(self, tag): TaggingMiddleware.add_tag_to_msg(self.message, tag) self.tag = TaggingMiddleware.map_msg_to_tag(self.message)