~elachuni/software-center/pep8-test-part2

« back to all changes in this revision

Viewing changes to test/gtk3/test_unity_launcher_integration.py

  • Committer: Michael Vogt
  • Date: 2012-03-07 09:32:52 UTC
  • mfrom: (2809.3.6 software-center)
  • Revision ID: michael.vogt@ubuntu.com-20120307093252-w2uk1ymao1ka45uf
* lp:~gary-lasker/software-center/list-view-icon-coordinates-lp947624:
  - This branch adds support for providing the correct icon size and 
    on-screen coordinates values in the Unity launcher integration dbus 
    call when an installation is initiated via the list view. 
    LP: #947624

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from softwarecenter.ui.gtk3.panes.availablepane import get_test_window
17
17
from softwarecenter.backend.unitylauncher import UnityLauncherInfo
18
18
 
 
19
# Tests for Ubuntu Software Center's integration with the Unity launcher,
 
20
# see https://wiki.ubuntu.com/SoftwareCenter#Learning%20how%20to%20launch%20an%20application
 
21
 
19
22
# we can only have one instance of availablepane, so create it here
20
23
win = get_test_window()
21
24
available_pane = win.get_data("pane")
22
25
 
23
 
# see https://wiki.ubuntu.com/SoftwareCenter#Learning%20how%20to%20launch%20an%20application
24
 
 
25
26
class TestUnityLauncherIntegration(unittest.TestCase):
26
 
    
 
27
 
 
28
    def setUp(self):
 
29
        # monkey patch is_unity_running
 
30
        softwarecenter.utils.is_unity_running = lambda: True
 
31
        
27
32
    def _zzz(self):
28
33
        for i in range(10):
29
34
            time.sleep(0.1)
33
38
        while Gtk.events_pending():
34
39
            Gtk.main_iteration()
35
40
 
36
 
    def setUp(self):
37
 
        # monkey patch is_unity_running
38
 
        softwarecenter.utils.is_unity_running = lambda: True
 
41
    def _install_from_list_view(self, pkgname):
 
42
        from softwarecenter.ui.gtk3.panes.availablepane import AvailablePane
 
43
        available_pane.notebook.set_current_page(AvailablePane.Pages.LIST)
 
44
        
 
45
        self._p()
 
46
        available_pane.on_search_terms_changed(None, "ark,artha,software-center")
 
47
        self._p()
 
48
        
 
49
        # select the first item in the list
 
50
        available_pane.app_view.tree_view.set_cursor(Gtk.TreePath(0),
 
51
                                                            None, False)
 
52
        # ok to just use the test app here                                            
 
53
        app = Application("", pkgname)
 
54
        self._p()
 
55
        
 
56
        # pretend we started an install
 
57
        available_pane.backend.emit("transaction-started",
 
58
                                    app.pkgname, app.appname,
 
59
                                    "testid101",
 
60
                                    TransactionTypes.INSTALL)
 
61
        # wait a wee bit
 
62
        self._zzz()
39
63
 
40
64
    def _navigate_to_appdetails_and_install(self, pkgname):
41
65
        app = Application("", pkgname)
59
83
                         self.expected_launcher_info.icon_name)
60
84
        self.assertTrue(launcher_info.icon_x > 5)
61
85
        self.assertTrue(launcher_info.icon_y > 5)
62
 
        self.assertEqual(launcher_info.icon_size, 96)
 
86
        # check that the icon size is one of either 32 pixels (for the
 
87
        # list view case) or 96 pixels (for the details view case)
 
88
        self.assertTrue(launcher_info.icon_size == 32 or
 
89
                        launcher_info.icon_size == 96)
63
90
        self.assertEqual(launcher_info.app_install_desktop_file_path,
64
91
                self.expected_launcher_info.app_install_desktop_file_path)
65
92
        self.assertEqual(launcher_info.trans_id,
66
93
                self.expected_launcher_info.trans_id)
 
94
        
 
95
    def test_unity_launcher_integration_list_view(self):
 
96
        # test the automatic add to launcher enabled functionality when
 
97
        # installing an app form the list view
 
98
        available_pane.add_to_launcher_enabled = True
 
99
        test_pkgname = "lincity-ng"
 
100
        # now pretend
 
101
        # for testing, we substitute a fake version of UnityLauncher's
 
102
        # send_application_to_launcher method that lets us check for the
 
103
        # correct values and also avoids firing the actual dbus signal
 
104
        # to the unity launcher service
 
105
        self.expected_pkgname = test_pkgname
 
106
        self.expected_launcher_info = UnityLauncherInfo("lincity-ng",
 
107
                 "lincity-ng",
 
108
                 0, 0, 0, 0, # these values are set in availablepane
 
109
                 "/usr/share/app-install/desktop/lincity-ng:lincity-ng.desktop",
 
110
                 "testid101")
 
111
        available_pane.unity_launcher.send_application_to_launcher = (
 
112
                self._fake_send_application_to_launcher_and_check)
 
113
        self._install_from_list_view(test_pkgname)
67
114
 
68
 
    def test_unity_launcher_integration(self):
69
 
        # test the automatic add to launcher enabled functionality
 
115
    def test_unity_launcher_integration_details_view(self):
 
116
        # test the automatic add to launcher enabled functionality when
 
117
        # installing an app from the details view
70
118
        available_pane.add_to_launcher_enabled = True
71
119
        test_pkgname = "lincity-ng"
72
120
        # now pretend
134
182
        # FIXME: this will only work if update-manager is installed
135
183
        self.assertEqual(installed_desktop_path,
136
184
                         "/usr/share/applications/update-manager.desktop")
137
 
        
 
185
    
138
186
 
139
187
if __name__ == "__main__":
140
188
    unittest.main()