mirror of
https://github.com/ansible/awx.git
synced 2026-01-20 14:11:24 -03:30
Merge pull request #2702 from kdelee/schema_validation
Pre-Merge Schema validation
Reviewed-by: Matthew Jones <mat@matburt.net>
https://github.com/matburt
This commit is contained in:
commit
39369c7721
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
# Ignore generated schema
|
||||
swagger.json
|
||||
schema.json
|
||||
reference-schema.json
|
||||
|
||||
# Tags
|
||||
.tags
|
||||
|
||||
21
Makefile
21
Makefile
@ -11,7 +11,6 @@ GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
||||
MANAGEMENT_COMMAND ?= awx-manage
|
||||
IMAGE_REPOSITORY_AUTH ?=
|
||||
IMAGE_REPOSITORY_BASE ?= https://gcr.io
|
||||
|
||||
VERSION := $(shell cat VERSION)
|
||||
|
||||
# NOTE: This defaults the container image version to the branch that's active
|
||||
@ -85,6 +84,11 @@ clean-venv:
|
||||
clean-dist:
|
||||
rm -rf dist
|
||||
|
||||
clean-schema:
|
||||
rm -rf swagger.json
|
||||
rm -rf schema.json
|
||||
rm -rf reference-schema.json
|
||||
|
||||
# Remove temporary build files, compiled Python files.
|
||||
clean: clean-ui clean-dist
|
||||
rm -rf awx/public
|
||||
@ -338,11 +342,14 @@ pyflakes: reports
|
||||
pylint: reports
|
||||
@(set -o pipefail && $@ | reports/$@.report)
|
||||
|
||||
genschema: reports
|
||||
$(MAKE) swagger PYTEST_ARGS="--genschema"
|
||||
|
||||
swagger: reports
|
||||
@if [ "$(VENV_BASE)" ]; then \
|
||||
. $(VENV_BASE)/awx/bin/activate; \
|
||||
fi; \
|
||||
(set -o pipefail && py.test awx/conf/tests/functional awx/main/tests/functional/api awx/main/tests/docs --release=$(VERSION_TARGET) | tee reports/$@.report)
|
||||
(set -o pipefail && py.test $(PYTEST_ARGS) awx/conf/tests/functional awx/main/tests/functional/api awx/main/tests/docs --release=$(VERSION_TARGET) | tee reports/$@.report)
|
||||
|
||||
check: flake8 pep8 # pyflakes pylint
|
||||
|
||||
@ -564,6 +571,16 @@ docker-compose-runtest:
|
||||
docker-compose-build-swagger:
|
||||
cd tools && CURRENT_UID=$(shell id -u) TAG=$(COMPOSE_TAG) DEV_DOCKER_TAG_BASE=$(DEV_DOCKER_TAG_BASE) docker-compose run --rm --service-ports awx /start_tests.sh swagger
|
||||
|
||||
docker-compose-genschema:
|
||||
cd tools && CURRENT_UID=$(shell id -u) TAG=$(COMPOSE_TAG) DEV_DOCKER_TAG_BASE=$(DEV_DOCKER_TAG_BASE) docker-compose run --rm --service-ports awx /start_tests.sh genschema
|
||||
mv swagger.json schema.json
|
||||
|
||||
docker-compose-validate-schema:
|
||||
$(MAKE) docker-compose-genschema
|
||||
curl https://s3.amazonaws.com/awx-public-ci-files/schema.json -o reference-schema.json
|
||||
# Ignore differences in whitespace with -b
|
||||
diff -u -b schema.json reference-schema.json
|
||||
|
||||
docker-compose-clean:
|
||||
cd tools && CURRENT_UID=$(shell id -u) TAG=$(COMPOSE_TAG) DEV_DOCKER_TAG_BASE=$(DEV_DOCKER_TAG_BASE) docker-compose run --rm -w /awx_devel --service-ports awx make clean
|
||||
cd tools && TAG=$(COMPOSE_TAG) DEV_DOCKER_TAG_BASE=$(DEV_DOCKER_TAG_BASE) docker-compose rm -sf
|
||||
|
||||
@ -15,6 +15,12 @@ from awx.main.tests.factories import (
|
||||
)
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--genschema", action="store_true", default=False, help="execute schema validator"
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
import sys
|
||||
sys._called_from_test = True
|
||||
|
||||
@ -49,7 +49,8 @@ class TestSwaggerGeneration():
|
||||
data.update(response.accepted_renderer.get_customizations() or {})
|
||||
|
||||
data['host'] = None
|
||||
data['modified'] = datetime.datetime.utcnow().isoformat()
|
||||
if not pytest.config.getoption("--genschema"):
|
||||
data['modified'] = datetime.datetime.utcnow().isoformat()
|
||||
data['schemes'] = ['https']
|
||||
data['consumes'] = ['application/json']
|
||||
|
||||
@ -121,7 +122,7 @@ class TestSwaggerGeneration():
|
||||
pattern = pattern.replace('{id}', '[0-9]+')
|
||||
pattern = pattern.replace(r'{category_slug}', r'[a-zA-Z0-9\-]+')
|
||||
for path, result in swagger_autogen.items():
|
||||
if re.match('^{}$'.format(pattern), path):
|
||||
if re.match(r'^{}$'.format(pattern), path):
|
||||
for key, value in result.items():
|
||||
method, status_code = key
|
||||
content_type, resp, request_data = value
|
||||
@ -139,11 +140,14 @@ class TestSwaggerGeneration():
|
||||
for param in node[method].get('parameters'):
|
||||
if param['in'] == 'body':
|
||||
node[method]['parameters'].remove(param)
|
||||
node[method].setdefault('parameters', []).append({
|
||||
'name': 'data',
|
||||
'in': 'body',
|
||||
'schema': {'example': request_data},
|
||||
})
|
||||
if pytest.config.getoption("--genschema"):
|
||||
pytest.skip("In schema generator skipping swagger generator", allow_module_level=True)
|
||||
else:
|
||||
node[method].setdefault('parameters', []).append({
|
||||
'name': 'data',
|
||||
'in': 'body',
|
||||
'schema': {'example': request_data},
|
||||
})
|
||||
|
||||
# Build response examples
|
||||
if resp:
|
||||
@ -164,8 +168,13 @@ class TestSwaggerGeneration():
|
||||
# replace ISO dates w/ the same value so we don't generate
|
||||
# needless diffs
|
||||
data = re.sub(
|
||||
'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+Z',
|
||||
'2018-02-01T08:00:00.000000Z',
|
||||
r'[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+Z',
|
||||
r'2018-02-01T08:00:00.000000Z',
|
||||
data
|
||||
)
|
||||
data = re.sub(
|
||||
r'''(\s+"client_id": ")([a-zA-Z0-9]{40})("\,\s*)''',
|
||||
r'\1xxxx\3',
|
||||
data
|
||||
)
|
||||
f.write(data)
|
||||
|
||||
8
tox.ini
8
tox.ini
@ -6,6 +6,7 @@ envlist =
|
||||
api,
|
||||
ui,
|
||||
swagger,
|
||||
validate-schema,
|
||||
|
||||
[testenv]
|
||||
;basepython = python2.7
|
||||
@ -71,3 +72,10 @@ deps =
|
||||
commands =
|
||||
make docker-compose-build
|
||||
make docker-compose-build-swagger
|
||||
|
||||
[testenv:validate-schema]
|
||||
deps =
|
||||
nodeenv
|
||||
commands =
|
||||
make docker-compose-build
|
||||
make docker-compose-validate-schema
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user