Skip to content

Commit

Permalink
Add schema 0.2.0 and a basic test of example data from the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Jun 27, 2019
1 parent 1a1c2d3 commit f548707
Show file tree
Hide file tree
Showing 8 changed files with 1,904 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- Support for schema version 0.2.
If no meta information is in the data, 0.1 is assumed and work happens as before.
- Statistic: Count of current ownership/control statements
- Statistic: Count of ownership-or-control statements by year
- Statistic: Count of subjects of ownership-or-control statements by year
Expand Down
1,766 changes: 1,766 additions & 0 deletions data/schema-0-2-0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libcovebods/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def bods_json_output(output_dir, file, file_type=None, json_data=None,
except ValueError:
raise APIException('The file looks like invalid json')

schema_bods = SchemaBODS(lib_cove_bods_config=lib_cove_bods_config)
schema_bods = SchemaBODS(json_data=json_data, lib_cove_bods_config=lib_cove_bods_config)

else:

Expand Down
8 changes: 8 additions & 0 deletions libcovebods/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
)

LIB_COVE_BODS_CONFIG_DEFAULT.update({
# These details are used if the data does not specify a version
'schema_url': os.path.join(_schema_folder, 'schema-0-1-0.json'),
'schema_url_host': _schema_folder,
# But from 0.2 onwards, data should specify a version
'schema_versions': {
'0.2': {
'schema_url': os.path.join(_schema_folder, 'schema-0-2-0.json'),
'schema_url_host': _schema_folder,
}
},
# These default values are very wide on purpose. It is left to apps using this to tighten them up.
'bods_additional_checks_person_birthdate_min_year': 1,
'bods_additional_checks_person_birthdate_max_year': datetime.datetime.now().year,
Expand Down
15 changes: 14 additions & 1 deletion libcovebods/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

class SchemaBODS(SchemaJsonMixin):

def __init__(self, lib_cove_bods_config=None):
def __init__(self, json_data=None, lib_cove_bods_config=None):
# The default schema we use ...
self.release_pkg_schema_url = lib_cove_bods_config.config['schema_url']
self.schema_host = lib_cove_bods_config.config['schema_url_host']
# ... unless the data specifies a version.
if isinstance(json_data, list) and len(json_data) > 0:
statement = json_data[0]
if isinstance(statement, dict) \
and 'publicationDetails' in statement \
and isinstance(statement['publicationDetails'], dict) \
and 'bodsVersion' in statement['publicationDetails'] \
and statement['publicationDetails']['bodsVersion']:
version = statement['publicationDetails']['bodsVersion']
if version in lib_cove_bods_config.config['schema_versions']:
self.release_pkg_schema_url = lib_cove_bods_config.config['schema_versions'][version]['schema_url']
self.schema_host = lib_cove_bods_config.config['schema_versions'][version]['schema_url_host']
96 changes: 96 additions & 0 deletions tests/fixtures/0.2/basic_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[
{
"statementID": "1dc0e987-5c57-4a1c-b3ad-61353b66a9b7",
"statementType": "entityStatement",
"isComponent": false,
"statementDate": "2017-11-18",
"entityType": "registeredEntity",
"name": "CHRINON LTD",
"foundingDate": "2010-11-18",
"identifiers": [
{
"scheme": "GB-COH",
"id": "07444723"
}
],
"publicationDetails": {
"publicationDate": "2018-02-13",
"bodsVersion": "0.2",
"publisher": {
"name": "CHRINON LTD"
}
}
},
{
"statementID": "019a93f1-e470-42e9-957b-03559861b2e2",
"statementType": "personStatement",
"isComponent": false,
"statementDate": "2017-11-18",
"personType": "knownPerson",
"nationalities": [
{
"code": "GB"
}
],
"names": [
{
"type": "individual",
"fullName": "Christopher Taggart",
"givenName": "Christopher",
"familyName": "Taggart"
},
{
"type": "alternative",
"fullName": "Chris Taggart"
}
],
"birthDate": "1964-04",
"addresses": [
{
"type": "service",
"address": "Aston House, Cornwall Avenue, London",
"country": "GB",
"postCode": "N3 1LF"
}
],
"publicationDetails": {
"publicationDate": "2018-02-13",
"bodsVersion": "0.2",
"publisher": {
"name": "CHRINON LTD"
}
}
},
{
"statementID": "fbfd0547-d0c6-4a00-b559-5c5e91c34f5c",
"statementType": "ownershipOrControlStatement",
"isComponent": false,
"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,
"minimum": 100,
"maximum": 100
}
}
],
"publicationDetails": {
"publicationDate": "2018-02-13",
"bodsVersion": "0.2",
"publisher": {
"name": "CHRINON LTD"
}
}
}
]
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/test_api_0_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import tempfile
import os
from libcovebods.api import bods_json_output


def test_basic_1():

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', '0.2', 'basic_1.json'
)

results = bods_json_output(cove_temp_folder, json_filename)

assert results['validation_errors_count'] == 0
assert results['additional_fields_count'] == 0
assert results['additional_checks_count'] == 0

0 comments on commit f548707

Please sign in to comment.