1
# Copyright (C) 2011 Canonical
6
# This program is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation; version 3.
10
# This program is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
m_dbus = m_polkit = m_aptd = None
24
def start_dummy_backend():
25
global m_dbus, m_polkit, m_aptd
27
m_dbus = subprocess.Popen(["dbus-daemon",
31
stdout=subprocess.PIPE)
32
# get and store address
33
bus_address = m_dbus.stdout.readline().strip()
34
os.environ["SOFTWARE_CENTER_APTD_FAKE"] = bus_address
35
# start fake polkit from python-aptdaemon.test
36
env = { "DBUS_SESSION_BUS_ADDRESS" : bus_address,
38
m_polkit = subprocess.Popen(
39
["/usr/share/aptdaemon/tests/fake-polkitd.py",
40
"--allowed-actions=all"],
42
# start aptd in dummy mode
43
m_aptd = subprocess.Popen(
44
["/usr/sbin/aptd","--dummy", "--session-bus", "--disable-timeout"],
46
# the sleep here is not ideal, but we need to wait a little bit
47
# to ensure that the fake daemon and fake polkit is ready
50
def stop_dummy_backend():
51
global m_dbus, m_polkit, m_aptd
59
def get_test_gtk3_viewmanager():
60
from gi.repository import Gtk
61
from softwarecenter.ui.gtk3.session.viewmanager import (
62
ViewManager, get_viewmanager)
63
vm = get_viewmanager()
65
notebook = Gtk.Notebook()
66
vm = ViewManager(notebook)
67
vm.view_to_pane = {None : None}
71
from softwarecenter.db.database import StoreDatabase
72
from softwarecenter.db.pkginfo import get_pkg_info
73
import softwarecenter.paths
74
cache = get_pkg_info()
76
db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
80
def get_test_install_backend():
81
from softwarecenter.backend.installbackend import get_install_backend
82
backend = get_install_backend()
85
def get_test_gtk3_icon_cache():
86
from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
87
import softwarecenter.paths
88
icons = get_sc_icon_theme(softwarecenter.paths.datadir)
91
def get_test_pkg_info():
92
from softwarecenter.db.pkginfo import get_pkg_info
93
cache = get_pkg_info()
97
def get_test_datadir():
98
import softwarecenter.paths
99
return softwarecenter.paths.datadir
101
def get_test_enquirer_matches(db, query=None, limit=20, sortmode=0):
102
from softwarecenter.db.enquire import AppEnquire
105
query = xapian.Query("")
106
enquirer = AppEnquire(db._aptcache, db)
107
enquirer.set_query(query,
110
nonblocking_load=False)
111
return enquirer.matches
114
from gi.repository import GObject
115
main_loop = GObject.main_context_default()
116
while main_loop.pending():
117
main_loop.iteration()
119
def get_mock_app_from_real_app(real_app):
120
""" take a application and return a app where the details are a mock
121
of the real details so they can easily be modified
123
from mock import Mock
125
app = copy.copy(real_app)
127
details = app.get_details(db)
128
details_mock = Mock()
129
for a in dir(details):
130
if a.startswith("_"): continue
131
setattr(details_mock, a, getattr(details, a))
132
app._details = details_mock
133
app.get_details = lambda db: app._details