Merge lp:~rvb/maas/bug-1154142-1.2 into lp:maas/1.2

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1373
Proposed branch: lp:~rvb/maas/bug-1154142-1.2
Merge into: lp:maas/1.2
Diff against target: 43 lines (+15/-0)
2 files modified
src/maasserver/api.py (+3/-0)
src/maasserver/tests/test_api.py (+12/-0)
To merge this branch: bzr merge lp:~rvb/maas/bug-1154142-1.2
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+152959@code.launchpad.net

Commit message

Backport revision 1455.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api.py'
2--- src/maasserver/api.py 2013-03-08 13:58:41 +0000
3+++ src/maasserver/api.py 2013-03-12 16:31:21 +0000
4@@ -102,6 +102,7 @@
5 PermissionDenied,
6 ValidationError,
7 )
8+from django.core.urlresolvers import reverse
9 from django.db.utils import DatabaseError
10 from django.forms.models import model_to_dict
11 from django.http import (
12@@ -1087,6 +1088,8 @@
13 # Encode the content as base64.
14 dict_representation['content'] = b64encode(
15 getattr(stored_file, 'content'))
16+ dict_representation['resource_uri'] = reverse(
17+ 'file_handler', args=[stored_file.filename])
18 # Emit the json for this object manually because, no matter what the
19 # piston documentation says, once a type is associated with a list
20 # of fields by piston's typemapper mechanism, there is no way to
21
22=== modified file 'src/maasserver/tests/test_api.py'
23--- src/maasserver/tests/test_api.py 2013-03-08 13:58:41 +0000
24+++ src/maasserver/tests/test_api.py 2013-03-12 16:31:21 +0000
25@@ -2948,6 +2948,18 @@
26 b64decode(parsed_result['content'])
27 ))
28
29+ def test_get_file_returns_file_object_with_resource_uri(self):
30+ filename = factory.make_name("file")
31+ content = sample_binary_data
32+ factory.make_file_storage(
33+ filename=filename, content=content, owner=self.logged_in_user)
34+ response = self.client.get(
35+ reverse('file_handler', args=[filename]))
36+ parsed_result = json.loads(response.content)
37+ self.assertEqual(
38+ reverse('file_handler', args=[filename]),
39+ parsed_result['resource_uri'])
40+
41 def test_get_file_returns_owned_file(self):
42 # If both an owned file and a non-owned file are present (with the
43 # same name), the owned file is returned.

Subscribers

People subscribed via source and target branches

to status/vote changes: