summaryrefslogtreecommitdiff
path: root/apitest.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-24 15:31:13 +0200
committerLars Wirzenius <liw@liw.fi>2018-03-24 18:13:54 +0200
commitcdcf71634ffc16a3cd09a2ee2641ddbaaba165ec (patch)
tree9b3a5d392382144d7a8b9c418f5484fe0b22b9fc /apitest.py
parentde78d0097e0feb858391010d3e8be784104ad28e (diff)
downloadapifw-cdcf71634ffc16a3cd09a2ee2641ddbaaba165ec.tar.gz
Add: tests for downloading
We're going to mess with uploading and download of data. Best have tests for them before we start.
Diffstat (limited to 'apitest.py')
-rw-r--r--apitest.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/apitest.py b/apitest.py
index 946e9e1..d28a61b 100644
--- a/apitest.py
+++ b/apitest.py
@@ -32,6 +32,10 @@ import apifw
class Api(apifw.Api):
+ def __init__(self):
+ super().__init__()
+ self._blob = None
+
def find_missing_route(self, path):
logging.info('find_missing_route called!\n')
return [
@@ -45,6 +49,11 @@ class Api(apifw.Api):
'path': '/upload',
'callback': self.upload,
},
+ {
+ 'method': 'GET',
+ 'path': '/download',
+ 'callback': self.download,
+ },
]
def version(self, content_type, body, **kwargs):
@@ -57,6 +66,7 @@ class Api(apifw.Api):
})
def upload(self, content_type, body, **kwargs):
+ self._blob = body
return apifw.Response({
'status': apifw.HTTP_OK,
'body': 'thank you for %s\n' % body.decode('ascii'),
@@ -65,6 +75,15 @@ class Api(apifw.Api):
},
})
+ def download(self, content_type, body, **kwargs):
+ return apifw.Response({
+ 'status': apifw.HTTP_OK,
+ 'body': self._blob,
+ 'headers': {
+ 'Content-Type': 'text/plain',
+ },
+ })
+
# We want logging. gunicorn provides logging, but only of its own
# stuff, and if we log something ourselves, using logging.debug and