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

Subscribers

People subscribed via source and target branches