From a0d43960221075a540276fafab7d17feb968a783 Mon Sep 17 00:00:00 2001 From: Alexey Nikitenko Date: Tue, 9 Mar 2021 20:51:06 +0300 Subject: [PATCH] Black style, fix tests --- README.md | 10 ++++++-- tests/test_validators.py | 50 ++++++++++++++++++---------------------- tox.ini | 2 +- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 9353315..944eef0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ -# django-json-schema-validator -[![Build Status](https://travis-ci.org/wblxyxolbkhv/django-json-schema-validator.svg?branch=main)](https://travis-ci.org/wblxyxolbkhv/django-json-schema-validator) +# django-json-field-schema-validator +[![Build Status](https://travis-ci.com/wblxyxolbkhv/django-json-schema-validator.svg?branch=main)](https://travis-ci.com/wblxyxolbkhv/django-json-schema-validator) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) Tiny tool for Django JSONField validation through [JSON Schema](https://python-jsonschema.readthedocs.io/en/latest/validate/) +## Installation + +```shell script +pip install django-json-field-schema-validator +``` ## Example diff --git a/tests/test_validators.py b/tests/test_validators.py index f389eb7..ea63ea4 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -1,53 +1,49 @@ import pytest from django.core.exceptions import ValidationError -from django_json_field_schema_validator.validators import JSONFieldSchemaValidator +from django_json_field_schema_validator.validators import ( + JSONFieldSchemaValidator, +) -@pytest.mark.parametrize('draft_version', (3, 4, 6, 7)) +@pytest.mark.parametrize("draft_version", (3, 4, 6, 7)) def test_validation_without_errors(draft_version): schema = { - '$schema': f'http://json-schema.org/draft-{draft_version:02d}/schema#', - 'type': 'object', - 'properties': { - 'id': {'type': 'number'}, - 'name': {'type': 'string'} - }, - 'required': ['id', 'name'] + "$schema": f"http://json-schema.org/draft-{draft_version:02d}/schema#", + "type": "object", + "properties": {"id": {"type": "number"}, "name": {"type": "string"}}, + "required": ["id", "name"], } validator = JSONFieldSchemaValidator(schema, draft_version) - validator({'id': 1, 'name': 'Foo'}) + validator({"id": 1, "name": "Foo"}) def test_validation_with_errors(): schema = { - '$schema': 'http://json-schema.org/draft-07/schema#', - 'type': 'object', - 'properties': { - 'id': {'type': 'number'}, - 'name': {'type': 'string'} - }, - 'required': ['id', 'name'] + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": {"id": {"type": "number"}, "name": {"type": "string"}}, + "required": ["id", "name"], } validator = JSONFieldSchemaValidator(schema) with pytest.raises(ValidationError): - validator({'id': 1}) + validator({"id": 1}) def test_validation_with_context(): schema = { - '$schema': 'http://json-schema.org/draft-07/schema#', - 'type': 'object', - 'properties': { - 'items': { - 'anyOf': [ - {'type': 'string', 'maxLength': 2}, - {'type': 'integer', 'minimum': 5} + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "items": { + "anyOf": [ + {"type": "string", "maxLength": 2}, + {"type": "integer", "minimum": 5}, ] } }, - 'required': ['items'] + "required": ["items"], } validator = JSONFieldSchemaValidator(schema) with pytest.raises(ValidationError): - validator({'items': [{}, 3, 'foo']}) + validator({"items": [{}, 3, "foo"]}) diff --git a/tox.ini b/tox.ini index c557be0..62da917 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ deps = pytest-cov==2.11.1 coveralls==3.0.1 [testenv:pytest-unit] -commands = coverage run -m pytest py.test --cov=django_json_field_schema_validator +commands = py.test --cov=django_json_field_schema_validator [testenv:flake8]