From fa9e5a8e265af558d1ee3f8abcb5cfae3be25695 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Tue, 7 Nov 2017 14:57:52 +0100 Subject: [PATCH] zulip_botserver: Test for import error with wrong credentials. --- zulip_botserver/tests/test_server.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index d44a0bf..1c5e01c 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -40,18 +40,21 @@ class BotServerTests(BotServerTestCase): @mock.patch('logging.error') def test_wrong_bot_credentials(self, mock_LoggingError): # type: (mock.Mock) -> None - available_bots = ['helloworld'] + available_bots = ['nonexistent-bot'] bots_config = { - 'helloworld': { + 'nonexistent-bot': { 'email': 'helloworld-bot@zulip.com', 'key': '123456789qwertyuiop', 'site': 'http://localhost', } } - server.available_bots = available_bots - server.load_bot_handlers() - mock_LoggingError.assert_called_with("Cannot fetch user profile, make sure you have set up the zuliprc file correctly.") - + # This complains about mismatching argument types, yet they are all correct? + # We should investigate and file an issue in mypy. + self.assertRaisesRegexp(ImportError, # type: ignore + "Bot \"nonexistent-bot\" doesn't exists. Please " + "make sure you have set up the flaskbotrc file correctly.", + lambda: self.assert_bot_server_response(available_bots=available_bots, + bots_config=bots_config)) if __name__ == '__main__': unittest.main()