Fix up the test endpoints with better fake data. Install them at a known location. Update the building test repository to point to the new fakes.
This commit is contained in:
parent
44fe17754a
commit
df389e81c7
5 changed files with 77 additions and 27 deletions
|
@ -1,9 +1,10 @@
|
|||
import math
|
||||
|
||||
from random import SystemRandom
|
||||
from flask import jsonify
|
||||
from app import app
|
||||
from flask import jsonify, request
|
||||
from loremipsum import get_sentences
|
||||
|
||||
from endpoints.api import api
|
||||
|
||||
def generate_image_completion(rand_func):
|
||||
images = {}
|
||||
|
@ -18,16 +19,10 @@ def generate_image_completion(rand_func):
|
|||
return images
|
||||
|
||||
|
||||
@app.route('/test/build/status', methods=['GET'])
|
||||
def generate_random_build_status():
|
||||
def generate_fake_status():
|
||||
response = {
|
||||
'id': 1,
|
||||
'total_commands': None,
|
||||
'current_command': None,
|
||||
'push_completion': 0.0,
|
||||
'id': 'deadbeef-dead-beef-dead-beefdeadbeef',
|
||||
'status': None,
|
||||
'message': None,
|
||||
'image_completion': {},
|
||||
}
|
||||
|
||||
random = SystemRandom()
|
||||
|
@ -38,9 +33,7 @@ def generate_random_build_status():
|
|||
'current_command': 0,
|
||||
},
|
||||
'initializing': {},
|
||||
'error': {
|
||||
'message': 'Oops!'
|
||||
},
|
||||
'error': {},
|
||||
'complete': {},
|
||||
'building': {
|
||||
'total_commands': 7,
|
||||
|
@ -55,7 +48,64 @@ def generate_random_build_status():
|
|||
}
|
||||
|
||||
phase = random.choice(phases.keys())
|
||||
response['status'] = phase
|
||||
response.update(phases[phase])
|
||||
response['phase'] = phase
|
||||
response['status'] = (phases[phase])
|
||||
|
||||
return jsonify(response)
|
||||
return response
|
||||
|
||||
|
||||
BASE_BUILDING_URL = '/repository/devtable/building/build/'
|
||||
|
||||
|
||||
@api.route(BASE_BUILDING_URL, methods=['GET'])
|
||||
def get_fake_repo_build_status_list():
|
||||
return jsonify({'builds': [generate_fake_status()]})
|
||||
|
||||
|
||||
@api.route(BASE_BUILDING_URL + 'deadbeef-dead-beef-dead-beefdeadbeef/logs',
|
||||
methods=['GET'])
|
||||
def get_fake_repo_build_logs():
|
||||
start = int(request.args.get('start', 0))
|
||||
end = int(request.args.get('end', 0))
|
||||
had_start = 'start' in request.args
|
||||
had_end = 'end' in request.args
|
||||
|
||||
adv_start = 0
|
||||
adv_end = 0
|
||||
adv_total = 0
|
||||
lorem_logs = []
|
||||
|
||||
if had_start and had_end:
|
||||
numlogs = end - start + 1
|
||||
adv_start = start
|
||||
adv_end = end
|
||||
adv_total = end + 1
|
||||
lorem_logs = get_sentences(numlogs)
|
||||
elif had_start:
|
||||
adv_start = start
|
||||
adv_end = start + 9
|
||||
lorem_logs = get_sentences(10)
|
||||
adv_total = adv_end + 1
|
||||
elif had_end:
|
||||
adv_start = max(0, (end - 9))
|
||||
adv_end = end
|
||||
adv_total = end + 1
|
||||
lorem_logs = get_sentences(adv_end - adv_start + 1)
|
||||
else:
|
||||
adv_start = 100
|
||||
adv_end = 109
|
||||
adv_total = 110
|
||||
lorem_logs = get_sentences(10)
|
||||
|
||||
return jsonify({
|
||||
'start': adv_start,
|
||||
'end': adv_end,
|
||||
'total': adv_total,
|
||||
'logs': [{'message': sentence} for sentence in lorem_logs]
|
||||
})
|
||||
|
||||
|
||||
@api.route(BASE_BUILDING_URL + '/deadbeef-dead-beef-dead-beefdeadbeef/status',
|
||||
methods=['GET'])
|
||||
def get_fake_repo_build_status():
|
||||
return jsonify(generate_fake_status())
|
||||
|
|
Reference in a new issue