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 26, 2016
1 parent b8b471c commit 9b2616a
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 63 deletions.
48 changes: 34 additions & 14 deletions ceagle/api_fake_data/fake_runbooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,58 @@
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),
"region_id": 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,
"region_id": random.choice(region_choices),
}
if with_parent:
run["parent"] = get_single_runbook(False)
return run


@base.api_handler
Expand All @@ -64,7 +84,7 @@ def handle_runbooks(region):
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 Down
10 changes: 10 additions & 0 deletions raml/abao_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 @@ -145,6 +150,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 @@ -277,3 +277,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
8 changes: 8 additions & 0 deletions raml/forms/runbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ type:
description: Type (i.e. bash, python, etc) of the runbook
required: true
type: string
tags:
description: List of tags
required: false
type: array
parameters:
description: List of runbook parameters
required: false
type: array
160 changes: 130 additions & 30 deletions raml/response_examples/200/runbook_runs.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,183 @@
{
"runs": [
{
"_id": "434",
"finished_at": "2016-12-20T16:27:42.150227",
"id": "434",
"updated_at": "2016-12-20T16:27:42.150227",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150142",
"created_at": "2016-12-20T16:18:42.150142",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "251",
"finished_at": "2016-12-20T16:33:42.150344",
"id": "251",
"updated_at": "2016-12-20T16:33:42.150344",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150312",
"created_at": "2016-12-20T16:18:42.150312",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "268",
"finished_at": "2016-12-20T16:30:42.150412",
"id": "268",
"updated_at": "2016-12-20T16:30:42.150412",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150385",
"created_at": "2016-12-20T16:18:42.150385",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "128",
"finished_at": "2016-12-20T16:25:42.150472",
"id": "128",
"updated_at": "2016-12-20T16:25:42.150472",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150445",
"created_at": "2016-12-20T16:18:42.150445",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "50",
"finished_at": "2016-12-20T16:21:42.150534",
"id": "50",
"updated_at": "2016-12-20T16:21:42.150534",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150505",
"created_at": "2016-12-20T16:18:42.150505",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "241",
"finished_at": "2016-12-20T16:24:42.150599",
"id": "241",
"updated_at": "2016-12-20T16:24:42.150599",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150575",
"created_at": "2016-12-20T16:18:42.150575",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "878",
"finished_at": "2016-12-20T16:32:42.150652",
"id": "878",
"updated_at": "2016-12-20T16:32:42.150652",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150628",
"created_at": "2016-12-20T16:18:42.150628",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "924",
"finished_at": "2016-12-20T16:29:42.150704",
"id": "924",
"updated_at": "2016-12-20T16:29:42.150704",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150680",
"created_at": "2016-12-20T16:18:42.150680",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "868",
"finished_at": "2016-12-20T16:33:42.150761",
"id": "868",
"updated_at": "2016-12-20T16:33:42.150761",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150736",
"created_at": "2016-12-20T16:18:42.150736",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
},
{
"_id": "263",
"finished_at": "2016-12-20T16:22:42.150815",
"id": "263",
"updated_at": "2016-12-20T16:22:42.150815",
"output": "SGVsbG8gV29ybGQhCg==",
"return_code": 0,
"started_at": "2016-12-20T16:18:42.150791",
"created_at": "2016-12-20T16:18:42.150791",
"status": "scheduled",
"runbook": {
"id": "602",
"description": "Demo runbook description",
"name": "Demo runbook",
"runbook": "IyEvYmluL2Jhc2gKCmVjaG8gIkhlbGxvIFdvcmxkISIK",
"tags": ["Monitoring"],
"latest_run": null
"type": "bash"
},
"user": "cloud_user"
}
]
Expand Down

0 comments on commit 9b2616a

Please sign in to comment.