From cb183fef4cd3902573495528b6ed3655006551b1 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Fri, 27 Jul 2018 13:41:18 +0530 Subject: [PATCH] botserver: Add tests for reading config section by bot name. --- zulip_botserver/tests/test_server.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index f482be9..57329c3 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -134,6 +134,8 @@ class BotServerTests(BotServerTestCase): with self.assertRaises(IOError): server.read_config_file("nonexistentfile.conf") current_dir = os.path.dirname(os.path.abspath(__file__)) + + # No bot specified; should read all bot configs. bot_conf1 = server.read_config_file(os.path.join(current_dir, "test.conf")) expected_config1 = { 'helloworld': { @@ -150,6 +152,20 @@ class BotServerTests(BotServerTestCase): } } assert json.dumps(bot_conf1, sort_keys=True) == json.dumps(expected_config1, sort_keys=True) + + # Specified bot exists; should read only that section. + bot_conf3 = server.read_config_file(os.path.join(current_dir, "test.conf"), "giphy") + expected_config3 = { + 'giphy': { + 'email': 'giphy-bot@zulip.com', + 'key': 'value2', + 'site': 'http://localhost', + 'token': 'abcd1234', + } + } + assert json.dumps(bot_conf3, sort_keys=True) == json.dumps(expected_config3, sort_keys=True) + + # Specified bot doesn't exist; should read the first section of the config. bot_conf2 = server.read_config_file(os.path.join(current_dir, "test.conf"), "redefined_bot") expected_config2 = { 'redefined_bot': { @@ -161,6 +177,5 @@ class BotServerTests(BotServerTestCase): } assert json.dumps(bot_conf2, sort_keys=True) == json.dumps(expected_config2, sort_keys=True) - if __name__ == '__main__': unittest.main()