# Scenario step implementations (local and remote instances) ## HTTP requests of various kinds IMPLEMENTS WHEN (\S+) makes request GET (\S+) user = get_next_match() 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 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 IMPLEMENTS WHEN (\S+) makes request POST (\S+) with a valid token and body (.+) user = get_next_match() path = get_next_match() body_text = get_next_match() print('path', path) 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 IMPLEMENTS WHEN (\S+) makes request POST (\S+) with an invalid token and body (.+) user = get_next_match() path = get_next_match() body_text = get_next_match() print('path', path) 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 IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with a valid token and body (.+) user = get_next_match() path = get_next_match() body_text = get_next_match() print('user', user) print('path', path) 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 IMPLEMENTS WHEN (\S+) makes request PUT (\S+) with an invalid token user = get_next_match() path = get_next_match() body_text = '{}' print('user', user) print('path', path) 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 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 response inspection IMPLEMENTS THEN result has status code (\d+) expected = int(get_next_match()) assertEqual(expected, vars['status_code']) IMPLEMENTS THEN body matches (.+) expected_text = get_next_match() expected = json.loads(expected_text) print('actual body', repr(vars['body'])) actual = json.loads(vars['body']) assertEqual(expected, actual) IMPLEMENTS THEN body text is "(.*)" expected = unescape(get_next_match()) actual = vars['body'] assertEqual(expected, actual) IMPLEMENTS THEN version in body matches version from setup.py body = vars['body'] obj = json.loads(body) actual = obj['version'] setup_py = os.path.join(srcdir, 'setup.py') wanted = cliapp.runcmd(['python3', setup_py, '--version']).strip() assertTrue(wanted.startswith(actual)) IMPLEMENTS THEN result has header (\S+): (\S+) name = get_next_match() value = get_next_match() headers = vars['headers'] assertEqual(headers[name].lower(), value.lower())