Skip to content

Commit

Permalink
MHR api changes to support drafts. (#35)
Browse files Browse the repository at this point in the history
* MHR api changes to support drafts.

Signed-off-by: Doug Lovett <[email protected]>

* Rename draftId to draftNumber.

Signed-off-by: Doug Lovett <[email protected]>

* Rename draftId to draftNumber.

Signed-off-by: Doug Lovett <[email protected]>

* Add submittingParty to draftSummary.

Signed-off-by: Doug Lovett <[email protected]>

Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett authored Oct 4, 2022
1 parent e849a36 commit e75bb0c
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/registry_schemas/example_data/mhr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
ADDRESS,
BASE_INFORMATION,
DESCRIPTION,
DRAFT_SUMMARY,
DRAFT_TRANSFER,
LOCATION,
MANUFACTURER_INFO,
NOTE,
Expand All @@ -41,6 +43,8 @@
'ADDRESS',
'BASE_INFORMATION',
'DESCRIPTION',
'DRAFT_SUMMARY',
'DRAFT_TRANSFER',
'LOCATION',
'MANUFACTURER_INFO',
'NOTE',
Expand Down
97 changes: 97 additions & 0 deletions src/registry_schemas/example_data/mhr/schema_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,103 @@
'otherRemarks': 'Other comments'
}

DRAFT_SUMMARY = [
{
'draftNumber': '150234',
'registrationType': 'MHREG',
'registrationDescription': 'REGISTER NEW UNIT',
'path': '/mhr/api/v1/drafts/00000234',
'createDateTime': '2020-02-21T18:56:20+00:00',
'lastUpdateDateTime': '2022-02-21T18:56:20+00:00',
'registeringName': 'Michael Smith',
'clientReferenceId': 'D-100001020',
'submittingParty': 'JOHN SMITH NOTARY PUBLIC'
},
{
'draftNumber': '150234',
'mhrNumber': '125234',
'registrationType': 'TRANS',
'registrationDescription': 'SALE OR GIFT',
'path': '/mhr/api/v1/drafts/00000191',
'createDateTime': '2022-11-23T22:58:46+00:00',
'lastUpdateDateTime': '2022-11-30T18:22:22+00:00',
'registeringName': 'Michael Smith',
'clientReferenceId': 'D-100001005',
'submittingParty': 'JOHN SMITH NOTARY PUBLIC'
}
]

DRAFT_TRANSFER = {
'draftNumber': '150234',
'type': 'TRANS',
'registration': {
'draftNumber': '150234',
'mhrNumber': '125234',
'clientReferenceId': 'EX-TRANS-001',
'submittingParty': {
'businessName': 'ABC SEARCHING COMPANY',
'address': {
'street': '222 SUMMER STREET',
'city': 'VICTORIA',
'region': 'BC',
'country': 'CA',
'postalCode': 'V8W 2V8'
},
'emailAddress': '[email protected]',
'phoneNumber': '6041234567',
'phoneExtension': '546'
},
'deleteOwnerGroups': [
{
'groupId': 1,
'owners': [
{
'individualName': {
'first': 'Jane',
'last': 'Smith'
},
'address': {
'street': '3122B LYNNLARK PLACE',
'city': 'VICTORIA',
'region': 'BC',
'postalCode': ' ',
'country': 'CA'
},
'phoneNumber': '6041234567'
}
],
'type': 'SOLE'
}
],
'addOwnerGroups': [
{
'groupId': 2,
'owners': [
{
'individualName': {
'first': 'James',
'last': 'Smith'
},
'address': {
'street': '3122B LYNNLARK PLACE',
'city': 'VICTORIA',
'region': 'BC',
'postalCode': ' ',
'country': 'CA'
},
'phoneNumber': '6041234567'
}
],
'type': 'SOLE',
'status': 'ACTIVE'
}
],
'deathOfOwner': False
},
'createDateTime': '2020-02-21T18:56:20+00:00',
'lastUpdateDateTime': '2020-02-21T18:56:20+00:00'
}

LOCATION = {
'locationType': 'MH_PARK',
'status': 'ACTIVE',
Expand Down
37 changes: 37 additions & 0 deletions src/registry_schemas/schemas/mhr/draft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://bcrs.gov.bc.ca/.well_known/schemas/mhr/draft",
"type": "object",
"title": "The MHR Draft Schema",
"properties": {
"draftNumber": {
"type": "string",
"maxLength": 10,
"description": "The identifier of the draft document. It is generated and returned in the response when the draft is first created."
},
"type": {
"type": "string",
"maxLength": 20,
"enum": ["EXEMPTION_RES", "EXEMPTION_NON_RES", "MHREG", "PERMIT", "TRANS", "TRAND"],
"description": "<p>The set of registration types supported by this API.<ol><li>EXEMPTION_NON_RES - non-residential exemption</li><li>EXEMPTION_RES - residential exemption</li><li>MHREG - manufactured home registration</li><li>PERMIT - transport permit</li><li>TRAND - transfer due to the death of a joint tenant</li><li>TRANS - transfer sale or gift</li></ol></p>"
},
"registration": {
"type": "object"
},
"createDateTime": {
"type": [ "string", "null" ],
"format": "date-time",
"description": "Generated by the MHR application and included in a response, the date and time a record is created in the system."
},
"lastUpdateDateTime": {
"type": [ "string", "null" ],
"format": "date-time",
"description": "Generated by the MHR application and included in a response, the date and time of the last change to the draft. Null if no update is made."
}
},
"required": [
"type",
"registration"
]
}
74 changes: 74 additions & 0 deletions src/registry_schemas/schemas/mhr/draftSummary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://bcrs.gov.bc.ca/.well_known/schemas/mhr/draftSummary",
"type": "array",
"title": "The MHR Draft Summary List Schema",
"definitions": {
"draftSummary": {
"type": "object",
"properties": {
"draftNumber": {
"type": "string",
"maxLength": 10,
"description": "The identifier of the draft document. It is generated and returned in the response when the draft is first created."
},
"mhrNumber": {
"type": [ "string", "null" ],
"minLength": 6,
"maxLength": 6,
"description": "For changes registrations, the MH Registration Number for the manufactured home that the change applies to. It is empty for a draft MH registrations."
},
"registrationType": {
"type": "string",
"maxLength": 20,
"enum": ["EXEMPTION_RES", "EXEMPTION_NON_RES", "MHREG", "PERMIT", "TRANS", "TRAND"],
"description": "<p>The set of registration types supported by this API.<ol><li>EXEMPTION_NON_RES - non-residential exemption</li><li>EXEMPTION_RES - residential exemption</li><li>MHREG - manufactured home registration</li><li>PERMIT - transport permit</li><li>TRAND - transfer due to the death of a joint tenant</li><li>TRANS - transfer sale or gift</li></ol></p>"
},
"registrationDescription": {
"type": "string",
"maxLength": 100,
"description": "A description of the registration type, generated by the MHR application and returned in the response."
},
"path": {
"type": "string",
"maxLength": 250,
"description": "The relative path for a GET request to retrieve an individual draft document."
},
"registeringName": {
"type": [ "string", "null" ],
"maxLength": 150,
"description": "The name of the person who submitted the draft request in the format first name last name."
},
"createDateTime": {
"type": [ "string", "null" ],
"format": "date-time",
"description": "Generated by the MHR application, the date and time the draft is created."
},
"lastUpdateDateTime": {
"type": [ "string", "null" ],
"format": "date-time",
"description": "Generated by the MHR application, the date and time the of the most recent draft update. When the draft is created it is identical to createDateTime."
},
"clientReferenceId": {
"type": [ "string", "null" ],
"maxLength": 40,
"description": "An optional client reference identifier associated with a change. Provided to facilitate client tracking of MHR activity."
},
"submittingParty": {
"type": "string",
"maxlength": 150,
"description": "The registration Submitting Party name."
}
},
"required": [
"draftNumber",
"registrationType",
"path",
"createDateTime"
]
}
},
"items": {
"$ref": "#/definitions/draftSummary"
}
}
5 changes: 5 additions & 0 deletions src/registry_schemas/schemas/mhr/registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"maxLength": 6,
"description": "Unique manufactured home registration number assigned by the Manufactured Home Registry when a registration is created."
},
"draftNumber": {
"type": [ "string", "null" ],
"maxLength": 10,
"description": "The identifier of the draft document if the registration is created from a draft. Include to mark the draft as used so it will be excluded from the account list."
},
"documentId": {
"type": [ "string", "null" ],
"maxLength": 8,
Expand Down
5 changes: 5 additions & 0 deletions src/registry_schemas/schemas/mhr/transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"maxLength": 6,
"description": "Unique manufactured home registration number assigned by the Manufactured Home Registry when a registration is created."
},
"draftNumber": {
"type": [ "string", "null" ],
"maxLength": 10,
"description": "The identifier of the draft document if the registration is created from a draft. Include to mark the draft as used so it will be excluded from the account list."
},
"documentId": {
"type": [ "string", "null" ],
"maxLength": 8,
Expand Down
2 changes: 1 addition & 1 deletion src/registry_schemas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '1.6.2' # pylint: disable=invalid-name
__version__ = '1.6.3' # pylint: disable=invalid-name
67 changes: 67 additions & 0 deletions tests/unit/mhr/test_draft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright © 2020 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test Suite to ensure the MHGR Draft schema is valid."""
import copy

import pytest

from registry_schemas import validate
from registry_schemas.example_data.mhr import DRAFT_TRANSFER


# testdata pattern is ({desc}, {valid}, {type}, {has_reg}, {create}, {update}, {draft_id})
TEST_DATA_TRANSFER = [
('Valid TRANS', True, 'TRANS', True, None, None, None),
('Valid TRAND', True, 'TRAND', True, None, None, None),
('Valid MHREG', True, 'MHREG', True, None, None, None),
('Valid PERMIT', True, 'PERMIT', True, None, None, None),
('Valid EXEMPTION_RES', True, 'EXEMPTION_RES', True, None, None, None),
('Valid EXEMPTION_NON_RES', True, 'EXEMPTION_NON_RES', True, None, None, None),
('Invalid missing type', False, None, True, None, None, None),
('Invalid type', False, 'XXXXX', True, None, None, None),
('Invalid missing registration', False, 'TRANS', False, None, None, None),
('Invalid create', False, 'TRANS', True, 'XXXXXXXXXXXX', None, None),
('Invalid update', False, 'TRANS', True, None, 'XXXXXXXXXXXX', None),
('Invalid draft id too long', False, 'TRANS', True, None, None, '01234567891')
]


@pytest.mark.parametrize('desc,valid,type,has_reg,create,update,draft_id', TEST_DATA_TRANSFER)
def test_draft(desc, valid, type, has_reg, create, update, draft_id):
"""Assert that the schema is performing as expected for a draft."""
draft = copy.deepcopy(DRAFT_TRANSFER)
if not type:
del draft['type']
else:
draft['type'] = type
if not has_reg:
del draft['registration']
if create:
draft['createDateTime'] = create
if update:
draft['lastUpdateDateTime'] = update
if draft_id:
draft['draftNumber'] = draft_id

is_valid, errors = validate(draft, 'draft', 'mhr')

if errors:
for err in errors:
print(err.message)
print(errors)

if valid:
assert is_valid
else:
assert not is_valid
59 changes: 59 additions & 0 deletions tests/unit/mhr/test_draft_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright © 2020 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test Suite to ensure the PPR Draft Summary schema is valid."""
import copy

import pytest

from registry_schemas import validate
from registry_schemas.example_data.mhr import DRAFT_SUMMARY


# testdata pattern is ({desc}, {valid}, {empty}, {has_id}, {has_type}, {has_path}, {has_create})
TEST_DATA = [
('Valid non-empty', True, False, True, True, True, True),
('Valid empty', True, True, True, True, True, True),
('Invalid missing draftNumber', False, False, False, True, True, True),
('Invalid missing type', False, False, True, False, True, True),
('Invalid missing path', False, False, True, True, False, True),
('Invalid missing createDateTime', False, False, True, True, True, False)
]


@pytest.mark.parametrize('desc,valid,empty,has_id,has_type,has_path,has_create', TEST_DATA)
def test_draft_summary(desc, valid, empty, has_id, has_type, has_path, has_create):
"""Assert that the schema is performing as expected for a draft summary list."""
drafts = copy.deepcopy(DRAFT_SUMMARY)
if empty:
drafts = []
else:
if not has_id:
del drafts[0]['draftNumber']
if not has_type:
del drafts[0]['registrationType']
if not has_path:
del drafts[0]['path']
if not has_create:
del drafts[0]['createDateTime']
is_valid, errors = validate(drafts, 'draftSummary', 'mhr')

if errors:
for err in errors:
print(err.message)
print(errors)

if valid:
assert is_valid
else:
assert not is_valid

0 comments on commit e75bb0c

Please sign in to comment.