Merge lp:~gary-lasker/software-center/unit-tests into lp:software-center

Proposed by Gary Lasker
Status: Merged
Merged at revision: 2562
Proposed branch: lp:~gary-lasker/software-center/unit-tests
Merge into: lp:software-center
Diff against target: 239 lines (+218/-1)
3 files modified
test/gtk3/test_custom_lists.py (+64/-0)
test/gtk3/test_installedpane.py (+1/-1)
test/gtk3/test_unity_launcher_integration.py (+153/-0)
To merge this branch: bzr merge lp:~gary-lasker/software-center/unit-tests
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+82486@code.launchpad.net

Description of the change

This branch adds two new unit tests, the first to test custom list functionality and the second to test the current state of the Unity integration (the latter to be updated when implementing per the latest spec). These were left behind with the move to the the UI, so I pulled them over and updated them for gtk3 and the new design.

Simple changelog for this one:

  * test/gtk3/test_custom_lists.py,
    test/gtk3/test_unity_launcher_integration.py:
    - Add unit tests

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks! That looks good and gives us 71% coverage now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'test/gtk3/test_custom_lists.py'
2--- test/gtk3/test_custom_lists.py 1970-01-01 00:00:00 +0000
3+++ test/gtk3/test_custom_lists.py 2011-11-17 04:15:24 +0000
4@@ -0,0 +1,64 @@
5+#!/usr/bin/python
6+
7+from gi.repository import Gtk, GObject
8+import sys
9+import time
10+import unittest
11+
12+sys.path.insert(0,"../..")
13+sys.path.insert(0,"..")
14+
15+from softwarecenter.enums import XapianValues, ActionButtons
16+import softwarecenter.paths
17+softwarecenter.paths.datadir = "../data"
18+
19+TIMEOUT=300
20+
21+class TestCustomLists(unittest.TestCase):
22+
23+ def _debug(self, index, model, needle):
24+ print ("Expected '%s' at index '%s', " +
25+ "and custom list contained: '%s'") % (
26+ needle, index, model[index][0].get_value(XapianValues.PKGNAME))
27+
28+ def assertPkgInListAtIndex(self, index, model, needle):
29+ doc = model[index][0]
30+ self.assertEqual(doc.get_value(XapianValues.PKGNAME),
31+ needle, self._debug(index, model, needle))
32+
33+ def test_custom_lists(self):
34+ from softwarecenter.ui.gtk3.panes.availablepane import get_test_window
35+ win = get_test_window()
36+ pane = win.get_data("pane")
37+ self._p()
38+ pane.on_search_terms_changed(None, "ark,artha,software-center")
39+ self._p()
40+ model = pane.app_view.tree_view.get_model()
41+
42+ # custom list should return three items
43+ self.assertTrue(len(model) == 3)
44+
45+ # check package names, ordering is default "by relevance"
46+ self.assertPkgInListAtIndex(0, model, "ark")
47+ self.assertPkgInListAtIndex(1, model, "software-center")
48+ self.assertPkgInListAtIndex(2, model, "artha")
49+
50+ # check that the status bar offers to install the packages
51+ install_button = pane.action_bar.get_button(ActionButtons.INSTALL)
52+ self.assertNotEqual(install_button, None)
53+
54+ GObject.timeout_add(TIMEOUT, lambda: win.destroy())
55+ Gtk.main()
56+
57+ def _p(self):
58+ for i in range(10):
59+ time.sleep(0.1)
60+ while Gtk.events_pending():
61+ Gtk.main_iteration()
62+
63+
64+if __name__ == "__main__":
65+ import logging
66+ logging.basicConfig(level=logging.INFO)
67+ unittest.main()
68+
69
70=== modified file 'test/gtk3/test_installedpane.py'
71--- test/gtk3/test_installedpane.py 2011-09-16 13:07:53 +0000
72+++ test/gtk3/test_installedpane.py 2011-11-17 04:15:24 +0000
73@@ -15,7 +15,7 @@
74 import softwarecenter.paths
75 softwarecenter.paths.datadir = "../data"
76
77-class TestSearch(unittest.TestCase):
78+class TestInstalledPane(unittest.TestCase):
79
80 def test_installedpane(self):
81 from softwarecenter.ui.gtk3.panes.installedpane import get_test_window
82
83=== added file 'test/gtk3/test_unity_launcher_integration.py'
84--- test/gtk3/test_unity_launcher_integration.py 1970-01-01 00:00:00 +0000
85+++ test/gtk3/test_unity_launcher_integration.py 2011-11-17 04:15:24 +0000
86@@ -0,0 +1,153 @@
87+#!/usr/bin/python
88+
89+from gi.repository import Gtk
90+import sys
91+import time
92+import unittest
93+
94+from mock import Mock
95+
96+sys.path.insert(0,"../..")
97+sys.path.insert(0,"..")
98+
99+# overwrite early
100+import softwarecenter.paths
101+import softwarecenter.utils
102+softwarecenter.paths.datadir = "../data"
103+
104+from softwarecenter.enums import ActionButtons, TransactionTypes
105+from softwarecenter.utils import convert_desktop_file_to_installed_location
106+from softwarecenter.db.application import Application
107+from softwarecenter.ui.gtk3.panes.availablepane import get_test_window
108+
109+# we can only have one instance of availablepane, so create it here
110+win = get_test_window()
111+available_pane = win.get_data("pane")
112+
113+# see https://wiki.ubuntu.com/SoftwareCenter#Learning%20how%20to%20launch%20an%20application
114+
115+class TestUnityLauncherIntegration(unittest.TestCase):
116+
117+ def _zzz(self):
118+ for i in range(10):
119+ time.sleep(0.1)
120+ self._p()
121+
122+ def _p(self):
123+ while Gtk.events_pending():
124+ Gtk.main_iteration()
125+
126+ def setUp(self):
127+ # monkey patch is_unity_running
128+ softwarecenter.utils.is_unity_running = lambda: True
129+
130+ def _navigate_to_appdetails_and_install(self, pkgname):
131+ app = Application("", pkgname)
132+ available_pane.app_view.emit("application-activated",
133+ app)
134+ self._p()
135+
136+ # pretend we started an install
137+ available_pane.backend.emit("transaction-started",
138+ app.pkgname, app.appname,
139+ "testid101",
140+ TransactionTypes.INSTALL)
141+ # wait a wee bit
142+ self._zzz()
143+
144+ def test_unity_launcher_stays_after_install_finished(self):
145+ test_pkgname = "gl-117"
146+ mock_result = Mock()
147+ mock_result.pkgname = test_pkgname
148+ mock_result.success = True
149+ # now pretend
150+ # now pretend
151+ self._navigate_to_appdetails_and_install(test_pkgname)
152+ # pretend we are done
153+ available_pane.backend.emit("transaction-finished", mock_result)
154+ # this is normally set in the transaction-finished call but our
155+ # app is not really installed so we need to mock it here
156+ available_pane.unity_launcher_items[test_pkgname].installed_desktop_file_path = "/some/path"
157+ # wait a wee bit
158+ self._zzz()
159+ # ensure we still have the button
160+ button = available_pane.action_bar.get_button(
161+ ActionButtons.ADD_TO_LAUNCHER)
162+ self.assertNotEqual(button, None)
163+ self.assertTrue(button.get_property("visible"))
164+ # now click it even though the transaction is over
165+ button.clicked()
166+ self._zzz()
167+ # ensure the add to launcher button is now hidden
168+ button = available_pane.action_bar.get_button(
169+ ActionButtons.ADD_TO_LAUNCHER)
170+ self.assertEqual(button, None)
171+
172+ def test_unity_launcher_integration(self):
173+ test_pkgname = "lincity-ng"
174+ mock_result = Mock()
175+ mock_result.pkgname = test_pkgname
176+ mock_result.success = True
177+ # now pretend
178+ self._navigate_to_appdetails_and_install(test_pkgname)
179+
180+ # verify that the panel is shown offering to add the app to the launcher
181+ self.assertTrue(available_pane.action_bar.get_property("visible"))
182+ button = available_pane.action_bar.get_button(
183+ ActionButtons.ADD_TO_LAUNCHER)
184+ self.assertTrue(button is not None)
185+ # click the button
186+ button.clicked()
187+
188+ # check that a correct UnityLauncherInfo object has been created and
189+ # added to the queue
190+ self.assertTrue(test_pkgname in available_pane.unity_launcher_items)
191+ launcher_info = available_pane.unity_launcher_items.pop(test_pkgname)
192+ # check the UnityLauncherInfo values themselves
193+ self.assertEqual(launcher_info.name, "lincity-ng")
194+ self.assertEqual(launcher_info.icon_name, "lincity-ng")
195+ self.assertTrue(launcher_info.icon_x > 5)
196+ self.assertTrue(launcher_info.icon_y > 5)
197+ self.assertEqual(launcher_info.icon_size, 96)
198+ self.assertEqual(launcher_info.app_install_desktop_file_path,
199+ "/usr/share/app-install/desktop/lincity-ng:lincity-ng.desktop")
200+ self.assertEqual(launcher_info.trans_id, "testid101")
201+ # finally, make sure the the app has been removed from the launcher
202+ # queue
203+ self.assertFalse(test_pkgname in available_pane.unity_launcher_items)
204+
205+ def test_desktop_file_path_conversion(self):
206+ # test 'normal' case
207+ app_install_desktop_path = ("./data/app-install/desktop/" +
208+ "deja-dup:deja-dup.desktop")
209+ installed_desktop_path = convert_desktop_file_to_installed_location(
210+ app_install_desktop_path, "deja-dup")
211+ self.assertEqual(installed_desktop_path,
212+ "./data/applications/deja-dup.desktop")
213+ # test encoded subdirectory case, e.g. e.g. kde4_soundkonverter.desktop
214+ app_install_desktop_path = ("./data/app-install/desktop/" +
215+ "soundkonverter:" +
216+ "kde4__soundkonverter.desktop")
217+ installed_desktop_path = convert_desktop_file_to_installed_location(
218+ app_install_desktop_path, "soundkonverter")
219+ self.assertEqual(installed_desktop_path,
220+ "./data/applications/kde4/soundkonverter.desktop")
221+ # test the for-purchase case (uses "software-center-agent" as its
222+ # appdetails.desktop_file value)
223+ # FIXME: this will only work if update-manager is installed
224+ app_install_desktop_path = "software-center-agent"
225+ installed_desktop_path = convert_desktop_file_to_installed_location(
226+ app_install_desktop_path, "update-manager")
227+ self.assertEqual(installed_desktop_path,
228+ "/usr/share/applications/update-manager.desktop")
229+ # test case where we don't have a value for app_install_desktop_path
230+ # (e.g. for a local .deb install, see bug LP: #768158)
231+ installed_desktop_path = convert_desktop_file_to_installed_location(
232+ None, "update-manager")
233+ # FIXME: this will only work if update-manager is installed
234+ self.assertEqual(installed_desktop_path,
235+ "/usr/share/applications/update-manager.desktop")
236+
237+
238+if __name__ == "__main__":
239+ unittest.main()

Subscribers

People subscribed via source and target branches