2 from basetest
import BaseTest
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.injector
import packagekit
, handler
, model
, fetch
8 from zeroinstall
.support
import tasks
17 return "/tid/%d" % self
.x
23 def connect_to_signal(self
, signal
, cb
):
24 self
.signals
[signal
] = cb
26 def get_dbus_method(self
, method
):
27 if hasattr(self
, method
):
28 return getattr(self
, method
)
29 raise dbus
.exceptions
.DBusException('org.freedesktop.DBus.Error.UnknownMethod')
31 def SetLocale(self
, locale
):
35 def Resolve(self
, query
, package_names
):
40 for package_name
in package_names
:
41 if package_name
== 'gimp':
43 self
.signals
['Package'](info
, "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "summary")
45 self
.signals
['Error']("package-not-found", "Package name %s could not be resolved" % package_name
)
48 self
.signals
['Finished'](result
, 100)
52 def GetDetails(self
, package_ids
):
56 for package_id
in package_ids
:
57 assert package_id
== "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu"
58 self
.signals
['Details'](package_id
, "GPL", "Graphics", "detail", "http://foo", 100)
61 self
.signals
['Finished']("success", 100)
65 def GetProgress(self
):
66 # %task, %sub-task, time-task, time-sub-task
67 return (50, 101, 351, 0)
69 def InstallPackages(self
, only_trusted
, package_ids
= None):
70 if package_ids
is None:
72 raise dbus
.exceptions
.DBusException('org.freedesktop.DBus.Error.UnknownMethod')
74 assert only_trusted
== False
78 for package_id
in package_ids
:
79 assert package_id
== "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu"
80 self
.signals
['StatusChanged']("setup")
82 # Unknown % for task and subtask
84 #self.signals['ProgressChanged'](101, 101, 0, 0)
88 #self.signals['ProgressChanged'](50, 101, 351, 0)
90 #self.signals['AllowCancel'](False)
91 self
.signals
['Package']("installing", "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "Graphics package")
95 #self.signals['ProgressChanged'](100, 101, 1351, 0)
96 self
.signals
['Package']("finished", "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "Graphics package")
99 self
.signals
['Finished']("success", 100)
102 class TestPackageKit(BaseTest
):
108 BaseTest
.tearDown(self
)
110 def find_module(self
, fullname
, path
=None):
111 if fullname
.startswith('dbus'):
112 raise ImportError("No (dummy) D-BUS")
116 def testNoDBUS(self
):
120 sys
.meta_path
= [self
]
121 del sys
.modules
['dbus']
125 pk
= packagekit
.PackageKit()
126 assert pk
.available
== False
128 factory
= Exception("not called")
129 pk
.get_candidates('gimp', factory
, 'package:null')
132 sys
.modules
['dbus'] = old_dbus
134 def testNoPackageKit(self
):
136 pk
= packagekit
.PackageKit()
137 assert not pk
.available
139 factory
= Exception("not called")
140 pk
.get_candidates('gimp', factory
, 'package:null')
142 def testPackageKit05(self
):
143 #import logging; logging.getLogger().setLevel(logging.DEBUG)
145 dbus
.system_services
['org.freedesktop.PackageKit'] = {
146 '/org/freedesktop/PackageKit': PackageKit05(),
147 '/tid/1': PackageKit05
.Tid1(),
148 '/tid/2': PackageKit05
.Tid2(),
149 '/tid/3': PackageKit05
.Install(),
152 pk
= packagekit
.PackageKit()
155 factory
= Exception("not called")
156 pk
.get_candidates('gimp', factory
, 'package:test')
158 blocker
= pk
.fetch_candidates(["gimp"])
159 tasks
.wait_for_blocker(blocker
)
163 def factory(impl_id
, only_if_missing
, installed
):
164 assert impl_id
.startswith('package:')
165 assert only_if_missing
is True
166 assert installed
is False
170 impl
= model
.DistributionImplementation(feed
, impl_id
, self
)
171 impl
.installed
= installed
172 impls
[impl_id
] = impl
175 pk
.get_candidates('gimp', factory
, 'package:test')
176 self
.assertEquals(["package:test:gimp:2.6.8-2:x86_64"], impls
.keys())
178 impl
, = impls
.values()
179 fetcher
= fetch
.Fetcher(config
= self
.config
)
180 self
.config
.handler
.allow_downloads
= True
181 b
= fetcher
.download_impl(impl
, impl
.download_sources
[0], stores
= None)
182 tasks
.wait_for_blocker(b
)
185 if __name__
== '__main__':