From e14f71451b2b1e5c14210b5edd9236d1e5f0a23a Mon Sep 17 00:00:00 2001 From: Colin Blackburn Date: Thu, 7 Mar 2024 16:05:28 +0000 Subject: [PATCH] Add summary to schema, use and test schema --- app/checkers.py | 6 +++--- app/schemas.py | 1 + test/fixtures_json.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/checkers.py b/app/checkers.py index a473626..04f2145 100644 --- a/app/checkers.py +++ b/app/checkers.py @@ -43,11 +43,11 @@ def check_ags(filename: Path, standard_AGS4_dictionary: Optional[str] = None) -> errors = {'File read error': [{'line': line_no, 'group': '', 'desc': description}]} dictionary = '' - # Discard unecessary summary from errors dictionary - errors.pop('Summary of data', None) + # Use summary from errors dictionary is available + summary = errors.pop('Summary of data', []) return dict(checker=f'python_ags4 v{python_ags4.__version__}', - errors=errors, dictionary=dictionary) + errors=errors, dictionary=dictionary, summary=summary) def check_bgs(filename: Path, **kwargs) -> dict: diff --git a/app/schemas.py b/app/schemas.py index e1040c3..859f04f 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -47,6 +47,7 @@ class Validation(BaseModel): message: str = Field(None, example="7 error(s) found in file!") errors: Dict[str, List[LineError]] = Field(..., example="Rule 1a") valid: bool = Field(..., example='false') + summary: List[dict] = list() additional_metadata: dict = Field(...) geojson: dict = dict() geojson_error: str = None diff --git a/test/fixtures_json.py b/test/fixtures_json.py index 6085424..4b2f939 100644 --- a/test/fixtures_json.py +++ b/test/fixtures_json.py @@ -10,6 +10,7 @@ 'message': 'All checks passed!', 'errors': {}, 'valid': True, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -97,6 +98,7 @@ ], }, "valid": False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -123,6 +125,7 @@ 'AGS Format Rule 15': [{'line': '-', 'group': 'UNIT', 'desc': 'UNIT group not found.'}], 'AGS Format Rule 17': [{'line': '-', 'group': 'TYPE', 'desc': 'TYPE group not found.'}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -287,6 +290,7 @@ "If not 'utf-8', then the encoding is most likely to be 'windows-1252' " "aka 'cp1252')"}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -305,6 +309,7 @@ 'group': '', 'line': 1}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -705,6 +710,7 @@ 'It is highly recommended that the file be saved without BOM encoding ' 'to avoid issues with other software.'}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -724,6 +730,7 @@ 'line': 1}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -738,6 +745,7 @@ 'errors': {'File read error': [ {'line': '-', 'group': '', 'desc': 'extension_is.bad is not an .ags file'}]}, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -754,6 +762,7 @@ 'message': 'All checks passed!', 'errors': {}, 'valid': True, + 'summary': [], 'additional_metadata': {}, 'geojson': { 'features': [{ @@ -896,6 +905,7 @@ ], }, "valid": False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': 'Line 31 does not have the same number of entries as the HEADING row in TYPE.' @@ -917,6 +927,7 @@ 'desc': ''}], }, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None @@ -934,6 +945,7 @@ 'desc': ''}], }, 'valid': False, + 'summary': [], 'additional_metadata': {}, 'geojson': {}, 'geojson_error': None