From 43d6acfc4717c8f139f2dcffbbb7c98d9705888f Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Tue, 23 Dec 2008 11:39:55 -0600 Subject: [PATCH] Updated Preferences dialog and added test cases for wnettools --- data/wicd.glade | 1090 ++++++++++++++++++++-------------------- setup.py | 21 +- tests/__init__.py | 9 + tests/testwnettools.py | 66 +++ wicd/wicd-client.py | 3 +- 5 files changed, 641 insertions(+), 548 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/testwnettools.py diff --git a/data/wicd.glade b/data/wicd.glade index 7aa264e..234fd4a 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -1,6 +1,6 @@ - + 450 @@ -429,14 +429,15 @@ 4 4 - + True - 12 + 24 - + True True - Automatically reconnect on wireless network connection loss + If enabled, the wired network interface will always be displayed in the main window. This can be useful if your wired network card does not detect when the interface is connected to a cable. + Always show wired interface 0 True @@ -444,67 +445,255 @@ 2 - 15 - 16 + 3 + 4 - + + True + True + + + 1 + 2 + 6 + 7 + + + + + + True + True + + + 1 + 2 + 7 + 8 + + + + + + True + True + + + 1 + 2 + 8 + 9 + + + + + True 0 - <b>Wireless automatic connection</b> + <b>Global DNS Servers</b> True 2 - 14 - 15 + 4 + 5 - + True 12 - + True True - Use last wired network profile + Use global DNS servers 0 - True True 2 - 13 - 14 + 5 + 6 - + True - 12 + 24 - + True - True - Prompt for wired network profile - 0 - True - True - pref_use_last_radio + 0 + Search domain: + 6 + 7 + + + + + + True + 24 + + + True + 0 + DNS server 1: + + + + + 7 + 8 + + + + + + True + 24 + + + True + 0 + DNS server 2: + + + + + 8 + 9 + + + + + + True + True + + + 1 2 - 12 - 13 + 9 + 10 + + + + + + True + 24 + + + True + 0 + DNS server 3: + + + + + 9 + 10 + + + + + + True + 0 + <b>Network Interfaces</b> + True + + + 2 + + + + + + True + True + + + 1 + 2 + 1 + 2 + + + + + + True + True + + + 1 + 2 + 2 + 3 + + + + + + True + 12 + + + True + 0 + Wireless interface: + + + + + 1 + 2 + + + + + + True + 12 + + + True + 0 + Wired interface: + + + + + 2 + 3 + + + + + + True + 0 + <b>Wired automatic connection</b> + True + + + 2 + 10 + 11 @@ -532,187 +721,73 @@ - - True - 0 - <b>Wired automatic connection</b> - True - - - 2 - 10 - 11 - - - - - + True 12 - - True - 0 - Wired interface: - - - - - 2 - 3 - - - - - - True - 12 - - - True - 0 - Wireless interface: - - - - - 1 - 2 - - - - - - True - True - - - 1 - 2 - 2 - 3 - - - - - - True - True - - - 1 - 2 - 1 - 2 - - - - - - True - 0 - <b>Network Interfaces</b> - True - - - 2 - - - - - - True - 24 - - - True - 0 - DNS server 3: - - - - - 9 - 10 - - - - - - True - True - - - 1 - 2 - 9 - 10 - - - - - - True - 24 - - - True - 0 - DNS server 2: - - - - - 8 - 9 - - - - - - True - 24 - - - True - 0 - DNS server 1: - - - - - 7 - 8 - - - - - - True - 24 - - - True - 0 - Search domain: - - - - - 6 - 7 - - - - - - True - 12 - - + True True - Use global DNS servers + Prompt for wired network profile + 0 + True + True + pref_use_last_radio + + + + + 2 + 12 + 13 + + + + + + True + 12 + + + True + True + Use last wired network profile + 0 + True + True + + + + + 2 + 13 + 14 + + + + + + True + 0 + <b>Wireless automatic connection</b> + True + + + 2 + 14 + 15 + + + + + + True + 12 + + + True + True + Automatically connect to on network connection loss 0 True @@ -720,83 +795,8 @@ 2 - 5 - 6 - - - - - - True - 0 - <b>Global DNS Servers</b> - True - - - 2 - 4 - 5 - - - - - - True - True - - - 1 - 2 - 8 - 9 - - - - - - True - True - - - 1 - 2 - 7 - 8 - - - - - - True - True - - - 1 - 2 - 6 - 7 - - - - - - True - 24 - - - True - True - If enabled, the wired network interface will always be displayed in the main window. This can be useful if your wired network card does not detect when the interface is connected to a cable. - Always show wired interface - 0 - True - - - - - 2 - 3 - 4 + 15 + 16 @@ -841,146 +841,13 @@ True 6 - + True 0 - <b>Route Table Flushing</b> + <b>DHCP Client</b> True - 4 - 5 - - - - - - True - 0 - <b>Wired Link Detection</b> - True - - - 2 - 3 - - - - - - True - 12 - - - True - - - True - True - Automatic (recommended) - 0 - True - True - - - False - - - - - True - True - ip - 0 - True - True - flush_auto_radio - - - False - 1 - - - - - True - True - route - 0 - True - True - flush_auto_radio - - - False - 2 - - - - - - - 5 - 6 - - - - - - True - 12 - - - True - - - True - True - Automatic (recommended) - 0 - True - True - - - False - - - - - True - True - ethtool - 0 - True - True - link_auto_radio - - - False - 1 - - - - - True - True - mii-tool - 0 - True - True - link_auto_radio - - - False - 2 - - - - - - - 3 - 4 @@ -1059,13 +926,146 @@ - + + True + 12 + + + True + + + True + True + Automatic (recommended) + 0 + True + True + + + False + + + + + True + True + ethtool + 0 + True + True + link_auto_radio + + + False + 1 + + + + + True + True + mii-tool + 0 + True + True + link_auto_radio + + + False + 2 + + + + + + + 3 + 4 + + + + + + True + 12 + + + True + + + True + True + Automatic (recommended) + 0 + True + True + + + False + + + + + True + True + ip + 0 + True + True + flush_auto_radio + + + False + 1 + + + + + True + True + route + 0 + True + True + flush_auto_radio + + + False + 2 + + + + + + + 5 + 6 + + + + + True 0 - <b>DHCP Client</b> + <b>Wired Link Detection</b> True + 2 + 3 + + + + + + True + 0 + <b>Route Table Flushing</b> + True + + + 4 + 5 @@ -1104,41 +1104,131 @@ 9 2 - + + True + + + 2 + 3 + + + + + + True + 0 + You should almost always use wext as the WPA supplicant driver. + True + + + 1 + 2 + 2 + 3 + + + + + True - 12 - + True - 0 - Driver: + + False + + 1 + 2 1 2 - + + True + 0 + <b>Backend</b> + True + + + 2 + 3 + 4 + + + + + + True + + + 1 + 2 + 4 + 5 + + + + + True 12 - + True - True - Use dBm to measure signal strength - 0 - True + 0 + Backend: + + 4 + 5 + + + + + + True + 0 + <b>Debugging</b> + True + 2 - 8 - 9 + 5 + 6 + + + + + + True + 0 + <b>WPA Supplicant</b> + True + + + 2 + + + + + + True + 0 + <b>Wireless Interface</b> + True + + + 2 + 7 + 8 @@ -1164,134 +1254,44 @@ - - True - 0 - <b>Wireless Interface</b> - True - - - 2 - 7 - 8 - - - - - - True - 0 - <b>WPA Supplicant</b> - True - - - 2 - - - - - - True - 0 - <b>Debugging</b> - True - - - 2 - 5 - 6 - - - - - + True 12 - + + True + True + Use dBm to measure signal strength + 0 + True + + + + + 2 + 8 + 9 + + + + + + True + 12 + + True 0 - Backend: + Driver: - 4 - 5 - - - - - - True - - - 1 - 2 - 4 - 5 - - - - - - True - 0 - <b>Backend</b> - True - - - 2 - 3 - 4 - - - - - - True - - - True - - - False - - - - - 1 - 2 1 2 - - - True - 0 - You should almost always use wext as the WPA supplicant driver. - True - - - 1 - 2 - 2 - 3 - - - - - - True - - - 2 - 3 - - - diff --git a/setup.py b/setup.py index 521e7dd..16644e5 100755 --- a/setup.py +++ b/setup.py @@ -219,7 +219,24 @@ class configure(Command): item_out.close() item_in.close() shutil.copymode(original_name, final_name) + +class test(Command): + description = "run Wicd's unit tests" + + user_options = [] + + def initialize_options(self): + pass + def finalize_options(self): + pass + + def run(self): + print "importing tests" + import tests + print 'running tests' + tests.run_tests() + class get_translations(Command): description = "download the translations from the online translator" @@ -330,7 +347,7 @@ try: data.append(( wpath.suspend, ['other/50-wicd-suspend.sh' ])) if not wpath.no_install_pmutils: data.append(( wpath.pmutils, ['other/55wicd' ])) - print 'Creating pid path', os.path.basename(wpath.pidfile) + print 'Using pid path', os.path.basename(wpath.pidfile) print 'Language support for', for language in os.listdir('translations/'): if not language.startswith('.'): @@ -354,7 +371,7 @@ iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'], sources = ['depends/python-iwscan/pyiwscan.c']) -setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall}, +setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test}, name="Wicd", version=VERSION_NUM, description="A wireless and wired network manager", diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..369c462 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,9 @@ + +def run_tests(): + import unittest + test_suite = unittest.TestSuite() + + import testwnettools + test_suite.addTest(testwnettools.suite()) + + unittest.TextTestRunner(verbosity=5).run(test_suite) diff --git a/tests/testwnettools.py b/tests/testwnettools.py new file mode 100644 index 0000000..2ace308 --- /dev/null +++ b/tests/testwnettools.py @@ -0,0 +1,66 @@ +import unittest +from wicd import wnettools + +class TestWnettools(unittest.TestCase): + def setUp(self): + self.interface = wnettools.BaseInterface('eth0') + + def test_find_wireless_interface(self): + interfaces = wnettools.GetWirelessInterfaces() + # wlan0 may change depending on your system + self.assertTrue('wlan0' in interfaces) + + def test_find_wired_interface(self): + interfaces = wnettools.GetWiredInterfaces() + # eth0 may change depending on your system + self.assertTrue('eth0' in interfaces) + + def test_wext_is_valid_wpasupplicant_driver(self): + self.assertTrue(wnettools.IsValidWpaSuppDriver('wext')) + + def test_needs_external_calls_not_implemented(self): + self.assertRaises(NotImplementedError, wnettools.NeedsExternalCalls) + + def test_get_ip_not_implemented(self): + self.assertRaises(NotImplementedError, self.interface.GetIP) + + def test_is_up_not_implemented(self): + self.assertRaises(NotImplementedError, self.interface.IsUp) + + def test_enable_debug_mode(self): + self.interface.SetDebugMode(True) + self.assertTrue(self.interface.verbose) + + def test_disable_debug_mode(self): + self.interface.SetDebugMode(False) + self.assertFalse(self.interface.verbose) + + def test_interface_name_sanitation(self): + interface = wnettools.BaseInterface('blahblah; uptime > /tmp/blah | cat') + self.assertEquals(interface.iface, 'blahblahuptimetmpblahcat') + + def test_freq_translation_low(self): + freq = '2.412 GHz' + interface = wnettools.BaseWirelessInterface('wlan0') + self.assertEquals(interface._FreqToChannel(freq), 1) + + def test_freq_translation_high(self): + freq = '2.484 GHz' + interface = wnettools.BaseWirelessInterface('wlan0') + self.assertEquals(interface._FreqToChannel(freq), 14) + + def test_generate_psk(self): + interface = wnettools.BaseWirelessInterface('wlan0') + psk = interface.GeneratePSK({'essid' : 'Network 1', 'key' : 'arandompassphrase'}) + self.assertEquals(psk, 'd70463014514f4b4ebb8e3aebbdec13f4437ac3a9af084b3433f3710e658a7be') + +def suite(): + suite = unittest.TestSuite() + tests = [] + [ tests.append(test) for test in dir(TestWnettools) if test.startswith('test') ] + for test in tests: + suite.addTest(TestWnettools(test)) + return suite + +if __name__ == '__main__': + unittest.main() diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 40114de..743b9e8 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -364,7 +364,8 @@ class TrayIcon(object): if DBUS_AVAIL: self.toggle_wicd_gui() else: - gui.error(None, language["daemon_unavailable"]) + # gui.error(None, language["daemon_unavailable"]) + pass def on_quit(self, widget=None): """ Closes the tray icon. """