Skip to content

Commit

Permalink
Update fake API responses in accordance with API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
teferi committed Dec 30, 2016
1 parent 57e6e7a commit ba75167
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 73 deletions.
18 changes: 10 additions & 8 deletions ceagle/api/v1/runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,42 @@
bp = flask.Blueprint("runbooks", __name__)


@bp.route("/<region>/runbooks",
@bp.route("/runbooks", methods=["GET"])
@bp.route("/region/<region>/runbooks",
methods=["GET", "POST"])
@fake_runbooks.handle_runbooks
def handle_runbooks(region):
def handle_runbooks(region=None):
return flask.jsonify("fixme!")


@bp.route("/<region>/runbooks/<book_id>",
@bp.route("/region/<region>/runbooks/<book_id>",
methods=["GET", "PUT", "DELETE"])
@fake_runbooks.handle_single_runbook
def handle_single_runbook(region, book_id):
return flask.jsonify("fixme!")


@bp.route("/<region>/runbooks/<book_id>/run",
@bp.route("/region/<region>/runbooks/<book_id>/run",
methods=["POST"])
@fake_runbooks.run_runbook
def run_runbook(region, book_id):
return flask.jsonify("fixme!")


@bp.route("/<region>/runbook_runs")
@bp.route("/runbook_runs")
@bp.route("/region/<region>/runbook_runs")
@fake_runbooks.runbook_runs
def runbook_runs(region):
def runbook_runs(region=None):
return flask.jsonify("fixme!")


@bp.route("/<region>/runbook_runs/<run_id>")
@bp.route("/region/<region>/runbook_runs/<run_id>")
@fake_runbooks.single_runbook_run
def single_runbook_run(region, run_id):
return flask.jsonify("fixme!")


def get_blueprints():
return [
["/region", bp],
["", bp],
]
52 changes: 36 additions & 16 deletions ceagle/api_fake_data/fake_runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,70 @@
from ceagle.api_fake_data import base


def get_single_runbook():
def get_single_runbook(with_latest_run=True):
tag_choices = [
["Monitoring"],
["Databases"],
["Monitoring", "Databases"],
None
[],
]
parameter_choices = [
[{"name": "user"}, {"name": "password"}],
None,
]
region_choices = [
"region_one", "region_two"
]
tags = random.choice(tag_choices)
runbook = {
"_id": str(random.randint(1, 1000)),
"id": str(random.randint(1, 1000)),
"description": "Demo runbook description",
"name": "Demo runbook",
"type": "bash",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK"
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"latest_run": None,
"tags": random.choice(tag_choices),
"parameters": random.choice(parameter_choices),
"regionId": random.choice(region_choices),
}
if tags:
runbook["tags"] = tags

if with_latest_run:
runbook['latest_run'] = get_single_run(False)
return runbook


def get_single_run():
def get_single_run(with_parent=True):
finished_at = datetime.datetime.now().isoformat()
started_at = (datetime.datetime.now() - datetime.timedelta(
minutes=random.randint(1, 20))).isoformat()
return {
"_id": str(random.randint(1, 1000)),
"started_at": started_at,
"finished_at": finished_at,

region_choices = [
"region_one", "region_two"
]
run = {
"id": str(random.randint(1, 1000)),
"created_at": started_at,
"updated_at": finished_at,
"user": "cloud_user",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"parent": None,
"regionId": random.choice(region_choices),
}
if with_parent:
run["parent"] = get_single_runbook(False)
return run


@base.api_handler
def handle_runbooks(region):
def handle_runbooks(region=None):
if flask.request.method == "POST":
body = flask.request.get_json(silent=True) or {}
for field in ["description", "name",
"runbook", "type"]:
if field not in body:
return flask.jsonify(
{"error": "missing {}".format(field)}), 400
body["_id"] = str(random.randint(1, 1000))
body["id"] = str(random.randint(1, 1000))
return flask.jsonify(body), 201
return flask.jsonify(
{"runbooks": [get_single_runbook() for i in range(10)]}
Expand All @@ -82,7 +102,7 @@ def handle_single_runbook(region, book_id):
if field not in body:
return flask.jsonify(
{"error": "missing {}".format(field)}), 400
body["_id"] = book_id
body["id"] = book_id
return flask.jsonify(body)
elif flask.request.method == "DELETE":
return '', 204
Expand All @@ -98,7 +118,7 @@ def run_runbook(region, book_id):


@base.api_handler
def runbook_runs(region):
def runbook_runs(region=None):
return flask.jsonify(
{"runs": [get_single_run() for i in range(10)]}
)
Expand Down
10 changes: 10 additions & 0 deletions raml/abao_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ hooks.before('GET /api/{version}/region/{region}/runbooks -> 200', function (tes
done();
});

hooks.before('GET /api/{version}/runbooks -> 200', function (test, done) {
test.request.params = params;
done();
});

hooks.before('POST /api/{version}/region/{region}/runbooks -> 201', function (test, done) {
test.request.params = params;
test.request.body = correctRunbook;
Expand Down Expand Up @@ -165,6 +170,11 @@ hooks.before('POST /api/{version}/region/{region}/runbooks/{runbook_id}/run -> 2
done();
});

hooks.before('GET /api/{version}/runbook_runs -> 200', function (test, done) {
test.request.params = paramsRunBookRun;
done();
});

hooks.before('GET /api/{version}/region/{region}/runbook_runs -> 200', function (test, done) {
test.request.params = paramsRunBookRun;
done();
Expand Down
23 changes: 23 additions & 0 deletions raml/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,26 @@ mediaType: application/json
body:
schema: !include schemas/200.json
example: !include response_examples/200/status_performance.json
/runbook_runs:
get:
description: Get list of all runs of all runbooks in all regions
responses:
200:
body:
schema: !include schemas/200.json
example: !include response_examples/200/runbook_runs.json
404:
body:
schema: !include schemas/404.json

/runbooks:
get:
description: List all runbooks for all regions
responses:
200:
body:
schema: !include schemas/200.json
example: !include response_examples/200/runbooks.json
404:
body:
schema: !include schemas/404.json
9 changes: 9 additions & 0 deletions raml/forms/runbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ type:
description: Type (i.e. bash, python, etc) of the runbook
required: true
type: string
# There seems to be no way to set array parameters for forms
# tags:
# description: List of tags
# required: false
# type: array
# parameters:
# description: List of runbook parameters
# required: false
# type: array

0 comments on commit ba75167

Please sign in to comment.