1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
# Copyright (C) 2011 Canonical
#
# Authors:
# Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
import subprocess
import sys
import tempfile
import time
m_dbus = m_polkit = m_aptd = None
def start_dummy_backend():
global m_dbus, m_polkit, m_aptd
# start private dbus
m_dbus = subprocess.Popen(["dbus-daemon",
"--session",
"--nofork",
"--print-address"],
stdout=subprocess.PIPE)
# get and store address
bus_address = m_dbus.stdout.readline().strip()
os.environ["SOFTWARE_CENTER_APTD_FAKE"] = bus_address
# start fake polkit from python-aptdaemon.test
env = {"DBUS_SESSION_BUS_ADDRESS": bus_address,
"DBUS_SYSTEM_BUS_ADDRESS": bus_address,
}
m_polkit = subprocess.Popen(
["/usr/share/aptdaemon/tests/fake-polkitd.py",
"--allowed-actions=all"],
env=env)
# start aptd in dummy mode
m_aptd = subprocess.Popen(
["/usr/sbin/aptd", "--dummy", "--session-bus", "--disable-timeout"],
env=env)
# the sleep here is not ideal, but we need to wait a little bit
# to ensure that the fake daemon and fake polkit is ready
time.sleep(0.5)
def stop_dummy_backend():
global m_dbus, m_polkit, m_aptd
m_aptd.terminate()
m_aptd.wait()
m_polkit.terminate()
m_polkit.wait()
m_dbus.terminate()
m_dbus.wait()
def get_test_gtk3_viewmanager():
from gi.repository import Gtk
from softwarecenter.ui.gtk3.session.viewmanager import (
ViewManager, get_viewmanager)
vm = get_viewmanager()
if not vm:
notebook = Gtk.Notebook()
vm = ViewManager(notebook)
vm.view_to_pane = {None: None}
return vm
def get_test_db():
from softwarecenter.db.database import StoreDatabase
from softwarecenter.db.pkginfo import get_pkg_info
import softwarecenter.paths
cache = get_pkg_info()
cache.open()
db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
db.open()
return db
def get_test_install_backend():
from softwarecenter.backend.installbackend import get_install_backend
backend = get_install_backend()
return backend
def get_test_gtk3_icon_cache():
from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
import softwarecenter.paths
icons = get_sc_icon_theme(softwarecenter.paths.datadir)
return icons
def get_test_pkg_info():
from softwarecenter.db.pkginfo import get_pkg_info
cache = get_pkg_info()
cache.open()
return cache
def get_test_datadir():
import softwarecenter.paths
return softwarecenter.paths.datadir
def get_test_categories(db):
import softwarecenter.paths
from softwarecenter.db.categories import CategoriesParser
parser = CategoriesParser(db)
cats = parser.parse_applications_menu(
softwarecenter.paths.APP_INSTALL_PATH)
return cats
def get_test_enquirer_matches(db, query=None, limit=20, sortmode=0):
from softwarecenter.db.enquire import AppEnquire
import xapian
if query is None:
query = xapian.Query("")
enquirer = AppEnquire(db._aptcache, db)
enquirer.set_query(query,
sortmode=sortmode,
limit=limit,
nonblocking_load=False)
return enquirer.matches
def do_events():
from gi.repository import GObject
main_loop = GObject.main_context_default()
while main_loop.pending():
main_loop.iteration()
def get_mock_app_from_real_app(real_app):
""" take a application and return a app where the details are a mock
of the real details so they can easily be modified
"""
from mock import Mock
import copy
app = copy.copy(real_app)
db = get_test_db()
details = app.get_details(db)
details_mock = Mock(details)
for a in dir(details):
if a.startswith("_"):
continue
setattr(details_mock, a, getattr(details, a))
app.details = details_mock
app.get_details = lambda db: app.details
return app
def setup_test_env():
""" Setup environment suitable for running the test/* code in a checkout.
This includes PYTHONPATH, sys.path and softwarecenter.paths.datadir.
"""
basedir = os.path.dirname(__file__)
while not os.path.exists(
os.path.join(basedir, "softwarecenter/__init__.py")):
basedir = os.path.abspath(os.path.join(basedir, ".."))
#print basedir, __file__, os.path.realpath(__file__)
sys.path.insert(0, basedir)
os.environ["PYTHONPATH"] = basedir
import softwarecenter.paths
softwarecenter.paths.datadir = os.path.join(basedir, "data")
softwarecenter.paths.SOFTWARE_CENTER_CACHE_DIR = tempfile.mkdtemp()
# factory stuff for the agent
def make_software_center_agent_app_dict():
app_dict = {
u'archive_root': 'http://private-ppa.launchpad.net/',
u'archive_id': u'commercial-ppa-uploaders/photobomb',
u'description': u"Easy and Social Image Editor\nPhotobomb "
u"give you easy access to images in your "
u"social networking feeds, pictures on ...",
u'name': u'Photobomb',
u'package_name': u'photobomb',
u'signing_key_id': u'1024R/75254D99',
u'screenshot_url': 'http://software-center.ubuntu.com/site_media/'\
'screenshots/2011/08/Screenshot.png',
u'license': 'Proprietary',
u'support_url': 'mailto:support@example.com',
u'series': {'oneiric': ['i386', 'amd64'],
'natty': ['i386', 'amd64'],
},
u'channel': 'For Purchase',
u'icon_url': 'http://software-center.ubuntu.com/site_media/icons/'\
'2011/08/64_Chainz.png',
u'categories': 'Game;LogicGame',
}
return app_dict
def make_software_center_agent_subscription_dict(app_dict):
subscription_dict = {
u'application': app_dict,
u'deb_line': u'deb https://some.user:ABCDEFGHIJKLMNOP@'
u'private-ppa.launchpad.net/commercial-ppa-uploaders/'
u'photobomb/ubuntu natty main',
u'distro_series': {u'code_name': u'natty', u'version': u'11.04'},
u'failures': [],
u'open_id': u'https://login.ubuntu.com/+id/ABCDEF',
u'purchase_date': u'2011-09-16 06:37:52',
u'purchase_price': u'2.99',
u'state': u'Complete',
}
return subscription_dict
def make_recommender_agent_recommend_me_dict():
# best to have a list of likely not-installed items
app_dict = {
u'data': [
{
u'package_name': u'clementine'
},
{
u'package_name': u'hedgewars'
},
{
u'package_name': u'mangler'
},
{
u'package_name': u'nexuiz'
},
{
u'package_name': u'fgo'
},
{
u'package_name': u'musique'
},
{
u'package_name': u'pybik'
},
{
u'package_name': u'radiotray'
},
{
u'package_name': u'cherrytree'
},
{
u'package_name': u'phlipple'
},
{
u'package_name': u'psi'
},
{
u'package_name': u'midori'
}
]
}
return app_dict
def make_recommender_profile_upload_data():
from softwarecenter.utils import get_uuid
recommender_uuid = get_uuid()
profile_upload_data = [
{
'uuid': recommender_uuid,
'package_list': [
u'clementine',
u'hedgewars',
u'mangler',
u'nexuiz',
u'fgo',
u'musique',
u'pybik',
u'radiotray',
u'cherrytree',
u'phlipple',
u'psi',
u'midori'
]
}
]
return profile_upload_data
def make_recommend_app_data():
recommend_app_data = {
u'rid': u'265c0bb1dece93a96c5a528e7ea5dd75',
u'data': [
{u'rating': 4.0, u'package_name': u'kftpgrabber'},
{u'rating': 4.0, u'package_name': u'sugar-emulator-0.90'},
{u'rating': 3.0, u'package_name': u'wakeup'},
{u'rating': 3.0, u'package_name': u'xvidcap'},
{u'rating': 2.0, u'package_name': u'airstrike'},
{u'rating': 2.0, u'package_name': u'pixbros'},
{u'rating': 2.0, u'package_name': u'bomber'},
{u'rating': 2.0, u'package_name': u'ktron'},
{u'rating': 2.0, u'package_name': u'gnome-mousetrap'},
{u'rating': 1.5, u'package_name': u'tucan'}],
u'app': u'pitivi'}
return recommend_app_data
|