From 8b4f23d6aa3137396454db2dbd60c54858e9c1b8 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sun, 17 Jun 2018 13:04:07 -0700 Subject: [PATCH] matrix tests: Add test for zulip-to-matrix messages. --- zulip/integrations/matrix/test_matrix.py | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/zulip/integrations/matrix/test_matrix.py b/zulip/integrations/matrix/test_matrix.py index a9dcbfb..1dc682d 100644 --- a/zulip/integrations/matrix/test_matrix.py +++ b/zulip/integrations/matrix/test_matrix.py @@ -1,6 +1,9 @@ -from matrix_bridge import check_zulip_message_validity +from matrix_bridge import ( + check_zulip_message_validity, + zulip_to_matrix, +) -from unittest import TestCase +from unittest import TestCase, mock from subprocess import Popen, PIPE import os @@ -117,3 +120,24 @@ class MatrixBridgeZulipToMatrixTests(TestCase): msg_from_bot = dict(self.valid_msg, sender_email=zulip_config['email']) self.assertFalse(check_zulip_message_validity(msg_from_bot, zulip_config)) + + def test_zulip_to_matrix(self): + # type: () -> None + room = mock.MagicMock() + zulip_config = self.valid_zulip_config + send_msg = zulip_to_matrix(zulip_config, room) + + msg = dict(self.valid_msg, sender_full_name="John Smith") + + expected = { + 'hi': '{} hi', + '*hi*': '{} *hi*', + '**hi**': '{} **hi**', + } + + for content in expected: + send_msg(dict(msg, content=content)) + + for (method, params, _), expect in zip(room.method_calls, expected.values()): + self.assertEqual(method, 'send_text') + self.assertEqual(params[0], expect.format(''))