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
21 return "/tid/%d" % self
.x
27 def connect_to_signal(self
, signal
, cb
):
28 self
.signals
[signal
] = cb
31 def get_dbus_method(self
, method
):
32 if hasattr(self
, method
):
33 return getattr(self
, method
)
34 raise dbus
.exceptions
.DBusException('org.freedesktop.DBus.Error.UnknownMethod')
36 def SetLocale(self
, locale
):
40 def Resolve(self
, query
, package_names
):
45 for package_name
in package_names
:
46 if package_name
== 'gimp':
48 self
.signals
['Package'](info
, "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "summary")
50 self
.signals
['Error']("package-not-found", "Package name %s could not be resolved" % package_name
)
53 self
.signals
['Finished'](result
, 100)
57 def GetDetails(self
, package_ids
):
61 for package_id
in package_ids
:
62 assert package_id
== "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu"
63 self
.signals
['Details'](package_id
, "GPL", "Graphics", "detail", "http://foo", 100)
66 self
.signals
['Finished']("success", 100)
70 def GetProgress(self
):
71 # %task, %sub-task, time-task, time-sub-task
72 return (50, 101, 351, 0)
74 def InstallPackages(self
, only_trusted
, package_ids
= None):
75 if package_ids
is None:
77 raise dbus
.exceptions
.DBusException('org.freedesktop.DBus.Error.UnknownMethod')
79 assert only_trusted
== False
83 for package_id
in package_ids
:
84 assert package_id
== "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu"
85 self
.signals
['StatusChanged']("setup")
87 # Unknown % for task and subtask
89 #self.signals['ProgressChanged'](101, 101, 0, 0)
93 #self.signals['ProgressChanged'](50, 101, 351, 0)
95 #self.signals['AllowCancel'](False)
96 self
.signals
['Package']("installing", "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "Graphics package")
100 #self.signals['ProgressChanged'](100, 101, 1351, 0)
101 self
.signals
['Package']("finished", "gimp;2.6.8-2ubuntu1.1;amd64;Ubuntu", "Graphics package")
104 self
.signals
['Finished']("success", 100)
107 class TestPackageKit(BaseTest
):
113 BaseTest
.tearDown(self
)
115 def find_module(self
, fullname
, path
=None):
116 if fullname
.startswith('dbus'):
117 raise ImportError("No (dummy) D-BUS")
121 def testNoDBUS(self
):
125 sys
.meta_path
= [self
]
126 del sys
.modules
['dbus']
128 imp
.reload(packagekit
)
130 pk
= packagekit
.PackageKit()
131 assert pk
.available
== False
133 factory
= Exception("not called")
134 pk
.get_candidates('gimp', factory
, 'package:null')
137 sys
.modules
['dbus'] = old_dbus
139 def testNoPackageKit(self
):
140 imp
.reload(packagekit
)
141 pk
= packagekit
.PackageKit()
142 assert not pk
.available
144 factory
= Exception("not called")
145 pk
.get_candidates('gimp', factory
, 'package:null')
147 def testPackageKit05(self
):
148 #import logging; logging.getLogger().setLevel(logging.DEBUG)
150 dbus
.system_services
['org.freedesktop.PackageKit'] = {
151 '/org/freedesktop/PackageKit': PackageKit05(),
152 '/tid/1': PackageKit05
.Tid1(),
153 '/tid/2': PackageKit05
.Tid2(),
154 '/tid/3': PackageKit05
.Install(),
156 imp
.reload(packagekit
)
157 pk
= packagekit
.PackageKit()
160 factory
= Exception("not called")
161 pk
.get_candidates('gimp', factory
, 'package:test')
163 blocker
= pk
.fetch_candidates(["gimp"])
164 tasks
.wait_for_blocker(blocker
)
168 def factory(impl_id
, only_if_missing
, installed
):
169 assert impl_id
.startswith('package:')
170 assert only_if_missing
is True
171 assert installed
is False
175 impl
= model
.DistributionImplementation(feed
, impl_id
, self
)
176 impl
.installed
= installed
177 impls
[impl_id
] = impl
180 pk
.get_candidates('gimp', factory
, 'package:test')
181 self
.assertEqual(["package:test:gimp:2.6.8-2:x86_64"], impls
.keys())
183 impl
, = impls
.values()
184 fetcher
= fetch
.Fetcher(config
= self
.config
)
185 self
.config
.handler
.allow_downloads
= True
186 b
= fetcher
.download_impl(impl
, impl
.download_sources
[0], stores
= None)
187 tasks
.wait_for_blocker(b
)
190 if __name__
== '__main__':