Created
September 24, 2018 22:58
-
-
Save eht16/297ca039aa69cfc7bcb4ddb8732b3f4f to your computer and use it in GitHub Desktop.
Tavern !anything with include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
test_name: test case 1 | |
includes: | |
- !include auth.yaml | |
stages: | |
- type: ref | |
id: api-login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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