diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-03-24 15:31:13 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-03-24 18:13:54 +0200 |
commit | cdcf71634ffc16a3cd09a2ee2641ddbaaba165ec (patch) | |
tree | 9b3a5d392382144d7a8b9c418f5484fe0b22b9fc | |
parent | de78d0097e0feb858391010d3e8be784104ad28e (diff) | |
download | apifw-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.
-rw-r--r-- | apifw.yarn | 13 | ||||
-rw-r--r-- | apitest.py | 19 |
2 files changed, 31 insertions, 1 deletions
@@ -38,7 +38,12 @@ It's a silly name. Please suggest something better. WHEN client gets an authorization token with scope "uapi_upload_put" AND client uploads a fake jpg THEN HTTP status code is 200 OK - AND HTTP body is "thank you for fake jpg" + AND HTTP body is "thank you for your data" + + WHEN client gets an authorization token with scope "uapi_download_get" + AND client requests GET /download using token + THEN HTTP status code is 200 OK + AND HTTP body is "fake jpg" FINALLY stop apitest @@ -87,6 +92,12 @@ It's a silly name. Please suggest something better. curl -sv -H "Authorization: Bearer $token" \ "http://127.0.0.1:$port/version" > "$DATADIR/out" 2> "$DATADIR/err" + IMPLEMENTS WHEN client requests GET /download using token + token="$(cat "$DATADIR/token")" + port="$(cat "$DATADIR/port")" + curl -sv -H "Authorization: Bearer $token" \ + "http://127.0.0.1:$port/download" > "$DATADIR/out" 2> "$DATADIR/err" + IMPLEMENTS WHEN client uploads a fake jpg token="$(cat "$DATADIR/token")" port="$(cat "$DATADIR/port")" @@ -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 |