summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2015-12-21 10:44:37 +0100
committerNavaL <mnandri@thoughtworks.com>2015-12-21 11:00:14 +0100
commit651568ff85bde4aa152ba18eed8b587f4f2f3cab (patch)
tree732b92a3de4bf74ac710d314b7e622a60f94b04e
parent4e7679766932e3d29914607f0db64ef8613b22b7 (diff)
added filename and size to the attachment endpoint post response
Issue #548
-rw-r--r--service/pixelated/resources/attachments_resource.py6
-rw-r--r--service/test/integration/test_retrieve_attachment.py6
-rw-r--r--service/test/unit/resources/test_attachments_resource.py5
-rw-r--r--service/test/unit/resources/test_mails_resource.py9
4 files changed, 19 insertions, 7 deletions
diff --git a/service/pixelated/resources/attachments_resource.py b/service/pixelated/resources/attachments_resource.py
index 05bc923f..19b5d0bc 100644
--- a/service/pixelated/resources/attachments_resource.py
+++ b/service/pixelated/resources/attachments_resource.py
@@ -94,7 +94,11 @@ class AttachmentsResource(Resource):
def send_location(attachment_id):
request.headers['Location'] = '/%s/%s' % (self.BASE_URL, attachment_id)
- respond_json_deferred({"attachment_id": attachment_id}, request, status_code=201)
+ response_json = {"attachment_id": attachment_id,
+ "content-type": _file.type,
+ "filename": _file.filename,
+ "filesize": len(_file.value)}
+ respond_json_deferred(response_json, request, status_code=201)
def error_handler(error):
print error
diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py
index b6010666..0998e688 100644
--- a/service/test/integration/test_retrieve_attachment.py
+++ b/service/test/integration/test_retrieve_attachment.py
@@ -67,4 +67,8 @@ class RetrieveAttachmentTest(SoledadTestBase):
self.assertEqual(201, req.code)
self.assertEqual('/attachment/B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A', req.headers['Location'])
- self.assertEqual({'attachment_id': 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A'}, json.loads(req.written[0]))
+ response_json = {'attachment_id': 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A',
+ 'content-type': content_type,
+ 'filename': filename,
+ 'filesize': len(data)}
+ self.assertEqual(response_json, json.loads(req.written[0]))
diff --git a/service/test/unit/resources/test_attachments_resource.py b/service/test/unit/resources/test_attachments_resource.py
index 2afa208c..c44dab84 100644
--- a/service/test/unit/resources/test_attachments_resource.py
+++ b/service/test/unit/resources/test_attachments_resource.py
@@ -27,6 +27,7 @@ class AttachmentsResourceTest(unittest.TestCase):
_file = MagicMock()
_file.value = 'some mocked value'
_file.type = 'some mocked type'
+ _file.filename = 'filename.txt'
mock_fields.return_value = {'attachment': _file}
when(self.mail_service).save_attachment('some mocked value', 'some mocked type').thenReturn(defer.succeed(attachment_id))
@@ -35,7 +36,9 @@ class AttachmentsResourceTest(unittest.TestCase):
def assert_response(_):
self.assertEqual(201, request.code)
self.assertEqual('/attachment/%s' % attachment_id, request.headers['Location'])
- self.assertEqual({'attachment_id': attachment_id}, json.loads(request.written[0]))
+ response_json = {'attachment_id': attachment_id, 'content-type': 'some mocked type',
+ 'filename': 'filename.txt', 'filesize': 17}
+ self.assertEqual(response_json, json.loads(request.written[0]))
verify(self.mail_service).save_attachment('some mocked value', 'some mocked type')
d.addCallback(assert_response)
diff --git a/service/test/unit/resources/test_mails_resource.py b/service/test/unit/resources/test_mails_resource.py
index 44aebd4d..76fe8bb3 100644
--- a/service/test/unit/resources/test_mails_resource.py
+++ b/service/test/unit/resources/test_mails_resource.py
@@ -15,13 +15,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import unittest
-import json
+
+from mock import patch
from mockito import mock, when, verify
-from test.unit.resources import DummySite
+from twisted.internet import defer
from twisted.web.test.requesthelper import DummyRequest
+
from pixelated.resources.mails_resource import MailsResource
-from twisted.internet import defer
-from mock import patch
+from test.unit.resources import DummySite
class TestMailsResource(unittest.TestCase):