Skip to content

Commit

Permalink
MHR staff death transfer validation updates. (#2074)
Browse files Browse the repository at this point in the history
* MHR staff death transfer validation updates.

Signed-off-by: Doug Lovett <doug@diamante.ca>

* MHR/PPR minor update to report request log messages.

Signed-off-by: Doug Lovett <doug@diamante.ca>

---------

Signed-off-by: Doug Lovett <doug@diamante.ca>
  • Loading branch information
doug-lovett authored Nov 27, 2024
1 parent 0e14c88 commit 391fff7
Show file tree
Hide file tree
Showing 14 changed files with 890 additions and 712 deletions.
2 changes: 1 addition & 1 deletion mhr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mhr-api"
version = "2.0.4"
version = "2.0.5"
description = ""
authors = ["dlovett <doug@daxiom.com>"]
license = "BSD 3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def get_registration_callback_report(
doc_name = model_utils.get_doc_storage_name(registration)
logger.info(f"Saving registration report output to doc storage: name={doc_name}.")
response = GoogleStorageService.save_document(doc_name, raw_data, DocumentTypes.REGISTRATION)
logger.info(f"Updating report tracking doc_storage_url to {doc_name}.")
logger.info(f"Updating report tracking doc_storage_url to {doc_name}, doc storage response {response}.")
report_info.doc_storage_url = doc_name
report_info.save()
# Track success event.
EventTracking.create(
registration_id, EventTracking.EventTrackingTypes.MHR_REGISTRATION_REPORT, int(HTTPStatus.OK)
)
return response, HTTPStatus.OK
return {}, HTTPStatus.OK
except ReportException as report_err:
return registration_callback_error(
resource_utils.CallbackExceptionCodes.REPORT_ERR,
Expand Down
2 changes: 1 addition & 1 deletion mhr-api/src/mhr_api/resources/v1/search_report_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def post_search_report_callback( # pylint: disable=too-many-branches,too-many-l
doc_name = model_utils.get_search_doc_storage_name(search_detail.search)
logger.info(f"Saving report output to doc storage: name={doc_name}.")
response = GoogleStorageService.save_document(doc_name, raw_data)
logger.info("Save document storage response: " + str(response))
logger.info(f"Save document storage response: {response}")
search_detail.doc_storage_url = doc_name
search_detail.save()

Expand Down
2 changes: 1 addition & 1 deletion mhr-api/src/mhr_api/resources/v1/search_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def generate_search_report(search_detail: SearchResult, search_id: str):
doc_name = model_utils.get_search_doc_storage_name(search_detail.search)
logger.info(f"Saving report output to doc storage: name={doc_name}.")
response = GoogleStorageService.save_document(doc_name, raw_data)
logger.info("Save document storage response: " + str(response))
logger.info(f"Save document storage response: {response}")
search_detail.doc_storage_url = doc_name
search_detail.save()

Expand Down
8 changes: 4 additions & 4 deletions mhr-api/src/mhr_api/utils/admin_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mhr_api.models import MhrRegistration
from mhr_api.models import registration_utils as reg_utils
from mhr_api.models.type_tables import MhrDocumentTypes, MhrNoteStatusTypes, MhrRegistrationTypes
from mhr_api.utils import validator_utils
from mhr_api.utils import validator_utils, validator_owner_utils
from mhr_api.utils.logging import logger

NCAN_DOC_TYPES = " CAU CAUC CAUE NCON NPUB REGC REST " # Set of doc types NCAN can cancel.
Expand Down Expand Up @@ -212,11 +212,11 @@ def validate_owners(registration: MhrRegistration, json_data: dict) -> str:
error_msg += DELETE_OWNERS_MISSING
if not json_data.get("addOwnerGroups") or not json_data.get("deleteOwnerGroups"):
return error_msg
active_group_count: int = validator_utils.get_active_group_count(json_data, registration)
active_group_count: int = validator_owner_utils.get_active_group_count(json_data, registration)
error_msg += validator_utils.validate_submitting_party(json_data)
error_msg += validator_utils.validate_owner_groups(
error_msg += validator_owner_utils.validate_owner_groups(
json_data.get("addOwnerGroups"), False, registration, json_data.get("deleteOwnerGroups"), active_group_count
)
if registration and json_data.get("deleteOwnerGroups"):
error_msg += validator_utils.validate_delete_owners(registration, json_data)
error_msg += validator_owner_utils.validate_delete_owners(registration, json_data)
return error_msg
350 changes: 96 additions & 254 deletions mhr-api/src/mhr_api/utils/registration_validator.py

Large diffs are not rendered by default.

711 changes: 711 additions & 0 deletions mhr-api/src/mhr_api/utils/validator_owner_utils.py

Large diffs are not rendered by default.

379 changes: 0 additions & 379 deletions mhr-api/src/mhr_api/utils/validator_utils.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions mhr-api/tests/unit/utils/test_admin_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from registry_schemas import utils as schema_utils
from registry_schemas.example_data.mhr import DESCRIPTION

from mhr_api.utils import admin_validator as validator, validator_utils
from mhr_api.utils import admin_validator as validator, validator_utils, validator_owner_utils as val_owner_utils
from mhr_api.models import MhrRegistration
from mhr_api.models.type_tables import MhrDocumentTypes
from mhr_api.services.authz import STAFF_ROLE
Expand Down Expand Up @@ -479,14 +479,14 @@
(False, '000919', 'REGC_STAFF', None, None, None, DELETE_OG_VALID, validator.ADD_OWNERS_MISSING),
(False, '000919', 'REGC_STAFF', None, None, ADD_OG_VALID, None, validator.DELETE_OWNERS_MISSING),
(False, '000919', 'REGC_STAFF', None, None, ADD_OG_INVALID_JT, DELETE_OG_VALID,
validator_utils.OWNERS_JOINT_INVALID),
val_owner_utils.OWNERS_JOINT_INVALID),
(True, '000912', 'EXRE', LOCATION_VALID, None, None, None, None),
(True, '000912', 'EXRE', LOCATION_VALID_MINIMAL, None, None, None, None),
(False, '000912', 'EXRE', LOCATION_000912, None, None, None, validator_utils.LOCATION_INVALID_IDENTICAL),
(False, '000912', 'EXRE', None, DESCRIPTION_000912, None, None, validator_utils.DESCRIPTION_INVALID_IDENTICAL),
(False, '000912', 'EXRE', None, None, None, DELETE_OG_000912, validator.ADD_OWNERS_MISSING),
(False, '000912', 'EXRE', None, None, ADD_OG_VALID, None, validator.DELETE_OWNERS_MISSING),
(False, '000912', 'EXRE', None, None, ADD_OG_INVALID_JT, DELETE_OG_000912, validator_utils.OWNERS_JOINT_INVALID),
(False, '000912', 'EXRE', None, None, ADD_OG_INVALID_JT, DELETE_OG_000912, val_owner_utils.OWNERS_JOINT_INVALID),
(True, '000912', 'EXRE', None, None, ADD_OG_VALID, DELETE_OG_000912, None),
(True, '000912', 'EXRE', None, DESCRIPTION, None, None, None)
]
Expand Down
53 changes: 25 additions & 28 deletions mhr-api/tests/unit/utils/test_registration_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from registry_schemas.example_data.mhr import REGISTRATION, TRANSFER, EXEMPTION

from mhr_api.utils import registration_validator as validator, manufacturer_validator as man_validator, validator_utils
from mhr_api.utils import validator_owner_utils as val_owner_utils
from mhr_api.models import MhrRegistration, MhrManufacturer, utils as model_utils
from mhr_api.models.type_tables import MhrRegistrationTypes, MhrTenancyTypes, MhrDocumentTypes
from mhr_api.models.utils import now_ts
Expand Down Expand Up @@ -144,11 +145,7 @@
('Reg invalid last name', None, 'first', 'middle', INVALID_TEXT_CHARSET, INVALID_CHARSET_MESSAGE, REGISTRATION),
('Reg street non utf-8', None, 'first', 'middle', 'last', None, REGISTRATION),
('Reg streetAdditional non utf-8', None, 'first', 'middle', 'last', None, REGISTRATION),
('Reg city non utf-8', None, 'first', 'middle', 'last', None, REGISTRATION),
('Trans invalid org/bus name', INVALID_TEXT_CHARSET, None, None, None, INVALID_CHARSET_MESSAGE, TRANSFER),
('Trans invalid first name', None, INVALID_TEXT_CHARSET, 'middle', 'last', INVALID_CHARSET_MESSAGE, TRANSFER),
('Trans invalid middle name', None, 'first', INVALID_TEXT_CHARSET, 'last', INVALID_CHARSET_MESSAGE, TRANSFER),
('Trans invalid last name', None, 'first', 'middle', INVALID_TEXT_CHARSET, INVALID_CHARSET_MESSAGE, TRANSFER)
('Reg city non utf-8', None, 'first', 'middle', 'last', None, REGISTRATION)
]
# testdata pattern is ({description}, {park_name}, {dealer}, {pad}, {reserve_num}, {band_name}, {pid_num}, {message content})
TEST_LOCATION_DATA_MANUFACTURER = [
Expand Down Expand Up @@ -288,25 +285,25 @@
('Valid TC', True, 1, 2, TC_GROUPS_VALID, None),
('Valid SO', True, None, None, SO_VALID, None),
('Valid JT', True, None, None, JT_VALID, None),
('Invalid TC no owner', False, 1, 2, TC_GROUPS_VALID, validator_utils.OWNERS_COMMON_INVALID),
('Invalid TC SO group', False, 1, 2, TC_GROUPS_VALID, validator_utils.OWNERS_COMMON_SOLE_INVALID),
('Invalid TC 2 owners', False, 1, 2, TC_GROUPS_VALID, validator_utils.OWNERS_COMMON_INVALID),
('Invalid TC only 1 group', False, 2, 2, TC_GROUPS_VALID, validator_utils.GROUP_COMMON_INVALID),
('Invalid TC numerator missing', False, None, 2, TC_GROUPS_VALID, validator_utils.GROUP_NUMERATOR_MISSING),
('Invalid TC numerator < 1', False, 0, 2, TC_GROUPS_VALID, validator_utils.GROUP_NUMERATOR_MISSING),
('Invalid TC denominator missing', False, 1, None, TC_GROUPS_VALID, validator_utils.GROUP_DENOMINATOR_MISSING),
('Invalid TC denominator < 1', False, 1, 0, TC_GROUPS_VALID, validator_utils.GROUP_DENOMINATOR_MISSING),
('Invalid JT 1 owner', False, None, None, JT_OWNER_SINGLE, validator_utils.OWNERS_JOINT_INVALID),
('Invalid SO 2 groups', False, None, None, SO_GROUP_MULTIPLE, validator_utils.ADD_SOLE_OWNER_INVALID),
('Invalid SO 2 owners', False, None, None, SO_OWNER_MULTIPLE, validator_utils.ADD_SOLE_OWNER_INVALID)
('Invalid TC no owner', False, 1, 2, TC_GROUPS_VALID, val_owner_utils.OWNERS_COMMON_INVALID),
('Invalid TC SO group', False, 1, 2, TC_GROUPS_VALID, val_owner_utils.OWNERS_COMMON_SOLE_INVALID),
('Invalid TC 2 owners', False, 1, 2, TC_GROUPS_VALID, val_owner_utils.OWNERS_COMMON_INVALID),
('Invalid TC only 1 group', False, 2, 2, TC_GROUPS_VALID, val_owner_utils.GROUP_COMMON_INVALID),
('Invalid TC numerator missing', False, None, 2, TC_GROUPS_VALID, val_owner_utils.GROUP_NUMERATOR_MISSING),
('Invalid TC numerator < 1', False, 0, 2, TC_GROUPS_VALID, val_owner_utils.GROUP_NUMERATOR_MISSING),
('Invalid TC denominator missing', False, 1, None, TC_GROUPS_VALID, val_owner_utils.GROUP_DENOMINATOR_MISSING),
('Invalid TC denominator < 1', False, 1, 0, TC_GROUPS_VALID, val_owner_utils.GROUP_DENOMINATOR_MISSING),
('Invalid JT 1 owner', False, None, None, JT_OWNER_SINGLE, val_owner_utils.OWNERS_JOINT_INVALID),
('Invalid SO 2 groups', False, None, None, SO_GROUP_MULTIPLE, val_owner_utils.ADD_SOLE_OWNER_INVALID),
('Invalid SO 2 owners', False, None, None, SO_OWNER_MULTIPLE, val_owner_utils.ADD_SOLE_OWNER_INVALID)
]
# testdata pattern is ({description}, {valid}, {interest_data}, {common_denominator}, {message content})
TEST_DATA_GROUP_INTEREST = [
('Valid 2 groups', True, INTEREST_VALID_1, 2, None),
('Valid 3 groups', True, INTEREST_VALID_2, 4, None),
('Valid 3 groups', True, INTEREST_VALID_3, 10, None),
('Invalid numerator sum low', False, INTEREST_INVALID_1, 4, validator_utils.GROUP_INTEREST_MISMATCH),
('Invalid numerator sum high', False, INTEREST_INVALID_2, 4, validator_utils.GROUP_INTEREST_MISMATCH)
('Invalid numerator sum low', False, INTEREST_INVALID_1, 4, val_owner_utils.GROUP_INTEREST_MISMATCH),
('Invalid numerator sum high', False, INTEREST_INVALID_2, 4, val_owner_utils.GROUP_INTEREST_MISMATCH)
]
# testdata pattern is ({description}, {mhr_number}, {message content})
TEST_DATA_LIEN_COUNT = [
Expand All @@ -323,16 +320,16 @@
('Valid TC exec', True, JT_VALID_EXEC, TC_VALID_EXEC, None, None, None),
('Valid TC trustee', True, JT_VALID_TRUSTEE, TC_VALID_TRUSTEE, None, None, None),
('Valid TC admin', True, JT_VALID_ADMIN, TC_VALID_ADMIN, None, None, None),
('Invalid SO type NA', False, SO_VALID_EXEC, None, 'NA', None, validator.TENANCY_TYPE_NA_INVALID),
('Invalid SO exec no desc', False, SO_VALID_EXEC, None, None, None, validator.OWNER_DESCRIPTION_REQUIRED),
('Invalid SO type NA', False, SO_VALID_EXEC, None, 'NA', None, val_owner_utils.TENANCY_TYPE_NA_INVALID),
('Invalid SO exec no desc', False, SO_VALID_EXEC, None, None, None, val_owner_utils.OWNER_DESCRIPTION_REQUIRED),
('Invalid common type JOINT', False, JT_VALID_EXEC, TC_VALID_EXEC, 'JOINT', None,
validator.TENANCY_PARTY_TYPE_INVALID),
('Invalid JT party types 1', False, JT_VALID_EXEC, None, None, 'ADMINISTRATOR', validator.GROUP_PARTY_TYPE_INVALID),
('Invalid JT party types 2', False, JT_VALID_TRUSTEE, None, None, 'EXECUTOR', validator.GROUP_PARTY_TYPE_INVALID),
('Invalid JT party types 3', False, JT_VALID_ADMIN, None, None, 'TRUSTEE', validator.GROUP_PARTY_TYPE_INVALID),
('Invalid JT type NA', False, JT_GROUP_VALID, None, 'NA', None, validator_utils.TENANCY_TYPE_NA_INVALID2),
('Invalid NA type mix', False, JT_GROUP_MIX, None, None, None, validator_utils.TENANCY_TYPE_NA_INVALID2),
('Invalid JT type mix', False, JT_GROUP_MIX, None, 'JT', None, validator.TENANCY_PARTY_TYPE_INVALID)
val_owner_utils.TENANCY_PARTY_TYPE_INVALID),
('Invalid JT party types 1', False, JT_VALID_EXEC, None, None, 'ADMINISTRATOR', val_owner_utils.GROUP_PARTY_TYPE_INVALID),
('Invalid JT party types 2', False, JT_VALID_TRUSTEE, None, None, 'EXECUTOR', val_owner_utils.GROUP_PARTY_TYPE_INVALID),
('Invalid JT party types 3', False, JT_VALID_ADMIN, None, None, 'TRUSTEE', val_owner_utils.GROUP_PARTY_TYPE_INVALID),
('Invalid JT type NA', False, JT_GROUP_VALID, None, 'NA', None, val_owner_utils.TENANCY_TYPE_NA_INVALID2),
('Invalid NA type mix', False, JT_GROUP_MIX, None, None, None, val_owner_utils.TENANCY_TYPE_NA_INVALID2),
('Invalid JT type mix', False, JT_GROUP_MIX, None, 'JT', None, val_owner_utils.TENANCY_PARTY_TYPE_INVALID)
]


Expand Down Expand Up @@ -699,7 +696,7 @@ def test_validate_group_interest(session, desc, valid, interest_data, common_den
group['interestNumerator'] = interest.get('numerator')
group['interestDenominator'] = interest.get('denominator')
json_data.append(group)
error_msg = validator_utils.validate_group_interest(json_data, common_den)
error_msg = val_owner_utils.validate_group_interest(json_data, common_den)
if valid:
assert error_msg == ''
else:
Expand Down
Loading

0 comments on commit 391fff7

Please sign in to comment.