summaryrefslogtreecommitdiff
path: root/yarns
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-06 17:20:09 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-09 20:56:44 +0300
commit614e0d87a7c7039c40b7db87e4593ee2567770e3 (patch)
tree9effe81a12cd6acc9851add3f70d07163e5cf4a4 /yarns
parent52b398761f0550c5a637007ab2aa780e9e1c53fe (diff)
downloadqvisqve-614e0d87a7c7039c40b7db87e4593ee2567770e3.tar.gz
Add: test scenario for managing blobs
Diffstat (limited to 'yarns')
-rw-r--r--yarns/900-implements.yarn46
-rw-r--r--yarns/lib.py20
-rw-r--r--yarns/smoke.yarn101
3 files changed, 166 insertions, 1 deletions
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index a5c267d..2f7ee0f 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -98,6 +98,32 @@ Start a Qvarn running in the background.
vars['status_code'], vars['headers'], vars['body'] = put(
vars['url'] + path, headers=headers, body=body)
+ IMPLEMENTS WHEN client requests PUT (/[a-z0-9/${}]+) with token, revision (\S+), content-type (\S+), and empty body
+ path = expand_vars(get_next_match(), vars)
+ revision = expand_vars(get_next_match(), vars)
+ ctype = expand_vars(get_next_match(), vars)
+ body = ''
+ headers = {
+ 'Authorization': 'Bearer {}'.format(vars['token']),
+ 'Revision': revision,
+ 'Content-Type': ctype,
+ }
+ vars['status_code'], vars['headers'], vars['body'] = put(
+ vars['url'] + path, headers=headers, body=body)
+
+ IMPLEMENTS WHEN client requests PUT (/[a-z0-9/${}]+) with token, revision (\S+), content-type (\S+), and body "(.+)"
+ path = expand_vars(get_next_match(), vars)
+ revision = expand_vars(get_next_match(), vars)
+ ctype = expand_vars(get_next_match(), vars)
+ body = unescape(expand_vars(get_next_match(), vars))
+ headers = {
+ 'Authorization': 'Bearer {}'.format(vars['token']),
+ 'Revision': revision,
+ 'Content-Type': ctype,
+ }
+ vars['status_code'], vars['headers'], vars['body'] = put(
+ vars['url'] + path, headers=headers, body=body)
+
IMPLEMENTS WHEN client requests DELETE (/.+) with token
path = get_next_match()
path = expand_vars(path, vars)
@@ -136,6 +162,11 @@ Start a Qvarn running in the background.
value = expand_vars(get_next_match(), vars)
assertEqual(vars['headers'].get(header), value)
+ IMPLEMENTS THEN remember HTTP (\S+) header as (.+)
+ header = get_next_match()
+ name = get_next_match()
+ vars[name] = vars['headers'].get(header)
+
IMPLEMENTS THEN resource id is (\S+)
import json
name = get_next_match()
@@ -149,6 +180,16 @@ Start a Qvarn running in the background.
body = json.loads(vars['body'])
vars[name] = body['revision']
+ IMPLEMENTS THEN revisions (\S+) and (\S+) are different
+ rev1 = get_next_match()
+ rev2 = get_next_match()
+ assertNotEqual(vars[rev1], vars[rev2])
+
+ IMPLEMENTS THEN revisions (\S+) and (\S+) match
+ rev1 = get_next_match()
+ rev2 = get_next_match()
+ assertEqual(vars[rev1], vars[rev2])
+
IMPLEMENTS THEN JSON body matches (.+)
import json
wanted = get_next_match()
@@ -161,6 +202,11 @@ Start a Qvarn running in the background.
print 'wanted3', repr(wanted)
assertTrue(values_match(wanted, actual))
+ IMPLEMENTS THEN body is "(.+)"
+ wanted = unescape(expand_vars(get_next_match(), vars))
+ body = vars['body']
+ assertTrue(values_match(wanted, body))
+
IMPLEMENTS THEN search result contains (.+)
import json
wanted1 = get_next_match()
diff --git a/yarns/lib.py b/yarns/lib.py
index 82e9133..459a821 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -36,6 +36,24 @@ datadir = os.environ['DATADIR']
vars = Variables(datadir)
+def hexdigit(c):
+ return ord(c) - ord('0')
+
+
+def unescape(s):
+ t = ''
+ while s:
+ if s.startswith('\\x') and len(s) >= 4:
+ a = hexdigit(s[2])
+ b = hexdigit(s[3])
+ t += chr(a * 16 + b)
+ s = s[4:]
+ else:
+ t += s[0]
+ s = s[1:]
+ return t
+
+
def add_postgres_config(config):
pg = os.environ.get('QVARN_POSTGRES')
if pg:
@@ -48,7 +66,7 @@ def add_postgres_config(config):
def get(url, headers=None):
print('get: url={} headers={}'.format(url, headers))
r = requests.get(url, headers=headers)
- return r.status_code, dict(r.headers), r.text
+ return r.status_code, dict(r.headers), r.content
def post(url, headers=None, body=None):
diff --git a/yarns/smoke.yarn b/yarns/smoke.yarn
index e56406f..6c960b6 100644
--- a/yarns/smoke.yarn
+++ b/yarns/smoke.yarn
@@ -485,6 +485,107 @@ don't need to be created specially.
FINALLY qvarn is stopped
+# Manage blobs
+
+Blobs are like sub-resources, but they're arbitrary binary data, not
+JSON.
+
+ SCENARIO manage blobs
+
+ GIVEN a running qvarn instance
+
+ WHEN client gets an authorization token with scope
+ ... "uapi_subjects_post uapi_subjects_blob_put uapi_subjects_blog_get"
+
+Create a subject.
+
+ WHEN client requests POST /subjects with token and body
+ ... { "type": "subject", "names": [ { "full_name": "Alfred" } ] }
+ THEN resource id is ID
+ AND revision is REV1
+
+Newly created subject does not have a blob.
+
+ WHEN client requests GET /subjects/${ID}/blob using token
+ THEN HTTP status code is 404 Not found
+
+Uploading an empty blob doesn't work.
+
+ WHEN client requests PUT /subjects/${ID}/blob with token,
+ ... revision REV1,
+ ... content-type image/jpeg,
+ ... and empty body
+ THEN HTTP status code is 411 Length required
+
+Uploading a COMPLETELY VALID JPEG as a blob fails, if subject resource
+revision is wrong.
+
+ WHEN client requests PUT /subjects/${ID}/blob with token,
+ ... revision BADREV,
+ ... content-type image/jpeg,
+ ... and body "FAKE JPEG"
+ THEN HTTP status code is 409 Conflict
+
+Uploading with valid revision works.
+
+ WHEN client requests PUT /subjects/${ID}/blob with token,
+ ... revision ${REV1},
+ ... content-type image/jpeg,
+ ... and body "FAKE JPEG"
+ THEN HTTP status code is 200 OK
+
+Do we get the right blob back? Also, note that subject revision
+should've changed.
+
+ WHEN client requests GET /subjects/${ID}/blob using token
+ THEN HTTP status code is 200 OK
+ AND HTTP Content-Type header is image/jpeg
+ AND body is "FAKE JPEG"
+ AND remember HTTP Revision header as REV2
+ AND revisions REV1 and REV2 are different
+
+Uploading with old revision fails.
+
+ WHEN client requests PUT /subjects/${ID}/blob with token,
+ ... revision ${REV1},
+ ... content-type image/jpeg,
+ ... and body "FAKE JPEG"
+ THEN HTTP status code is 409 Conflict
+
+Uploading a new blob with the current revision works.
+
+ WHEN client requests PUT /subjects/${ID}/blob with token,
+ ... revision ${REV2},
+ ... content-type image/jpeg,
+ ... and body "\x89"
+ THEN HTTP status code is 200 OK
+ AND remember HTTP Revision header as REV3
+
+And it did get updated.
+
+ WHEN client requests GET /subjects/${ID}/blob using token
+ THEN HTTP status code is 200 OK
+ AND HTTP Content-Type header is image/jpeg
+ AND body is "\x89"
+
+Updating parent doesn't affect the blob.
+
+ WHEN client requests PUT /subjects/${ID} with token and body
+ ... {
+ ... "type": "subject",
+ ... "revision": "${REV3}",
+ ... "names": [ { "full_name": "Melissa" } ]
+ ... }
+ THEN revision is REV4
+
+ WHEN client requests GET /subjects/${ID}/blob using token
+ THEN HTTP status code is 200 OK
+ AND HTTP Content-Type header is image/jpeg
+ AND body is "\x89"
+ AND remember HTTP Revision header as REV5
+ AND revisions REV4 and REV5 match
+
+ FINALLY qvarn is stopped
# Search subjects