botserver: Add tests for reading config section by bot name.
This commit is contained in:
parent
1127f973aa
commit
cb183fef4c
|
@ -134,6 +134,8 @@ class BotServerTests(BotServerTestCase):
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
server.read_config_file("nonexistentfile.conf")
|
server.read_config_file("nonexistentfile.conf")
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
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"))
|
bot_conf1 = server.read_config_file(os.path.join(current_dir, "test.conf"))
|
||||||
expected_config1 = {
|
expected_config1 = {
|
||||||
'helloworld': {
|
'helloworld': {
|
||||||
|
@ -150,6 +152,20 @@ class BotServerTests(BotServerTestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert json.dumps(bot_conf1, sort_keys=True) == json.dumps(expected_config1, sort_keys=True)
|
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")
|
bot_conf2 = server.read_config_file(os.path.join(current_dir, "test.conf"), "redefined_bot")
|
||||||
expected_config2 = {
|
expected_config2 = {
|
||||||
'redefined_bot': {
|
'redefined_bot': {
|
||||||
|
@ -161,6 +177,5 @@ class BotServerTests(BotServerTestCase):
|
||||||
}
|
}
|
||||||
assert json.dumps(bot_conf2, sort_keys=True) == json.dumps(expected_config2, sort_keys=True)
|
assert json.dumps(bot_conf2, sort_keys=True) == json.dumps(expected_config2, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue