12
sys.path.insert(0, "..")
14
import softwarecenter.utils
15
from softwarecenter.app import SoftwareCenterApp
16
from softwarecenter.paths import XAPIAN_BASE_PATH
17
from softwarecenter.enums import ActionButtons, TransactionTypes
18
from softwarecenter.utils import convert_desktop_file_to_installed_location
19
from softwarecenter.ui.gtk.appview import AppStore
21
# see https://wiki.ubuntu.com/SoftwareCenter#Learning%20how%20to%20launch%20an%20application
23
# we make s_c_app global as its relatively expensive to create
24
# and in setUp it would be created and destroyed for each
26
apt.apt_pkg.config.set("Dir::log::history", "/tmp")
27
#apt.apt_pkg.config.set("Dir::state::lists", "/tmp")
29
mock_options.enable_lp = False
30
mock_options.enable_buy = True
31
s_c_app = SoftwareCenterApp("../data", XAPIAN_BASE_PATH, mock_options)
32
s_c_app.window_main.show_all()
34
class TestUnityLauncherIntegration(unittest.TestCase):
42
while gtk.events_pending():
46
self.s_c_app = s_c_app
47
# monkey patch is_unity_running
48
softwarecenter.utils.is_unity_running = lambda: True
49
self.s_c_app.available_pane._send_dbus_signal_to_unity_launcher = Mock()
52
self.s_c_app.available_pane.navigation_bar.remove_all(animate=False)
57
def _run_search(self, search_text):
58
logging.info("_run_search", search_text)
59
self.s_c_app.available_pane.searchentry.delete_text(0, -1)
60
self.s_c_app.available_pane.searchentry.insert_text(search_text)
64
return self.s_c_app.available_pane.app_view.get_model()
66
def assertFirstPkgInModel(self, model, needle):
67
pkgname_from_row = model[0][AppStore.COL_PKGNAME]
69
pkgname_from_row, needle, "expected row '%s' got '%s'" % (
70
needle, pkgname_from_row))
72
def _navigate_to_pkgname_and_click_install(self, pkgname):
74
self.s_c_app.show_available_packages([pkgname])
76
appname = self.s_c_app.available_pane.app_details_view.app.appname
77
# pretend we started a install
78
self.s_c_app.backend.emit("transaction-started", pkgname, appname, "testid101", TransactionTypes.INSTALL)
82
def test_unity_launcher_stays_after_install_finished(self):
85
mock_result.pkgname = pkgname
86
mock_result.success = True
88
self._navigate_to_pkgname_and_click_install(pkgname)
90
self.s_c_app.backend.emit("transaction-finished", mock_result)
91
# this is normally set in the transaction-finished call but our
92
# app is not really installed so we need to mock it here
93
self.s_c_app.available_pane.unity_launcher_items[pkgname].installed_desktop_file_path = "/some/path"
96
# ensure we still have the button
97
button = self.s_c_app.available_pane.action_bar.get_button(
98
ActionButtons.ADD_TO_LAUNCHER)
99
self.assertNotEqual(button, None)
100
self.assertTrue(button.get_property("visible"))
101
# ensure we haven't called the launcher prematurely
102
self.assertFalse(self.s_c_app.available_pane._send_dbus_signal_to_unity_launcher.called)
103
# now click it and ensure its added even though the transaction is over
106
# ensure the button is gone
107
button = self.s_c_app.available_pane.action_bar.get_button(
108
ActionButtons.ADD_TO_LAUNCHER)
109
self.assertEqual(button, None)
110
self.assertTrue(self.s_c_app.available_pane._send_dbus_signal_to_unity_launcher.called)
113
def test_unity_launcher_integration(self):
114
pkgname = "lincity-ng"
115
self._navigate_to_pkgname_and_click_install(pkgname)
116
# verify that the panel is shown offering to add the app to the launcher
118
self.s_c_app.available_pane.action_bar.get_property("visible"))
119
button = self.s_c_app.available_pane.action_bar.get_button(
120
ActionButtons.ADD_TO_LAUNCHER)
121
self.assertTrue(button is not None)
125
# check that a correct UnityLauncherInfo object has been created and added to the queue
126
self.assertTrue(pkgname in self.s_c_app.available_pane.unity_launcher_items)
127
launcher_info = self.s_c_app.available_pane.unity_launcher_items.pop(pkgname)
128
# check the UnityLauncherInfo values themselves
129
self.assertEqual(launcher_info.name, "Lincity-ng")
130
self.assertEqual(launcher_info.icon_name, "lincity-ng")
131
self.assertTrue(launcher_info.icon_x > 20)
132
self.assertTrue(launcher_info.icon_y > 20)
133
self.assertEqual(launcher_info.icon_size, 84)
134
self.assertEqual(launcher_info.app_install_desktop_file_path, "/usr/share/app-install/desktop/lincity-ng.desktop")
135
self.assertEqual(launcher_info.trans_id, "testid101")
136
# finally, make sure the the app has been removed from the launcher queue
137
self.assertFalse(pkgname in self.s_c_app.available_pane.unity_launcher_items)
139
def test_desktop_file_path_conversion(self):
141
app_install_desktop_path = "./data/app-install/desktop/deja-dup.desktop"
142
installed_desktop_path = convert_desktop_file_to_installed_location(app_install_desktop_path)
143
self.assertEqual(installed_desktop_path, "./data/applications/deja-dup.desktop")
144
# test encoded subdirectory case, e.g. e.g. kde4_soundkonverter.desktop
145
app_install_desktop_path = "./data/app-install/desktop/kde4__soundkonverter.desktop"
146
installed_desktop_path = convert_desktop_file_to_installed_location(app_install_desktop_path)
147
self.assertEqual(installed_desktop_path, "./data/applications/kde4/soundkonverter.desktop")
148
# test the for-purchase case (uses "software-center-agent" as its appdetails.desktop_file value)
149
# FIXME: this will only work if update-manager is installed
150
app_install_desktop_path = "software-center-agent"
151
installed_desktop_path = convert_desktop_file_to_installed_location(app_install_desktop_path,
153
self.assertEqual(installed_desktop_path, "/usr/share/applications/update-manager.desktop")
154
# test case where we don't have a value for app_install_desktop_path (e.g. for a local .deb
155
# install, see bug LP: #768158)
156
installed_desktop_path = convert_desktop_file_to_installed_location(None,
158
# FIXME: this will only work if update-manager is installed
159
self.assertEqual(installed_desktop_path, "/usr/share/applications/update-manager.desktop")
162
if __name__ == "__main__":