From 189a30af9600460e2590ea9e77db4557aafb7e49 Mon Sep 17 00:00:00 2001 From: Sheng Date: Mon, 23 Apr 2018 16:46:49 +0800 Subject: [PATCH] Added test_settings.py --- tests/known_hosts_example2 | 1 + tests/test_settings.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/known_hosts_example2 create mode 100644 tests/test_settings.py diff --git a/tests/known_hosts_example2 b/tests/known_hosts_example2 new file mode 100644 index 0000000..f4c7aab --- /dev/null +++ b/tests/known_hosts_example2 @@ -0,0 +1 @@ +192.168.1.196 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINwZGQmNFADnAAlm5uFLQTrdxqpNxHdgg4JPbB3sR2kr diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..fc5cb7c --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,30 @@ +import os.path +import unittest +import tornado.options as options + +from settings import get_host_keys_settings, base_dir +from policy import load_host_keys + + +class TestSettings(unittest.TestCase): + + def test_get_host_keys_settings(self): + options.hostFile = '' + options.sysHostFile = '' + dic = get_host_keys_settings(options) + + filename = os.path.join(base_dir, 'known_hosts') + self.assertEqual(dic['host_keys'], load_host_keys(filename)) + self.assertEqual(dic['host_keys_filename'], filename) + self.assertEqual( + dic['system_host_keys'], + load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) + ) + + options.hostFile = 'tests/known_hosts_example' + options.sysHostFile = 'tests/known_hosts_example2' + dic2 = get_host_keys_settings(options) + self.assertEqual(dic2['host_keys'], load_host_keys(options.hostFile)) + self.assertEqual(dic2['host_keys_filename'], options.hostFile) + self.assertEqual(dic2['system_host_keys'], + load_host_keys(options.sysHostFile))