summaryrefslogtreecommitdiff
path: root/apitest.py
diff options
context:
space:
mode:
Diffstat (limited to 'apitest.py')
-rw-r--r--apitest.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/apitest.py b/apitest.py
index 946e9e1..0a55756 100644
--- a/apitest.py
+++ b/apitest.py
@@ -19,7 +19,9 @@
import logging
import os
+import tempfile
+import bottle
import yaml
import apifw
@@ -32,6 +34,11 @@ import apifw
class Api(apifw.Api):
+ def __init__(self):
+ super().__init__()
+ fd, self._filename = tempfile.mkstemp()
+ os.close(fd)
+
def find_missing_route(self, path):
logging.info('find_missing_route called!\n')
return [
@@ -44,6 +51,12 @@ class Api(apifw.Api):
'method': 'PUT',
'path': '/upload',
'callback': self.upload,
+ 'big-blobs': True,
+ },
+ {
+ 'method': 'GET',
+ 'path': '/download',
+ 'callback': self.download,
},
]
@@ -57,14 +70,23 @@ class Api(apifw.Api):
})
def upload(self, content_type, body, **kwargs):
+ mega = 2 ** 20
+ read = bottle.request.environ['wsgi.input'].read
+ with open(self._filename, 'wb') as f:
+ for part in body(mega):
+ f.write(part)
+
return apifw.Response({
'status': apifw.HTTP_OK,
- 'body': 'thank you for %s\n' % body.decode('ascii'),
+ 'body': 'thank you for your data\n',
'headers': {
'Content-Type': 'text/plain',
},
})
+ def download(self, content_type, body, **kwargs):
+ raise apifw.StaticFile(self._filename)
+
# We want logging. gunicorn provides logging, but only of its own
# stuff, and if we log something ourselves, using logging.debug and