~echidnaman/jockey/jockey-pykde4

« back to all changes in this revision

Viewing changes to tests/ui.py

  • Committer: Martin Pitt
  • Date: 2008-08-15 11:06:41 UTC
  • Revision ID: martin.pitt@canonical.com-20080815110641-wm66b52ztixmgul7
Add --dbus-server mode to UI

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# with this program; if not, write to the Free Software Foundation, Inc.,
19
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
 
21
 
import unittest, sys, os, signal, time
 
21
import unittest, sys, os, signal, time, traceback
22
22
from cStringIO import StringIO
23
23
import SimpleHTTPServer, BaseHTTPServer
24
24
 
720
720
 
721
721
        self.stop_capture()
722
722
        self.assert_('already supports' in self.stderr, self.stderr)
 
723
 
 
724
    # TODO: disabled, this currently breaks
 
725
    def teest_ui_dbus(self):
 
726
        '''UI --dbus-server'''
 
727
 
 
728
        svr_pid = os.fork()
 
729
        if svr_pid == 0:
 
730
            sys.argv = ['ui-test', '--dbus-server']
 
731
            try:
 
732
                sandbox.TestUI().run()
 
733
            except:
 
734
                print '********** UI D-BUS server failed: ***********'
 
735
                traceback.print_exc()
 
736
                os._exit(1)
 
737
            os._exit(0)
 
738
 
 
739
        time.sleep(2)
 
740
        iface = sandbox.TestUI.get_dbus_client()
 
741
 
 
742
        self.assertEqual(iface.search_driver('unknown:foo'), False)
 
743
 
 
744
        # shuts down after one request
 
745
        try:
 
746
            iface.search_driver('unknown:bar')
 
747
            fail('should only accept one method call and then terminate')
 
748
        except Exception, e:
 
749
            self.assertEqual(e._dbus_error_name, 'org.freedesktop.DBus.Error.NoReply')
 
750
 
 
751
        # give the daemon a second to terminate
 
752
        timeout = 10
 
753
        while timeout >= 0:
 
754
            (pid, exitcode) = os.waitpid(svr_pid, os.WNOHANG)
 
755
            if pid > 0:
 
756
                self.assertEqual(svr_pid, pid)
 
757
                self.assertEqual(exitcode, 0)
 
758
                break
 
759
            time.sleep(0.1)
 
760
            timeout -= 1
 
761
        if timeout <= 0:
 
762
            os.kill(svr_pid, signal.SIGKILL)
 
763
            os.waitpid(svr_pid, 0)
 
764
            self.fail('UI D-BUS server does not auto-terminate, killing')
 
765
 
 
766
    def test_search_driver_errors(self):
 
767
        '''D-BUS API: Search for drivers which cannot be enabled'''
 
768
 
 
769
        ui = sandbox.TestUI()
 
770
 
 
771
        # does not exist
 
772
        self.assertEqual(ui.search_driver('unknown:foo'), False)
 
773
 
 
774
        # kmod:vanilla, already enabled
 
775
        self.assertEqual(ui.search_driver(
 
776
            'modalias:pci:v00001001d0sv0sd0bc03sc00i00'), True)
 
777
 
 
778
    def test_search_driver_disabled(self):
 
779
        '''D-BUS API: Search for a noninstalled driver'''
 
780
 
 
781
        ui = sandbox.TestUI()
 
782
        ui.confirm_response = True
 
783
 
 
784
        sandbox.start_driverdb_server()
 
785
        try:
 
786
            ui.backend().add_driverdb('XMLRPCDriverDB', ['http://localhost:80080'])
 
787
            # first match is kmod:mint:UbuOne in our fake db
 
788
            result = ui.search_driver(
 
789
                'modalias:pci:v0000FFF0d00001sv0sd0bc06sc01i0')
 
790
        finally:
 
791
            sandbox.stop_driverdb_server()
 
792
 
 
793
        self.stop_capture()
 
794
        self.assertEqual(result, True)
 
795
 
 
796
        info = ui.backend().handler_info('kmod:mint:UbuOne')
 
797
        self.assertEqual(info['enabled'], 'True')