Skip to content

Commit

Permalink
bugfix: crash when statementID is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Sep 21, 2021
1 parent dc7c8ac commit 6f63877
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions 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]

### 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
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"
}
}
}
]
19 changes: 19 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,21 @@ 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 6f63877

Please sign in to comment.