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())
|
||||
|
|
18
initdb.py
18
initdb.py
|
@ -275,6 +275,12 @@ def populate_database():
|
|||
'Empty repository which is building.',
|
||||
False, [], (0, [], None))
|
||||
|
||||
token = model.create_access_token(building, 'write')
|
||||
tag = 'ci.devtable.com:5000/%s/%s' % (building.namespace, building.name)
|
||||
build = model.create_repository_build(building, token, '123-45-6789', tag)
|
||||
build.uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
||||
build.save()
|
||||
|
||||
org = model.create_organization('buynlarge', 'quay@devtable.com',
|
||||
new_user_1)
|
||||
org.stripe_id = TEST_STRIPE_ID
|
||||
|
@ -298,19 +304,11 @@ def populate_database():
|
|||
model.add_user_to_team(new_user_2, reader_team)
|
||||
model.add_user_to_team(reader, reader_team)
|
||||
|
||||
token = model.create_access_token(building, 'write')
|
||||
tag = 'ci.devtable.com:5000/%s/%s' % (building.namespace, building.name)
|
||||
build = model.create_repository_build(building, token, '123-45-6789', tag)
|
||||
|
||||
build.build_node_id = 1
|
||||
build.phase = 'building'
|
||||
build.status_url = 'http://localhost:5000/test/build/status'
|
||||
build.save()
|
||||
|
||||
__generate_repository(new_user_1, 'superwide', None, False, [],
|
||||
[(10, [], 'latest2'),
|
||||
(2, [], 'latest3'),
|
||||
(2, [(1, [], 'latest11'), (2, [], 'latest12')], 'latest4'),
|
||||
(2, [(1, [], 'latest11'), (2, [], 'latest12')],
|
||||
'latest4'),
|
||||
(2, [], 'latest5'),
|
||||
(2, [], 'latest6'),
|
||||
(2, [], 'latest7'),
|
||||
|
|
|
@ -22,3 +22,4 @@ logstash_formatter
|
|||
redis
|
||||
hiredis
|
||||
git+https://github.com/dotcloud/docker-py.git
|
||||
loremipsum
|
|
@ -23,6 +23,7 @@ html5lib==1.0b3
|
|||
itsdangerous==0.23
|
||||
lockfile==0.9.1
|
||||
logstash-formatter==0.5.8
|
||||
loremipsum==1.0.2
|
||||
marisa-trie==0.5.1
|
||||
mixpanel-py==3.1.1
|
||||
mock==1.0.1
|
||||
|
|
Binary file not shown.
Reference in a new issue