Permalink
Browse files

Add a quick test that JSONSchema extension works correctly

  • Loading branch information...
1 parent fb04fef commit be11cfef3d62483c7ffdc4058d8ba2b72d032509 @svanoort committed Mar 15, 2016
View
@@ -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
@@ -6,7 +6,7 @@ RUN rpm -ivh http://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
@@ -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
@@ -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
@@ -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')
}
@@ -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('http://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:
@@ -0,0 +1,21 @@
+{
+ "$schema": "http://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"
+ }
+ }
+}
@@ -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.