Skip to content

Commit

Permalink
Add a quick test that JSONSchema extension works correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
svanoort committed Mar 15, 2016
1 parent fb04fef commit be11cfe
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -x
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR

UBUNTU_14_VERSION=0.5
CENTOS6_VERSION=0.5
PYTHON3_VERSION=0.6
UBUNTU_14_VERSION=0.6
CENTOS6_VERSION=0.6
PYTHON3_VERSION=0.7

docker build -t pyresttest-build-ubuntu-14:$UBUNTU_14_VERSION-SNAPSHOT ./ubuntu14-py27
docker build -t pyresttest-build-centos6:$CENTOS6_VERSION-SNAPSHOT ./centos6-py26
Expand Down
2 changes: 1 addition & 1 deletion docker/centos6-py26/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noar

# pycurl is part of yum, and so is python, so we don't install
RUN yum install -y python-pip git-core python-mock rpm-build tar && yum clean all \
&& pip install discover jmespath pyyaml django==1.6.5 django-tastypie==0.12.1
&& pip install discover jmespath jsonpath pyyaml django==1.6.5 django-tastypie==0.12.1

COPY verify_image.py /tmp/verify_image.py
RUN chmod a+rwx /tmp/verify_image.py
2 changes: 1 addition & 1 deletion docker/python3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y git-core tar \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Python 2 and 3 dependencies, future is just for python 3 compat, sigh
RUN pip3 install pycurl jmespath pyyaml django==1.6.5 django-tastypie==0.12.1 future
RUN pip3 install pycurl jmespath jsonpath pyyaml django==1.6.5 django-tastypie==0.12.1 future

COPY verify_image.py /tmp/verify_image.py
RUN chmod a+rwx /tmp/verify_image.py
2 changes: 1 addition & 1 deletion docker/ubuntu14-py27/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y python python-p
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Python 2 and 3 dependencies
RUN pip install mock jmespath pyyaml django==1.6.5 django-tastypie==0.12.1
RUN pip install mock jmespath jsonpath pyyaml django==1.6.5 django-tastypie==0.12.1

COPY verify_image.py /tmp/verify_image.py
RUN chmod a+rwx /tmp/verify_image.py
6 changes: 3 additions & 3 deletions jenkins/jenkins-build-images.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ node {
def python3 = docker.build("pyresttest-build-python3:test", 'docker/python3')

stage name:'test/tag', concurrency: 1
run_test(ubuntu14_py27, 'python', '0.5')
run_test(centos6_py26, 'python', '0.5')
run_test(ubuntu14_py27, 'python', '0.6')
run_test(centos6_py26, 'python', '0.6')

// For some inexplicable reasons, the test script here is more brittle than the others
// Direct docker run works, it hit issues with docker.build, so... okay?
run_test(python3, 'python3', '0.6')
run_test(python3, 'python3', '0.7')
}

19 changes: 18 additions & 1 deletion pyresttest/functionaltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,24 @@ def test_benchmark_get(self):
self.assertTrue(benchmark_config.benchmark_runs, len(
benchmark_result.results['total_time']))

def test_get_validators_jmespath_fail(self):
def test_use_validator_ext_jsonschema(self):
try:
import jsonschema
except ImportError:
print("Skipping jsonschema import test because library absent")
raise unittest.SkipTest("JSONSchema module absent")
# Serious hack dumping the schema in local directory to allow executing it this way
# But otherwise kind of painful
path = os.path.join(os.path.dirname(
os.path.realpath(__file__)), 'testapp/schema_test.yaml')
print(path)
tests = resttest.parse_testsets('https://localhost:8000', resttest.read_test_file(
path), working_directory=os.path.dirname(os.path.realpath(__file__)))
failures = resttest.run_testsets(tests)
self.assertTrue(
failures == 0, 'Simple tests failed where success expected')

def test_use_validators_jmespath_fail(self):
try:
import jmespath
except ImportError:
Expand Down
21 changes: 21 additions & 0 deletions pyresttest/miniapp-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://json-schema.org/draft-04/schema#",
"title": "Person",
"description": "A person from the miniapp",
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Unique person ID"
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"login": {
"type": "string"
}
}
}
5 changes: 5 additions & 0 deletions pyresttest/testapp/schema_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- test:
- url: /api/person/1/
- validators:
- json_schema: {schema: {file: 'miniapp-schema.json'}}

0 comments on commit be11cfe

Please sign in to comment.