From a71177c9a73ac73d670387276552dbd07fa7e7d4 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Wed, 16 Apr 2014 15:07:03 -0700 Subject: [PATCH] Add a test for reading a configuration file Signed-off-by: Sean Robinson --- test/data/wifi-radar-test.conf | 55 +++++++++++++++++++++++++++++++++ test/unit/config.py | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 test/data/wifi-radar-test.conf diff --git a/test/data/wifi-radar-test.conf b/test/data/wifi-radar-test.conf new file mode 100644 index 0000000..0e4a9bd --- /dev/null +++ b/test/data/wifi-radar-test.conf @@ -0,0 +1,55 @@ +[DEFAULT] +auto_profile_order = [u'WinterPalace:00:09:5B:D5:03:4A'] +commit_required = False +ifconfig_command = /sbin/ifconfig +ifup_required = False +interface = auto_detect +iwconfig_command = /sbin/iwconfig +iwlist_command = /sbin/iwlist +logfile = /var/log/wifi-radar.log +loglevel = 50 +route_command = /sbin/route +version = 0.0.0 + +[DHCP] +args = -D -o -i dhcp_client -t 30 +command = /sbin/dhcpcd +kill_args = -k +pidfile = /etc/dhcpc/dhcpcd-auto_detect.pid +timeout = 30 + +[WPA] +args = -B -i auto_detect -c /etc/wpa_supplicant.conf -D wext -P /var/run/wpa_supplicant.pid +command = /usr/sbin/wpa_supplicant +configuration = /etc/wpa_supplicant.conf +driver = wext +kill_command = +pidfile = /var/run/wpa_supplicant.pid + +[WinterPalace:00:09:5B:D5:03:4A] +available = False +bssid = 00:09:5B:D5:03:4A +channel = auto +con_postscript = +con_prescript = +dis_postscript = +dis_prescript = +dns1 = +dns2 = +domain = +encrypted = True +essid = WinterPalace +gateway = +ip = +key = +known = True +mode = auto +netmask = +protocol = g +roaming = False +security = none +signal = -193 +use_dhcp = True +wep_mode = none +wpa_psk = + diff --git a/test/unit/config.py b/test/unit/config.py index 68bf511..f4cd56e 100644 --- a/test/unit/config.py +++ b/test/unit/config.py @@ -236,6 +236,76 @@ class TestConfigManager(unittest.TestCase): self.assertEqual(self.config.items('SECT03'), items_orig) +class TestConfigFileManager(unittest.TestCase): + def setUp(self): + self.test_conf_file = './test/data/wifi-radar-test.conf' + self.DEFAULT = { + 'auto_profile_order': "[u'WinterPalace:00:09:5B:D5:03:4A']", + 'commit_required': 'False', + 'ifconfig_command': '/sbin/ifconfig', + 'ifup_required': 'False', + 'interface': 'auto_detect', + 'iwconfig_command': '/sbin/iwconfig', + 'iwlist_command': '/sbin/iwlist', + 'logfile': '/var/log/wifi-radar.log', + 'loglevel': '50', + 'route_command': '/sbin/route', + 'version': '0.0.0'} + self.DHCP = {'__name__': 'DHCP', + 'args': '-D -o -i dhcp_client -t 30', + 'command': '/sbin/dhcpcd', + 'kill_args': '-k', + 'pidfile': '/etc/dhcpc/dhcpcd-auto_detect.pid', + 'timeout': '30'} + self.WPA = {'__name__': 'WPA', + 'args': '-B -i auto_detect -c /etc/wpa_supplicant.conf ' + '-D wext -P /var/run/wpa_supplicant.pid', + 'command': '/usr/sbin/wpa_supplicant', + 'configuration': '/etc/wpa_supplicant.conf', + 'driver': 'wext', + 'kill_command': '', + 'pidfile': '/var/run/wpa_supplicant.pid'} + self.WINTERPALACE = {'__name__': 'WinterPalace:00:09:5B:D5:03:4A', + 'available': 'False', + 'bssid': '00:09:5B:D5:03:4A', + 'channel': 'auto', + 'con_postscript': '', + 'con_prescript': '', + 'dis_postscript': '', + 'dis_prescript': '', + 'dns1': '', + 'dns2': '', + 'domain': '', + 'encrypted': 'True', + 'essid': 'WinterPalace', + 'gateway': '', + 'ip': '', + 'key': '', + 'known': 'True', + 'mode': 'auto', + 'netmask': '', + 'protocol': 'g', + 'roaming': 'False', + 'security': 'none', + 'signal': '-193', + 'use_dhcp': 'True', + 'wep_mode': 'none', + 'wpa_psk': ''} + + def test_read(self): + """ Test read method. """ + self.config = ConfigFileManager(self.test_conf_file) + self.config.read() + self.assertEqual(self.config.defaults(), self.DEFAULT) + self.assertEqual(self.config._sections['DHCP'], self.DHCP) + self.assertEqual(self.config._sections['WPA'], self.WPA) + self.assertEqual( + self.config._sections['WinterPalace:00:09:5B:D5:03:4A'], + self.WINTERPALACE) + self.assertEqual(self.config.auto_profile_order, + [u'WinterPalace:00:09:5B:D5:03:4A']) + + class TestConfigFunctions(unittest.TestCase): def test_copy(self): -- 2.11.4.GIT