Merge lp:~rvb/maas/bug-1154142 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1455
Proposed branch: lp:~rvb/maas/bug-1154142
Merge into: lp:~maas-committers/maas/trunk
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
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Jeroen T. Vermeulen (community) Approve
Review via email: mp+152943@code.launchpad.net

Commit message

Add 'resource_uri' when returning the JSONized value of a file.

Description of the change

We're generating the JSON representation of a file manually (because we're base64-encoding its content), we also need to populate the value of 'resource_uri' manually. The Go provider relies on that.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Thanks for the testing, and the fix! The "Add the resource_uri" comment is probably a bit overkill — this is python and it's pretty clear what you're doing.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

I think a workaround will need to go into gomaasapi too, because this has probably missed the SRU.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

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:46:34 +0000
3+++ src/maasserver/api.py 2013-03-12 16:02:21 +0000
4@@ -104,6 +104,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@@ -845,6 +846,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:46:34 +0000
24+++ src/maasserver/tests/test_api.py 2013-03-12 16:02:21 +0000
25@@ -2861,6 +2861,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.