-
Notifications
You must be signed in to change notification settings - Fork 135
/
app.py
54 lines (41 loc) · 1.59 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
from flask import Flask, Response, request
from werkzeug.datastructures import Headers
HTTP_METHODS = ['DELETE', 'GET', 'OPTIONS', 'POST', 'PUT']
app = Flask(__name__)
current_state = ''
provider_states = {
'consumer': {
'a simple json blob exists': Response(
status=200,
response=json.dumps({'name': 'Jonas'}),
headers=Headers([('Content-Type', 'application/json')])),
'the user `bob` exists': Response(
status=200,
headers={'Content-Type': 'application/json'},
response=json.dumps(
{'username': 'bob',
'id': '100',
'groups': ['users', 'admins']})),
'a list of users exists': Response(
status=200,
headers={'Content-Type': 'application/json'},
response=json.dumps({'results': [
{'username': 'bob', 'id': 101, 'groups': [234, 123]},
{'username': 'sue', 'id': 102, 'groups': [345, 123]}]}))
}}
@app.route('/_pact/provider-states', methods=['GET'])
def states():
return json.dumps({k: v.keys() for k, v in provider_states.items()})
@app.route('/_pact/provider-states/active', methods=['POST'])
def set_active():
body = request.get_json()
global current_state
current_state = provider_states[body['consumer']][body['state']]
return Response(status=200)
@app.route('/', defaults={'path': ''}, methods=HTTP_METHODS)
@app.route('/<path:path>', methods=HTTP_METHODS)
def catch_all(path):
return current_state
if __name__ == '__main__':
app.run(port='5000')