mock_mcomm.py 1.46 KB
Newer Older
Rob Carleski's avatar
Rob Carleski committed
1
2
#!/usr/bin/env python
import json
3
import os
Rob Carleski's avatar
Rob Carleski committed
4
5
6
7
8

from flask import Flask

app = Flask(__name__)

9
10
11
12
13
14
15
16
17
18

def get_testdata(base, name):
    fname = os.path.join(os.path.dirname(__file__), 'data/{}_{}.json'.format(base, name))
    if os.path.exists(fname):
        with open(fname, 'r') as f:
            return f.read()
    else:
        return '{}'


Rob Carleski's avatar
Rob Carleski committed
19
20
21
22
23
24
25
26
@app.route("/iamGroups/create", methods=['POST'])
@app.route("/iamGroups/delete/<dn>", methods=['GET'])
@app.route("/iamGroups/renew/<dn>", methods=['GET'])
@app.route("/iamGroups/reserve", methods=['POST'])
@app.route("/iamGroups/update/<attrib>", methods=['POST'])
def return_success(attrib=False, dn=False):
    return '{"status": "success"}'

27

Rob Carleski's avatar
Rob Carleski committed
28
29
@app.route("/iamGroups/profile/dn/<dn>", methods=['GET'])
def get_group(dn):
30
31
32
    cn = dn.split(',')[0].split('=')[1]
    return get_testdata('profile', cn)

Rob Carleski's avatar
Rob Carleski committed
33
34
35

@app.route("/iamGroups/find/both/<name>", methods=['GET'])
def get_both(name):
36
37
    return get_testdata('find_both', name)

Rob Carleski's avatar
Rob Carleski committed
38
39
40

@app.route("/iamGroups/find/person/<uid>", methods=['GET'])
def get_user(uid):
41
42
    return get_testdata('find_person', uid)

Rob Carleski's avatar
Rob Carleski committed
43
44
45
46
47
48
49
50

@app.route("/iamGroups/isValidName/<name>", methods=['GET'])
def is_valid_name(name):
    if name != 'badname':
        return '{"valid": "true"}'
    else:
        return '{"valid": "false"}'

51

Rob Carleski's avatar
Rob Carleski committed
52
53
54
@app.route("/inst/oauth2/token", methods=['POST'])
def return_token():
    return '{"access_token": "a1b2c3d4c5d6e7f8g9h10i11j12k13l14"}'
Paul Arthur's avatar
Paul Arthur committed
55
56
57
58
59
60
61


def main():
    app.run()

if __name__ == '__main__':
    main()