diff options
-rw-r--r-- | yarns/900-implements.yarn | 53 | ||||
-rw-r--r-- | yarns/lib.py | 8 |
2 files changed, 18 insertions, 43 deletions
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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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 diff --git a/yarns/lib.py b/yarns/lib.py index 6575e6d..8f885c0 100644 --- a/yarns/lib.py +++ b/yarns/lib.py @@ -96,6 +96,14 @@ def get_token(user): return cat(filename) +def http(vars, func, url, **kwargs): + status, content_type, headers, body = func(url, **kwargs) + vars['status_code'] = status + vars['content_type'] = content_type + vars['headers'] = headers + vars['body'] = body + + def get(url, token): headers = { 'Authorization': 'Bearer {}'.format(token), |