from random import SystemRandom from flask import jsonify, send_file from app import app @app.route('/test/build/status', methods=['GET']) def generate_random_build_status(): response = { 'id': 1, 'total_commands': None, 'total_images': None, 'current_command': None, 'current_image': None, 'image_completion_percent': None, 'status': None, 'message': None, } random = SystemRandom() phases = { 'waiting': {}, 'starting': { 'total_commands': 7, 'current_command': 0, }, 'initializing': {}, 'error': { 'message': 'Oops!' }, 'complete': {}, 'building': { 'total_commands': 7, 'current_command': random.randint(1, 7), }, 'pushing': { 'total_commands': 7, 'current_command': 7, 'total_images': 11, 'current_image': random.randint(1, 11), 'image_completion_percent': random.randint(0, 100), }, } phase = random.choice(phases.keys()) response['status'] = phase response.update(phases[phase]) return jsonify(response)