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
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2013-03-08 13:46:34 +0000
+++ src/maasserver/api.py 2013-03-12 16:02:21 +0000
@@ -104,6 +104,7 @@
104 PermissionDenied,104 PermissionDenied,
105 ValidationError,105 ValidationError,
106 )106 )
107from django.core.urlresolvers import reverse
107from django.db.utils import DatabaseError108from django.db.utils import DatabaseError
108from django.forms.models import model_to_dict109from django.forms.models import model_to_dict
109from django.http import (110from django.http import (
@@ -845,6 +846,8 @@
845 # Encode the content as base64.846 # Encode the content as base64.
846 dict_representation['content'] = b64encode(847 dict_representation['content'] = b64encode(
847 getattr(stored_file, 'content'))848 getattr(stored_file, 'content'))
849 dict_representation['resource_uri'] = reverse(
850 'file_handler', args=[stored_file.filename])
848 # Emit the json for this object manually because, no matter what the851 # Emit the json for this object manually because, no matter what the
849 # piston documentation says, once a type is associated with a list852 # piston documentation says, once a type is associated with a list
850 # of fields by piston's typemapper mechanism, there is no way to853 # of fields by piston's typemapper mechanism, there is no way to
851854
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2013-03-08 13:46:34 +0000
+++ src/maasserver/tests/test_api.py 2013-03-12 16:02:21 +0000
@@ -2861,6 +2861,18 @@
2861 b64decode(parsed_result['content'])2861 b64decode(parsed_result['content'])
2862 ))2862 ))
28632863
2864 def test_get_file_returns_file_object_with_resource_uri(self):
2865 filename = factory.make_name("file")
2866 content = sample_binary_data
2867 factory.make_file_storage(
2868 filename=filename, content=content, owner=self.logged_in_user)
2869 response = self.client.get(
2870 reverse('file_handler', args=[filename]))
2871 parsed_result = json.loads(response.content)
2872 self.assertEqual(
2873 reverse('file_handler', args=[filename]),
2874 parsed_result['resource_uri'])
2875
2864 def test_get_file_returns_owned_file(self):2876 def test_get_file_returns_owned_file(self):
2865 # If both an owned file and a non-owned file are present (with the2877 # If both an owned file and a non-owned file are present (with the
2866 # same name), the owned file is returned.2878 # same name), the owned file is returned.