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
1=== modified file 'tests/autopilot/address_book_app/tests/test_edit_contact.py'
2--- tests/autopilot/address_book_app/tests/test_edit_contact.py 2014-07-03 16:56:55 +0000
3+++ tests/autopilot/address_book_app/tests/test_edit_contact.py 2014-07-04 18:44:06 +0000
4@@ -223,32 +223,34 @@
5 def test_press_photo_icon(self):
6 """Test to press the photo icon on the contact editor"""
7 print('Running test_press_photo_icon')
8- url_dispatcher = FakeURLDispatcher()
9- self.useFixture(url_dispatcher)
10+ content_hub = FakeContentHub()
11+ self.useFixture(content_hub)
12 contact_editor = self.main_window.go_to_add_contact()
13 contact_editor.press_photo_icon()
14
15- def get_last_dispatch_url_call_parameter():
16+ def get_last_import_from_peer_parameters():
17 # Workaround for http://pad.lv/1312384
18 try:
19- return url_dispatcher.get_last_dispatch_url_call_parameter()
20+ fake_service = content_hub.fake_service
21+ return fake_service.get_last_import_from_peer_parameters()
22 except ContactEditorException:
23 return None
24
25 self.assertThat(
26- get_last_dispatch_url_call_parameter,
27- Eventually(Equals('image://theme/contact')))
28+ get_last_import_from_peer_parameters,
29+ Eventually(Equals(('', ''))))
30+ print(content_hub.fake_service.import_mock.GetCalls())
31
32
33 class ContactEditorException(Exception):
34 """Exception raised from ContactEditor"""
35
36
37-class FakeURLDispatcher(fixtures.Fixture):
38+class FakeContentHub(fixtures.Fixture):
39
40 def setUp(self):
41- super(FakeURLDispatcher, self).setUp()
42- self.fake_service = FakeURLDispatcherService()
43+ super(FakeContentHub, self).setUp()
44+ self.fake_service = FakeContentHubService()
45 self.addCleanup(self.fake_service.stop)
46 self.fake_service.start()
47
48@@ -256,33 +258,38 @@
49 return self.fake_service.get_last_dispatch_url_call_parameter()
50
51
52-class FakeURLDispatcherService(object):
53+class FakeContentHubService(object):
54
55- """Fake URL Dispatcher service using a dbusmock interface."""
56+ """Fake Content Hub service using a dbusmock interface."""
57
58 def __init__(self):
59- super(FakeURLDispatcherService, self).__init__()
60+ super(FakeContentHubService, self).__init__()
61 self.dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)
62
63 def start(self):
64- """Start the fake URL Dispatcher service."""
65- # Stop the real url-dispatcher.
66- subprocess.call(['initctl', 'stop', 'url-dispatcher'])
67+ """Start the fake Content Hub service."""
68+ # Stop the real content-hub.
69+ subprocess.call(['pkill', '-9', '-f', 'content-hub-service'])
70 self.dbus_mock_server = dbusmock.DBusTestCase.spawn_server(
71- 'com.canonical.URLDispatcher',
72- '/com/canonical/URLDispatcher',
73- 'com.canonical.URLDispatcher',
74+ 'com.ubuntu.content.dbus.Service',
75+ '/',
76+ 'com.ubuntu.content.dbus.Service',
77 system_bus=False,
78 stdout=subprocess.PIPE)
79 self.mock = self._get_mock_interface()
80+ import_path = '/transfers/_/import/'
81+ import_id = '1'
82 self.mock.AddMethod(
83- 'com.canonical.URLDispatcher', 'DispatchURL', 's', '', '')
84- print('Started fake url dispatcher')
85+ 'com.ubuntu.content.dbus.Service',
86+ 'CreateImportFromPeer', 'ss', 'o',
87+ 'ret = "{}{}"'.format(import_path, import_id))
88+ self.add_import_object(import_path, import_id)
89+ print('Started fake content hub')
90
91 def _get_mock_interface(self):
92 return dbus.Interface(
93 self.dbus_connection.get_object(
94- 'com.canonical.URLDispatcher', '/com/canonical/URLDispatcher'),
95+ 'com.ubuntu.content.dbus.Service', '/'),
96 dbusmock.MOCK_IFACE)
97
98 def stop(self):
99@@ -290,12 +297,41 @@
100 self.dbus_mock_server.terminate()
101 self.dbus_mock_server.wait()
102
103- def get_last_dispatch_url_call_parameter(self):
104+ def get_last_import_from_peer_parameters(self):
105 """Return the parameter used in the last call to dispatch URL."""
106 calls = self.mock.GetCalls()
107 print(('Number of calls:{}'.format(len(calls))))
108 if len(calls) == 0:
109 raise ContactEditorException(
110- 'URL dispatcher has not been called.')
111+ 'Content hub has not been called.')
112 last_call = self.mock.GetCalls()[-1]
113- return last_call[2][0]
114\ No newline at end of file
115+ return last_call[2][0], last_call[2][1]
116+
117+ def add_import_object(self, object_path, object_id):
118+ self.mock.AddObject(
119+ object_path + object_id,
120+ 'com.ubuntu.content.dbus.Transfer',
121+ {},
122+ [
123+ ('Abort', '', '', ''),
124+ ('Charge', 'as', '', ''),
125+ ('Collect', '', 'as', ''),
126+ ('Direction', '', 'i', 'return 0'),
127+ ('Download', '', '', ''),
128+ ('DownloadId', '', 's', ''),
129+ ('Finalize', '', '', ''),
130+ ('Handled', '', '', ''),
131+ ('Id', '', 'i', 'ret ' + object_id),
132+ ('SelectionType', '', 'i', ''),
133+ ('SetDownloadId', 's', '', ''),
134+ ('SetSelectionType', 'i', '', ''),
135+ ('SetStore', 's', '', ''),
136+ ('Start', '', '', ''),
137+ ('State', '', 'i', ''),
138+ ('Store', '', 's', '')
139+ ]
140+ )
141+ self.import_mock = dbus.Interface(
142+ self.dbus_connection.get_object(
143+ 'com.ubuntu.content.dbus.Service', object_path + object_id),
144+ dbusmock.MOCK_IFACE)

Subscribers

People subscribed via source and target branches

to all changes: