Merge lp:~mandel/ubuntuone-client/add_ipc_client_code_7 into lp:ubuntuone-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Roberto Alsina
Approved revision: 987
Merged at revision: 982
Proposed branch: lp:~mandel/ubuntuone-client/add_ipc_client_code_7
Merge into: lp:ubuntuone-client
Prerequisite: lp:~mandel/ubuntuone-client/add_ipc_client_code_6
Diff against target: 254 lines (+229/-1)
2 files modified
tests/platform/windows/test_ipc.py (+186/-1)
ubuntuone/platform/windows/ipc_client.py (+43/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/add_ipc_client_code_7
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Shane Fagan (community) Approve
Review via email: mp+59514@code.launchpad.net

Commit message

Adds a client side object that allows to access to the public files API provided by the sync daemon. This allows client applications to perform the IPC more easily.

Description of the change

Adds a client side object that allows to access to the public files API provided by the sync daemon. This allows client applications to perform the IPC more easily.

This is a windows only change and the way to test it is:

C:\Users\Mandel\Documents\ubuntuone-client\continue-ipc>python C:\Python27\Scripts\u1trial tests\platform\windows\test_ipc.py

To post a comment you must log in.
Revision history for this message
Shane Fagan (shanepatrickfagan) :
review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/windows/test_ipc.py'
2--- tests/platform/windows/test_ipc.py 2011-04-29 14:11:08 +0000
3+++ tests/platform/windows/test_ipc.py 2011-04-29 14:11:09 +0000
4@@ -46,6 +46,7 @@
5 EventsClient,
6 FoldersClient,
7 FileSystemClient,
8+ PublicFilesClient,
9 StatusClient,
10 SyncDaemonClient,
11 SharesClient
12@@ -2693,4 +2694,188 @@
13 d.addCallback(test_emit)
14 # pylint: enable=E1101
15 return d
16-
17\ No newline at end of file
18+
19+
20+class TestPublicFilesClient(TestCase):
21+ """Test the status client class."""
22+
23+ def setUp(self):
24+ """Setup tests."""
25+ super(TestPublicFilesClient, self).setUp()
26+ self.mocker = Mocker()
27+ self.root = self.mocker.mock()
28+ self.files = PublicFiles(None, None)
29+ self.files.syncdaemon_public_files = self.root
30+ # start pb
31+ self.syncdaemon_root = SyncDaemonRoot(None, None, None, None,
32+ None, None, None, self.files)
33+ self.server_factory = SaveProtocolServerFactory(self.syncdaemon_root)
34+ # pylint: disable=E1101
35+ self.listener = reactor.listenTCP(0, self.server_factory)
36+ self.client_factory = PBClientFactory()
37+ self.connector = reactor.connectTCP('localhost',
38+ self.listener.getHost().port,
39+ self.client_factory)
40+ # pylint: enable=E1101
41+
42+ def tearDown(self):
43+ """Clean reactor."""
44+ if self.server_factory.protocolInstance is not None:
45+ self.server_factory.protocolInstance.transport.loseConnection()
46+ return defer.gatherResults([self._tearDownServer(),
47+ self._tearDownClient()])
48+
49+ def _tearDownServer(self):
50+ """Teardown the server."""
51+ return defer.maybeDeferred(self.listener.stopListening)
52+
53+ def _tearDownClient(self):
54+ """Tear down the client."""
55+ self.connector.disconnect()
56+ return defer.succeed(None)
57+
58+ @defer.inlineCallbacks
59+ def _get_client(self):
60+ """Get the client."""
61+ # request the remote object and create a client
62+ root = yield self.client_factory.getRootObject()
63+ remote = yield root.callRemote('get_public_files')
64+ client = PublicFilesClient(remote)
65+ yield client.register_to_signals()
66+ # set the cb
67+ for signal in ['on_public_access_changed_cb',
68+ 'on_public_access_change_error_cb',
69+ 'on_public_files_list_cb',
70+ 'on_public_files_list_error_cb']:
71+ setattr(client, signal, self.mocker.mock())
72+ defer.returnValue(client)
73+
74+ def test_change_public_access(self):
75+ """Change the public access of a file."""
76+ share_id = 'share_id'
77+ node_id = 'node_id'
78+ is_public = False
79+
80+ @defer.inlineCallbacks
81+ def test_execution(client):
82+ """Actual test."""
83+ self.root.change_public_access(share_id, node_id, is_public)
84+ self.mocker.replay()
85+ yield client.change_public_access(share_id, node_id, is_public)
86+ yield client.unregister_to_signals()
87+ self.mocker.verify()
88+
89+ d = self._get_client()
90+ # pylint: disable=E1101
91+ d.addCallback(test_execution)
92+ # pylint: enable=E1101
93+ return d
94+
95+ def test_get_public_files(self):
96+ """Request the list of public files to the server."""
97+
98+ @defer.inlineCallbacks
99+ def test_execution(client):
100+ """Actual test."""
101+ self.root.get_public_files()
102+ self.mocker.replay()
103+ yield client.get_public_files()
104+ yield client.unregister_to_signals()
105+ self.mocker.verify()
106+
107+ d = self._get_client()
108+ # pylint: disable=E1101
109+ d.addCallback(test_execution)
110+ # pylint: enable=E1101
111+ return d
112+
113+ def test_on_public_access_changed(self):
114+ """Emit the PublicAccessChanged signal."""
115+ share_id = 'share_id'
116+ node_id = 'node_id'
117+ is_public = False
118+ public_url = 'public_url'
119+ path = 'path'
120+ info_dict = dict(path=path, public_url=public_url, share_id=share_id,
121+ node_id=node_id, is_public='')
122+
123+ @defer.inlineCallbacks
124+ def test_emit(client):
125+ """Actual test."""
126+ self.root.get_path(share_id, node_id)
127+ self.mocker.result(path)
128+ client.on_public_access_changed_cb(info_dict)
129+ self.mocker.replay()
130+ self.files.emit_public_access_changed(share_id, node_id, is_public,
131+ public_url)
132+ yield client.unregister_to_signals()
133+ self.mocker.verify()
134+
135+ d = self._get_client()
136+ # pylint: disable=E1101
137+ d.addCallback(test_emit)
138+ # pylint: enable=E1101
139+ return d
140+
141+ def test_on_public_access_change_error(self):
142+ """Emit the PublicAccessChangeError signal."""
143+ share_id = 'share_id'
144+ node_id = 'node_id'
145+ error = 'error'
146+ path = 'path'
147+ info = dict(share_id=share_id, node_id=node_id, path=path)
148+
149+ @defer.inlineCallbacks
150+ def test_emit(client):
151+ """Actual test."""
152+ self.root.get_path(share_id, node_id)
153+ self.mocker.result(path)
154+ client.on_public_access_change_error_cb(info, error)
155+ self.mocker.replay()
156+ self.files.emit_public_access_change_error(share_id, node_id, error)
157+ yield client.unregister_to_signals()
158+ self.mocker.verify()
159+
160+ d = self._get_client()
161+ # pylint: disable=E1101
162+ d.addCallback(test_emit)
163+ # pylint: enable=E1101
164+ return d
165+
166+ def test_on_public_files_list(self):
167+ """Emit the PublicFilesList signal."""
168+ public_files = []
169+
170+ @defer.inlineCallbacks
171+ def test_emit(client):
172+ """Actual test."""
173+ client.on_public_files_list_cb(public_files)
174+ self.mocker.replay()
175+ self.files.emit_public_files_list(public_files)
176+ yield client.unregister_to_signals()
177+ self.mocker.verify()
178+
179+ d = self._get_client()
180+ # pylint: disable=E1101
181+ d.addCallback(test_emit)
182+ # pylint: enable=E1101
183+ return d
184+
185+ def test_on_public_files_list_error(self):
186+ """Emit the PublicFilesListError signal."""
187+ error = 'error'
188+
189+ @defer.inlineCallbacks
190+ def test_emit(client):
191+ """Actual test."""
192+ client.on_public_files_list_error_cb(error)
193+ self.mocker.replay()
194+ self.files.emit_public_files_list_error(error)
195+ yield client.unregister_to_signals()
196+ self.mocker.verify()
197+
198+ d = self._get_client()
199+ # pylint: disable=E1101
200+ d.addCallback(test_emit)
201+ # pylint: enable=E1101
202+ return d
203\ No newline at end of file
204
205=== modified file 'ubuntuone/platform/windows/ipc_client.py'
206--- ubuntuone/platform/windows/ipc_client.py 2011-04-29 14:11:08 +0000
207+++ ubuntuone/platform/windows/ipc_client.py 2011-04-29 14:11:09 +0000
208@@ -614,3 +614,46 @@
209 @signal
210 def on_folder_unsubscribe_error(self, folder_id, error):
211 """Emit the FolderUnSubscribeError signal"""
212+
213+
214+class PublicFilesClient(RemoteClient, Referenceable):
215+ """An IPC interface for handling public files."""
216+
217+ __metaclass__ = RemoteMeta
218+
219+ # calls that will be accessible remotely
220+ remote_calls = ['on_public_access_changed',
221+ 'on_public_access_change_error',
222+ 'on_public_files_list',
223+ 'on_public_files_list_error']
224+
225+ def __init__(self, remote_public_files):
226+ super(PublicFilesClient, self).__init__(remote_public_files)
227+
228+ @remote
229+ def change_public_access(self, share_id, node_id, is_public):
230+ """Change the public access of a file."""
231+
232+ @remote
233+ def get_public_files(self):
234+ """Request the list of public files to the server.
235+
236+ The result will be send in a PublicFilesList signal.
237+ """
238+
239+ @signal
240+ def on_public_access_changed(self, share_id, node_id, is_public,
241+ public_url):
242+ """Emit the PublicAccessChanged signal."""
243+
244+ @signal
245+ def on_public_access_change_error(self, share_id, node_id, error):
246+ """Emit the PublicAccessChangeError signal."""
247+
248+ @signal
249+ def on_public_files_list(self, public_files):
250+ """Emit the PublicFilesList signal."""
251+
252+ @signal
253+ def on_public_files_list_error(self, error):
254+ """Emit the PublicFilesListError signal."""

Subscribers

People subscribed via source and target branches