Merge lp:~elopio/address-book-app/content-hub into lp:~rhuddie/address-book-app/add-photo-helper

Proposed by Leo Arias
Status: Needs review
Proposed branch: lp:~elopio/address-book-app/content-hub
Merge into: lp:~rhuddie/address-book-app/add-photo-helper
Diff against target: 144 lines (+60/-24)
1 file modified
tests/autopilot/address_book_app/tests/test_edit_contact.py (+60/-24)
To merge this branch: bzr merge lp:~elopio/address-book-app/content-hub
Reviewer Review Type Date Requested Status
Richard Huddie Pending
Review via email: mp+225705@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

222. By Leo Arias

Changed the fake for content-hub.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/address_book_app/tests/test_edit_contact.py'
--- tests/autopilot/address_book_app/tests/test_edit_contact.py 2014-07-03 16:56:55 +0000
+++ tests/autopilot/address_book_app/tests/test_edit_contact.py 2014-07-04 18:44:06 +0000
@@ -223,32 +223,34 @@
223 def test_press_photo_icon(self):223 def test_press_photo_icon(self):
224 """Test to press the photo icon on the contact editor"""224 """Test to press the photo icon on the contact editor"""
225 print('Running test_press_photo_icon')225 print('Running test_press_photo_icon')
226 url_dispatcher = FakeURLDispatcher()226 content_hub = FakeContentHub()
227 self.useFixture(url_dispatcher)227 self.useFixture(content_hub)
228 contact_editor = self.main_window.go_to_add_contact()228 contact_editor = self.main_window.go_to_add_contact()
229 contact_editor.press_photo_icon()229 contact_editor.press_photo_icon()
230230
231 def get_last_dispatch_url_call_parameter():231 def get_last_import_from_peer_parameters():
232 # Workaround for http://pad.lv/1312384232 # Workaround for http://pad.lv/1312384
233 try:233 try:
234 return url_dispatcher.get_last_dispatch_url_call_parameter()234 fake_service = content_hub.fake_service
235 return fake_service.get_last_import_from_peer_parameters()
235 except ContactEditorException:236 except ContactEditorException:
236 return None237 return None
237238
238 self.assertThat(239 self.assertThat(
239 get_last_dispatch_url_call_parameter,240 get_last_import_from_peer_parameters,
240 Eventually(Equals('image://theme/contact')))241 Eventually(Equals(('', ''))))
242 print(content_hub.fake_service.import_mock.GetCalls())
241243
242244
243class ContactEditorException(Exception):245class ContactEditorException(Exception):
244 """Exception raised from ContactEditor"""246 """Exception raised from ContactEditor"""
245247
246248
247class FakeURLDispatcher(fixtures.Fixture):249class FakeContentHub(fixtures.Fixture):
248250
249 def setUp(self):251 def setUp(self):
250 super(FakeURLDispatcher, self).setUp()252 super(FakeContentHub, self).setUp()
251 self.fake_service = FakeURLDispatcherService()253 self.fake_service = FakeContentHubService()
252 self.addCleanup(self.fake_service.stop)254 self.addCleanup(self.fake_service.stop)
253 self.fake_service.start()255 self.fake_service.start()
254256
@@ -256,33 +258,38 @@
256 return self.fake_service.get_last_dispatch_url_call_parameter()258 return self.fake_service.get_last_dispatch_url_call_parameter()
257259
258260
259class FakeURLDispatcherService(object):261class FakeContentHubService(object):
260262
261 """Fake URL Dispatcher service using a dbusmock interface."""263 """Fake Content Hub service using a dbusmock interface."""
262264
263 def __init__(self):265 def __init__(self):
264 super(FakeURLDispatcherService, self).__init__()266 super(FakeContentHubService, self).__init__()
265 self.dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)267 self.dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)
266268
267 def start(self):269 def start(self):
268 """Start the fake URL Dispatcher service."""270 """Start the fake Content Hub service."""
269 # Stop the real url-dispatcher.271 # Stop the real content-hub.
270 subprocess.call(['initctl', 'stop', 'url-dispatcher'])272 subprocess.call(['pkill', '-9', '-f', 'content-hub-service'])
271 self.dbus_mock_server = dbusmock.DBusTestCase.spawn_server(273 self.dbus_mock_server = dbusmock.DBusTestCase.spawn_server(
272 'com.canonical.URLDispatcher',274 'com.ubuntu.content.dbus.Service',
273 '/com/canonical/URLDispatcher',275 '/',
274 'com.canonical.URLDispatcher',276 'com.ubuntu.content.dbus.Service',
275 system_bus=False,277 system_bus=False,
276 stdout=subprocess.PIPE)278 stdout=subprocess.PIPE)
277 self.mock = self._get_mock_interface()279 self.mock = self._get_mock_interface()
280 import_path = '/transfers/_/import/'
281 import_id = '1'
278 self.mock.AddMethod(282 self.mock.AddMethod(
279 'com.canonical.URLDispatcher', 'DispatchURL', 's', '', '')283 'com.ubuntu.content.dbus.Service',
280 print('Started fake url dispatcher')284 'CreateImportFromPeer', 'ss', 'o',
285 'ret = "{}{}"'.format(import_path, import_id))
286 self.add_import_object(import_path, import_id)
287 print('Started fake content hub')
281288
282 def _get_mock_interface(self):289 def _get_mock_interface(self):
283 return dbus.Interface(290 return dbus.Interface(
284 self.dbus_connection.get_object(291 self.dbus_connection.get_object(
285 'com.canonical.URLDispatcher', '/com/canonical/URLDispatcher'),292 'com.ubuntu.content.dbus.Service', '/'),
286 dbusmock.MOCK_IFACE)293 dbusmock.MOCK_IFACE)
287294
288 def stop(self):295 def stop(self):
@@ -290,12 +297,41 @@
290 self.dbus_mock_server.terminate()297 self.dbus_mock_server.terminate()
291 self.dbus_mock_server.wait()298 self.dbus_mock_server.wait()
292299
293 def get_last_dispatch_url_call_parameter(self):300 def get_last_import_from_peer_parameters(self):
294 """Return the parameter used in the last call to dispatch URL."""301 """Return the parameter used in the last call to dispatch URL."""
295 calls = self.mock.GetCalls()302 calls = self.mock.GetCalls()
296 print(('Number of calls:{}'.format(len(calls))))303 print(('Number of calls:{}'.format(len(calls))))
297 if len(calls) == 0:304 if len(calls) == 0:
298 raise ContactEditorException(305 raise ContactEditorException(
299 'URL dispatcher has not been called.')306 'Content hub has not been called.')
300 last_call = self.mock.GetCalls()[-1]307 last_call = self.mock.GetCalls()[-1]
301 return last_call[2][0]
302\ No newline at end of file308\ No newline at end of file
309 return last_call[2][0], last_call[2][1]
310
311 def add_import_object(self, object_path, object_id):
312 self.mock.AddObject(
313 object_path + object_id,
314 'com.ubuntu.content.dbus.Transfer',
315 {},
316 [
317 ('Abort', '', '', ''),
318 ('Charge', 'as', '', ''),
319 ('Collect', '', 'as', ''),
320 ('Direction', '', 'i', 'return 0'),
321 ('Download', '', '', ''),
322 ('DownloadId', '', 's', ''),
323 ('Finalize', '', '', ''),
324 ('Handled', '', '', ''),
325 ('Id', '', 'i', 'ret ' + object_id),
326 ('SelectionType', '', 'i', ''),
327 ('SetDownloadId', 's', '', ''),
328 ('SetSelectionType', 'i', '', ''),
329 ('SetStore', 's', '', ''),
330 ('Start', '', '', ''),
331 ('State', '', 'i', ''),
332 ('Store', '', 's', '')
333 ]
334 )
335 self.import_mock = dbus.Interface(
336 self.dbus_connection.get_object(
337 'com.ubuntu.content.dbus.Service', object_path + object_id),
338 dbusmock.MOCK_IFACE)

Subscribers

People subscribed via source and target branches

to all changes: