From cdcf71634ffc16a3cd09a2ee2641ddbaaba165ec Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 24 Mar 2018 15:31:13 +0200 Subject: Add: tests for downloading We're going to mess with uploading and download of data. Best have tests for them before we start. --- apifw.yarn | 13 ++++++++++++- apitest.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apifw.yarn b/apifw.yarn index a914ab9..064784b 100644 --- a/apifw.yarn +++ b/apifw.yarn @@ -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")" 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 -- cgit v1.2.1