summaryrefslogtreecommitdiff
path: root/yarns/900-implements.yarn
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-12-15 16:45:33 +0200
committerLars Wirzenius <liw@liw.fi>2017-12-15 16:45:33 +0200
commitd8f880bec11ee7d81a3715a1677b4b29ebbef201 (patch)
treeaa3bb8c8e5de96953d2025d3316c2ee04087082c /yarns/900-implements.yarn
parentb5b953029a26e1e8701d75149581497bdcf26a96 (diff)
downloadick2-d8f880bec11ee7d81a3715a1677b4b29ebbef201.tar.gz
Refactor: add function http, for easier requests
Diffstat (limited to 'yarns/900-implements.yarn')
-rw-r--r--yarns/900-implements.yarn53
1 files changed, 10 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