Skip to content

Instantly share code, notes, and snippets.

@eht16
Created September 24, 2018 22:58
Show Gist options
  • Save eht16/297ca039aa69cfc7bcb4ddb8732b3f4f to your computer and use it in GitHub Desktop.
Save eht16/297ca039aa69cfc7bcb4ddb8732b3f4f to your computer and use it in GitHub Desktop.
Tavern !anything with include
---
name: Authentication stage
description: Reusable test stage for authentication
stages:
- id: api-login
name: successful login
request:
url: "http://127.0.0.1:5000/login"
json:
username: "foobar"
password: "barfoo"
method: POST
headers:
content-type: application/json
response:
status_code: 200
body:
id: !anystr
roles: !anything
username: "{tavern.request_vars.json.username}"
headers:
content-type: application/json
# -*- coding: utf-8 -*-
from flask import Flask, jsonify, request
app = Flask(__name__)
app.secret_key = "t1uNraxw+dsakj93mfdoi,o3er4="
SERVERNAME = "testserver"
@app.route("/login", methods=["POST"])
def login():
r = request.get_json()
if r["username"] != "foobar" or r["password"] != "barfoo":
return jsonify({"error": "Incorrect username/password"}), 401
return jsonify({"id": "42", "username": r["username"], "roles": ["role-foo-bar"]}), 200
---
test_name: test case 1
includes:
- !include auth.yaml
stages:
- type: ref
id: api-login
---
test_name: test case 1
stages:
- id: api-login-direct
name: successful login
request:
url: "http://127.0.0.1:5000/login"
json:
username: "foobar"
password: "barfoo"
method: POST
headers:
content-type: application/json
response:
status_code: 200
body:
id: !anystr
roles: !anything
username: "{tavern.request_vars.json.username}"
headers:
content-type: application/json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment