Skip to content

Commit

Permalink
Merge pull request #68 from openownership/67-500-crash
Browse files Browse the repository at this point in the history
bugfix: crash when statementID is not a string & Release: 0.10.1
  • Loading branch information
James (ODSC) authored Sep 22, 2021
2 parents 50f91b1 + 8d30684 commit 19bc3ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.10.1] - 2021-09-22

### Fixed

- A crash when statementID is not a string https://github.com/openownership/cove-bods/issues/67

## [0.10.0] - 2021-04-08

### Changed
Expand Down
2 changes: 1 addition & 1 deletion libcovebods/lib/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def run(self):
count_replaces_statements_missing += 1
if replaces_statement_id in current_statement_ids:
current_statement_ids.remove(replaces_statement_id)
if 'statementID' in statement:
if 'statementID' in statement and isinstance(statement['statementID'], str):
statement_ids.add(statement['statementID'])

# Return Results
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='libcovebods',
version='0.10.0',
version='0.10.1',
author='Open Data Services',
author_email='[email protected]',
url='https://github.com/openownership/lib-cove-bods',
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/0.2/bad_statement_id_type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"statementID": {},
"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"
}
}
}
]
18 changes: 18 additions & 0 deletions tests/test_api_0_2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import tempfile
import os
from libcovebods.api import bods_json_output
Expand Down Expand Up @@ -33,3 +34,20 @@ def test_iscompontent_os_03_dr_03():
assert results['validation_errors_count'] == 0
assert results['additional_fields_count'] == 0
assert results['additional_checks_count'] == 0


def test_bad_statement_id_type():

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

results = bods_json_output(cove_temp_folder, json_filename)

assert results['schema_version'] == '0.2'
assert results['validation_errors_count'] == 1
validation_error = json.loads(results['validation_errors'][0][0])
assert validation_error['message'].startswith("'statementID' should be a string.")
assert results['additional_fields_count'] == 0
assert results['additional_checks_count'] == 0

0 comments on commit 19bc3ba

Please sign in to comment.