From d14cfc976184d9d5b956254bba78f9be6a069db8 Mon Sep 17 00:00:00 2001 From: Doug Lovett Date: Mon, 15 Jan 2024 08:27:05 -0800 Subject: [PATCH] MHR API correction/amendment registration schema updates. (#62) Signed-off-by: Doug Lovett --- .../schemas/mhr/adminRegistration.json | 17 +++- .../schemas/mhr/registration.json | 5 ++ src/registry_schemas/version.py | 2 +- tests/unit/mhr/test_admin_registration.py | 77 +++++++++++++++++-- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/registry_schemas/schemas/mhr/adminRegistration.json b/src/registry_schemas/schemas/mhr/adminRegistration.json index 33d3be1..d8f70c9 100644 --- a/src/registry_schemas/schemas/mhr/adminRegistration.json +++ b/src/registry_schemas/schemas/mhr/adminRegistration.json @@ -10,6 +10,12 @@ "maxLength": 6, "description": "Unique manufactured home registration number assigned by the Manufactured Home Registry when a registration is created." }, + "status": { + "type": [ "string", "null" ], + "maxLength": 20, + "enum": ["ACTIVE", "EXEMPT", "FROZEN", "CANCELLED"], + "description": "The status of the registration. ACTIVE - registered; FROZEN; EXEMPT;CANCELLED - cancelled. FROZEN is a temporary state where only BC Registries staff can make a change to the manufactured home." + }, "documentId": { "type": [ "string", "null" ], "maxLength": 8, @@ -52,7 +58,7 @@ "documentType": { "type": "string", "maxLength": 20 , - "enum": ["ADDI", "ATTA", "COMP", "CONF", "COUR", "DNCH", "EXRE", "FZE", "INTE", "INTW", "MAID", "MAIL", "MARR", "MEAM", "NAMV", "NCAN", "NRED", "PDEC", "PUBA", "REBU", "REGC", "STAT", "THAW", "WHAL", "AMEND_PERMIT", "CANCEL_PERMIT"] + "enum": ["ADDI", "ATTA", "COMP", "CONF", "COUR", "DNCH", "EXRE", "FZE", "INTE", "INTW", "MAID", "MAIL", "MARR", "MEAM", "NAMV", "NCAN", "NRED", "PDEC", "PUBA", "REBU", "REGC", "REGC_CLIENT", "REGC_STAFF", "STAT", "THAW", "WHAL", "AMEND_PERMIT", "CANCEL_PERMIT"] }, "updateDocumentId": { "type": [ "string", "null" ], @@ -62,7 +68,14 @@ "note": { "$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/mhr/note" }, - "ownerGroups": { + "deleteOwnerGroups": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/mhr/ownerGroup" + } + }, + "addOwnerGroups": { "type": "array", "minItems": 1, "items": { diff --git a/src/registry_schemas/schemas/mhr/registration.json b/src/registry_schemas/schemas/mhr/registration.json index a086eea..2ea75f5 100644 --- a/src/registry_schemas/schemas/mhr/registration.json +++ b/src/registry_schemas/schemas/mhr/registration.json @@ -31,6 +31,11 @@ "maxLength": 100, "description": "Included in a response as a description of the registration report document." }, + "documentType": { + "type": "string", + "maxLength": 20, + "description": "Conditionally included in a response to support internal registration report generation." + }, "registrationType": { "type": "string", "maxLength": 20, diff --git a/src/registry_schemas/version.py b/src/registry_schemas/version.py index 1cb5543..84d36b8 100644 --- a/src/registry_schemas/version.py +++ b/src/registry_schemas/version.py @@ -22,4 +22,4 @@ Development release segment: .devN """ -__version__ = '1.8.8' # pylint: disable=invalid-name +__version__ = '1.8.9' # pylint: disable=invalid-name diff --git a/tests/unit/mhr/test_admin_registration.py b/tests/unit/mhr/test_admin_registration.py index e07ecd7..4420880 100644 --- a/tests/unit/mhr/test_admin_registration.py +++ b/tests/unit/mhr/test_admin_registration.py @@ -17,16 +17,18 @@ import pytest from registry_schemas import validate -from registry_schemas.example_data.mhr import ADMIN_REGISTRATION, LOCATION +from registry_schemas.example_data.mhr import ADMIN_REGISTRATION, DESCRIPTION, LOCATION, OWNER_GROUP LONG_CLIENT_REF = '012345678901234567890123456789012345678901234567890' +OWNER_GROUPS = [ + OWNER_GROUP +] # testdata pattern is ({desc},{valid},{doc_type},{has_submitting},{is_request},{client_ref}, {attention}) TEST_DATA = [ ('Valid request COUR', True, 'COUR', True, True, None, None), ('Valid request NRED', True, 'NRED', True, True, None, None), ('Valid request NCAN', True, 'NCAN', True, True, None, None), - ('Valid request REGC', True, 'REGC', True, True, None, None), ('Valid request STAT', True, 'STAT', True, True, None, None), ('Valid request CANCEL_PERMIT', True, 'CANCEL_PERMIT', True, True, None, None), ('Valid response CANCEL_PERMIT', True, 'CANCEL_PERMIT', True, True, None, None), @@ -38,10 +40,28 @@ ('Invalid missing sub party', False, 'NRED', False, True, None, None), ('Invalid update doc id', False, 'NRED', True, True, None, None) ] +# testdata pattern is ({desc},{valid},{doc_type},{status},{location},{description}, {owner_group}) +TEST_DATA_AMEND_CORRECT = [ + ('Valid amendment location', True, 'PUBA', None, LOCATION, None, None), + ('Valid staff correction location', True, 'REGC_STAFF', None, LOCATION, None, None), + ('Valid client correction location', True, 'REGC_CLIENT', None, LOCATION, None, None), + ('Valid amendment description', True, 'PUBA', None, None, DESCRIPTION, None), + ('Valid staff correction description', True, 'REGC_STAFF', None, None, DESCRIPTION, None), + ('Valid client correction description', True, 'REGC_CLIENT', None, None, DESCRIPTION, None), + ('Valid amendment owners', True, 'PUBA', None, None, None, OWNER_GROUPS), + ('Valid staff correction owners', True, 'REGC_STAFF', None, None, None, OWNER_GROUPS), + ('Valid client correction owners', True, 'REGC_CLIENT', None, None, None, OWNER_GROUPS), + ('Valid amendment status', True, 'PUBA', 'ACTIVE', None, None, None), + ('Valid staff correction status', True, 'REGC_STAFF', 'EXEMPT', None, None, None), + ('Invalid client correction status', False, 'REGC_CLIENT', 'JUNK', None, None, None), + ('Invalid client correction location', False, 'REGC_CLIENT', None, LOCATION, None, None), + ('Invalid staff correction description', False, 'REGC_STAFF', None, None, DESCRIPTION, None), + ('Invalid amendment owners', False, 'PUBA', None, None, None, OWNER_GROUPS), +] @pytest.mark.parametrize('desc,valid,doc_type,has_sub,is_request,client_ref,attention', TEST_DATA) -def test_note_registration(desc, valid, doc_type, has_sub, is_request, client_ref, attention): +def test_admin_registration(desc, valid, doc_type, has_sub, is_request, client_ref, attention): """Assert that the staff admin registration schema is performing as expected.""" data = copy.deepcopy(ADMIN_REGISTRATION) if not doc_type: @@ -65,8 +85,9 @@ def test_note_registration(desc, valid, doc_type, has_sub, is_request, client_re del data['registrationType'] if desc == 'Invalid update doc id': data['updateDocumentId'] = '123456789' - elif desc in ('Valid request REGC', 'Valid request STAT', - 'Valid request CANCEL_PERMIT', 'Valid response CANCEL_PERMIT'): + elif desc in ('Valid request STAT', + 'Valid request CANCEL_PERMIT', + 'Valid response CANCEL_PERMIT'): data['location'] = copy.deepcopy(LOCATION) if desc in ('Valid request CANCEL_PERMIT', 'Valid response CANCEL_PERMIT'): data['documentType'] = 'CANCEL_PERMIT' @@ -81,3 +102,49 @@ def test_note_registration(desc, valid, doc_type, has_sub, is_request, client_re assert is_valid else: assert not is_valid + + +@pytest.mark.parametrize('desc,valid,doc_type,status,location,description,owner_group', TEST_DATA_AMEND_CORRECT) +def test_admin_amend_correct(desc, valid, doc_type, status, location, description, owner_group): + """Assert that the staff admin registration schema is performing as expected for amendments/corrections.""" + data = copy.deepcopy(ADMIN_REGISTRATION) + data['documentType'] = doc_type + del data['mhrNumber'] + del data['createDateTime'] + del data['payment'] + del data['registrationType'] + if status: + data['status'] = status + if location: + if valid: + data['location'] = location + else: + bad_location = copy.deepcopy(location) + del bad_location['locationType'] + data['location'] = bad_location + if description: + if valid: + data['description'] = description + else: + bad_desc = copy.deepcopy(description) + del bad_desc['sections'] + data['description'] = bad_desc + if owner_group: + data['deleteOwnerGroups'] = owner_group + if valid: + data['addOwnerGroups'] = owner_group + else: + bad_owners = copy.deepcopy(owner_group) + del bad_owners[0]['type'] + data['addOwnerGroups'] = bad_owners + + is_valid, errors = validate(data, 'adminRegistration', 'mhr') + + if errors: + for err in errors: + print(err.message) + + if valid: + assert is_valid + else: + assert not is_valid