From d8f880bec11ee7d81a3715a1677b4b29ebbef201 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 15 Dec 2017 16:45:33 +0200 Subject: Refactor: add function http, for easier requests --- yarns/900-implements.yarn | 53 +++++++++-------------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) (limited to 'yarns/900-implements.yarn') diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index afddb3b..069b37b 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -34,33 +34,21 @@ along with this program. If not, see . path = get_next_match() token = get_token(user) url = vars['url'] - status, content_type, headers, body = get(url + path, token) - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, get, url + path, token=token) IMPLEMENTS WHEN (\S+) retrieves (\S+) from blob service user = get_next_match() path = get_next_match() token = get_token(user) url = vars['bsurl'] - status, content_type, headers, body = get_blob(url + path, token) - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body.encode('hex') + http(vars, get_blob, url + path, token=token) IMPLEMENTS WHEN (\S+) makes request GET (\S+) with an invalid token user = get_next_match() path = get_next_match() token = get_token(user) url = vars['url'] - status, content_type, headers, body = get(url + path, 'invalid') - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, get, url + path, token='invalid') IMPLEMENTS WHEN (\S+) makes request POST (\S+) with a valid token and body (.+) user = get_next_match() @@ -70,11 +58,7 @@ along with this program. If not, see . print('body', body_text) token = get_token(user) url = vars['url'] - status, content_type, headers, body = post(url + path, body_text, token) - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, post, url + path, body_text=body_text, token=token) IMPLEMENTS WHEN (\S+) makes request POST (\S+) with an invalid token and body (.+) user = get_next_match() @@ -84,11 +68,7 @@ along with this program. If not, see . print('body', body_text) token = get_token(user) url = vars['url'] - status, content_type, headers, body = post(url + path, body_text, 'invalid') - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body.encode('hex') + http(vars, post, url + path, body_text=body_text, token='invalid') IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with a valid token and body (.+) user = get_next_match() @@ -99,11 +79,7 @@ along with this program. If not, see . print('body', body_text) token = get_token(user) url = vars['url'] - status, content_type, headers, body = put(url + path, body_text, token) - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, put, url + path, body_text=body_text, token=token) IMPLEMENTS WHEN (\S+) sends blob (\S+) to blob service as (\S+) user = get_next_match() @@ -112,8 +88,7 @@ along with this program. If not, see . body = cat(filename) token = get_token(user) url = vars['bsurl'] - status, content_type, headers, body = put_blob(url + path, body, token) - vars['status_code'] = status + http(vars, put_blob, url + path, body=body, token=token) IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with an invalid token user = get_next_match() @@ -124,22 +99,14 @@ along with this program. If not, see . print('body', body_text) token = get_token(user) url = vars['url'] - status, content_type, headers, body = put(url + path, body_text, 'invalid') - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, put, url + path, body_text=body_text, token='invalid') IMPLEMENTS WHEN (\S+) makes request DELETE (\S+) user = get_next_match() path = get_next_match() token = get_token(user) url = vars['url'] - status, content_type, headers, body = delete(url + path, token) - vars['status_code'] = status - vars['content_type'] = content_type - vars['headers'] = headers - vars['body'] = body + http(vars, delete, url + path, token=token) ## HTTP response inspection @@ -162,7 +129,7 @@ along with this program. If not, see . IMPLEMENTS THEN body is the same as the blob (\S+) filename = get_next_match() blob = cat(filename) - body = vars['body'].decode('hex') + body = vars['body'] assertEqual(body, blob) IMPLEMENTS THEN version in body matches version from setup.py -- cgit v1.2.1