Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests of improved validation error messages for oneOf #8

Merged
merged 17 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Use lib-cove version 0.5.0, which includes schema validation message changes

## [0.3.0] - 2019-03-22

### Added
Expand Down Expand Up @@ -39,4 +43,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.1.0] - 2018-11-22

First Release
First Release
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-e git+https://github.com/OpenDataServices/[email protected]#egg=flattentool
-e git+https://github.com/OpenDataServices/lib-cove.git@v0.3.1#egg=libcove
-e git+https://github.com/OpenDataServices/lib-cove.git@v0.5.0#egg=libcove
-e .
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-e git+https://github.com/OpenDataServices/flatten-tool.git@4c13ef0b32a59e810919a3de09bc8f64ce8f9392#egg=flattentool
-e git+https://github.com/OpenDataServices/lib-cove.git@7bcec77f9289e405499d871c131b78289d9316cc#egg=libcove
-e git+https://github.com/OpenDataServices/lib-cove.git@v0.5.0#egg=libcove
## The following requirements were added by pip freeze:
bleach==3.1.0
cached-property==1.5.1
Expand All @@ -19,8 +19,10 @@ lxml==4.3.2
openpyxl==2.6.1
pytz==2018.9
requests==2.21.0
rfc3987==1.3.8
schema==0.7.0
six==1.12.0
strict-rfc3339==0.7
urllib3==1.24.1
webencodings==0.5.1
xmltodict==0.12.0
4 changes: 1 addition & 3 deletions requirements_dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-e git+https://github.com/OpenDataServices/[email protected]#egg=flattentool
-e git+https://github.com/OpenDataServices/[email protected]#egg=libcove
-e .
-r requirements.in
pytest
flake8
9 changes: 5 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-e git+https://github.com/OpenDataServices/flatten-tool.git@4c13ef0b32a59e810919a3de09bc8f64ce8f9392#egg=flattentool
-e git+https://github.com/OpenDataServices/lib-cove.git@7bcec77f9289e405499d871c131b78289d9316cc#egg=libcove

-r requirements.in
pytest==4.3.1
flake8==3.7.7
## The following requirements were added by pip freeze:
Expand All @@ -15,25 +13,28 @@ contextlib2==0.5.5
Django==2.1.7
entrypoints==0.3
et-xmlfile==1.0.1
-e git+https://github.com/OpenDataServices/flatten-tool.git@4c13ef0b32a59e810919a3de09bc8f64ce8f9392#egg=flattentool
future==0.17.1
idna==2.8
jdcal==1.4
json-merge-patch==0.2
jsonref==0.2
jsonschema==2.6.0
-e git+https://github.com/OpenDataServices/[email protected]#egg=libcove
lxml==4.3.2
mccabe==0.6.1
more-itertools==6.0.0
openpyxl==2.6.1
pathlib2==2.3.3
pluggy==0.9.0
py==1.8.0
pycodestyle==2.5.0
pyflakes==2.1.1
pytz==2018.9
requests==2.21.0
rfc3987==1.3.8
schema==0.7.0
six==1.12.0
strict-rfc3339==0.7
urllib3==1.24.1
webencodings==0.5.1
xmltodict==0.12.0
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
install_requires=[
'jsonref',
'jsonschema<2.7',
# Required for jsonschema to validate URIs
'rfc3987',
# Required for jsonschema to validate date-time
'strict-rfc3339',
'CommonMark',
'Django',
'bleach',
Expand Down
73 changes: 73 additions & 0 deletions tests/fixtures/api/basic_statement_id_and_type_errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"statementType": "entityStatement",
"statementDate": "2017-11-18",
"entityType": "registeredEntity",
"name": "CHRINON LTD",
"foundingDate": "2010-11-18",
"identifiers": [
{
"scheme": "GB-COH",
"id": "07444723"
}
]
},
{
"statementID": "shortID",
"statementType": "personStatement",
"statementDate": "2017-11-18",
"personType": "knownPerson",
"nationalities": [
{
"code": "GB"
}
],
"names": [
{
"type": "individual",
"fullName": "Christopher Taggart",
"givenName": "Christopher",
"familyName": "Taggart"
},
{
"type": "aka",
"fullName": "Chris Taggart"
}
],
"birthDate": "1964-04",
"addresses": [
{
"type": "service",
"address": "Aston House, Cornwall Avenue, London",
"country": "GB",
"postCode": "N3 1LF"
}
]
},
{
"statementType": "ownershipOrControlStatement",
"statementDate": "2017-11-18",
"subject": {
"describedByEntityStatement": "1dc0e987-5c57-4a1c-b3ad-61353b66a9b7"
},
"interestedParty": {
"describedByPersonStatement": "019a93f1-e470-42e9-957b-03559861b2e2"
},
"interests": [
{
"type": "shareholding",
"interestLevel": "direct",
"beneficialOwnershipOrControl":true,
"startDate": "2016-04-06",
"share": {
"exact": 100
}
}
]
},
{
},
{
"statementType": "test"
}
]
50 changes: 49 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from libcovebods.config import LibCoveBODSConfig


def unpack_validation_error(validation_error_result):
validation_error, data = validation_error_result
validation_error_data = json.loads(validation_error)
return validation_error_data, data


def test_basic_1():

cove_temp_folder = tempfile.mkdtemp(prefix='lib-cove-bods-tests-', dir=tempfile.gettempdir())
Expand Down Expand Up @@ -271,7 +277,49 @@ def test_basic_missing_statement_ids():

for validation_error, data in results['validation_errors']:
validation_error_data = json.loads(validation_error)
assert 'is not valid under any of the given schemas' in validation_error_data['message']
assert "'statementID' is missing but required" in validation_error_data['message']


def test_basic_statement_id_and_type_errors():

cove_temp_folder = tempfile.mkdtemp(prefix='lib-cove-bods-tests-', dir=tempfile.gettempdir())
json_filename = os.path.join(os.path.dirname(
os.path.realpath(__file__)), 'fixtures', 'api', 'basic_statement_id_and_type_errors.json'
)

results = bods_json_output(cove_temp_folder, json_filename)

assert results['file_type'] == 'json'
assert results['validation_errors_count'] == 5
assert results['additional_fields_count'] == 0
assert results['additional_checks_count'] == 1
assert results['statistics']['count_entity_statements'] == 1
assert results['statistics']['count_person_statements'] == 1
assert results['statistics']['count_ownership_or_control_statement'] == 1
assert results['statistics']['count_ownership_or_control_statement_interested_party_with_person'] == 1
assert results['statistics']['count_ownership_or_control_statement_interested_party_with_entity'] == 0

validation_error_data, data = unpack_validation_error(results['validation_errors'][0])
assert "'shortID' is too short" in validation_error_data['message']
assert data[0]['path'] == '1/statementID'
assert data[0]['value'] == 'shortID'

validation_error_data, data = unpack_validation_error(results['validation_errors'][1])
assert "'statementID' is missing but required" in validation_error_data['message']
assert data[0]['path'] == '0'
assert data[1]['path'] == '2'

validation_error_data, data = unpack_validation_error(results['validation_errors'][2])
assert "'statementType' is missing but required" in validation_error_data['message']
assert data[0]['path'] == '3'

validation_error_data, data = unpack_validation_error(results['validation_errors'][3])
assert "Invalid code found in 'statementType'" in validation_error_data['message']
assert data[0]['path'] == '4/statementType'
assert data[0]['value'] == 'test'

assert results['additional_checks'][0]['type'] == 'person_statement_not_used_in_ownership_or_control_statement'
assert results['additional_checks'][0]['person_statement'] == 'shortID'


def test_additional_fields_1():
Expand Down