Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPR, MHR latest schema updates. #63

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/registry_schemas/schemas/mhr/adminRegistration.json
Original file line number Diff line number Diff line change
@@ -58,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", "REGC_CLIENT", "REGC_STAFF", "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", "REREGISTER_C"]
},
"updateDocumentId": {
"type": [ "string", "null" ],
11 changes: 11 additions & 0 deletions src/registry_schemas/schemas/mhr/note.json
Original file line number Diff line number Diff line change
@@ -73,6 +73,17 @@
"type": [ "string", "null" ],
"maxLength": 8,
"description": "Conditionally included with the NCAN document type as the unique document registration number for the unit note registration that has been cancelled."
},
"nonResidentialOther": {
"type": "string",
"maxLength": 125,
"description": "For EXNR document types where nonResidentialReason is OTHER, provide a brief reason description."
},
"nonResidentialReason": {
"type": "string",
"maxLength": 20,
"enum": ["BURNT", "DISMANTLED", "DILAPIDATED", "OFFICE", "STORAGE_SHED", "BUNKHOUSE", "OTHER"],
"description": "Only include and required for EXNR document types as the reason for the non-residential exemption."
}
},
"required": [
12 changes: 12 additions & 0 deletions src/registry_schemas/schemas/ppr/amendmentStatement.json
Original file line number Diff line number Diff line change
@@ -106,6 +106,18 @@
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/generalCollateral"
}
},
"deleteSecuritiesActNotices": {
"type": [ "array", "null" ],
"items": {
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActNotice"
}
},
"addSecuritiesActNotices": {
"type": [ "array", "null" ],
"items": {
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActNotice"
}
},
"createDateTime": {
"type": "string",
"format": "date-time",
2 changes: 1 addition & 1 deletion src/registry_schemas/schemas/ppr/draftSummary.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
},
"registrationType": {
"type": "string",
"enum": ["SA", "RL", "FR", "LT", "MH", "SG", "FL", "FA", "FS", "MR", "AM", "CO", "AC", "DR", "DT", "PD", "ST", "SU"],
"enum": ["SA", "RL", "FR", "LT", "MH", "SG", "FL", "FA", "FS", "MR", "AM", "CO", "AC", "DR", "DT", "PD", "ST", "SU", "SE"],
"description": "For a Financing Statement the draft type value. For a Change Statement and an Amendment Statement the changeType value."
},
"documentId": {
12 changes: 10 additions & 2 deletions src/registry_schemas/schemas/ppr/financingStatement.json
Original file line number Diff line number Diff line change
@@ -8,8 +8,10 @@
"type": {
"type": "string",
"maxLength": 2,
"enum": ["SA", "RL", "FR", "LT", "MH", "SG", "FL", "FA", "FS", "MR", "CC", "CT", "DP", "ET", "FO", "FT", "HR", "IP", "LO", "MI", "OT"
, "PG", "PS", "IT", "RA", "SS", "TL", "HN", "ML", "MN", "PN", "WL", "TF", "TA", "TG", "TM", "MD", "PT", "SC", "TO", "SV"],
"enum": ["SA", "RL", "FR", "LT", "MH", "SG", "FL", "FA", "FS", "MR", "CC", "CT", "DP", "ET", "FO", "FT"
, "HR", "IP", "LO", "MI", "OT"
, "PG", "PS", "IT", "RA", "SS", "TL", "HN", "ML", "MN", "PN", "WL", "TF", "TA", "TG", "TM", "MD", "PT"
, "SC", "TO", "SV", "SE"],
"description": "Specifies the type of Financing Statement. Includes all legacy registration types."
},
"clientReferenceId": {
@@ -92,6 +94,12 @@
"format": "date-time",
"description": "The date the vehicle was or will be surrendered to the owner in the ISO 8601 format YYYY-MM-DDThh:mm:ssTZD. When provided it must be within the past 21 days or a later date. Required when the type is RL, otherwise it should be absent."
},
"securitiesActNotices": {
"type": [ "array", "null" ],
"items": {
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActNotice"
}
},
"baseRegistrationNumber": {
"type": "string",
"minLength": 1,
2 changes: 1 addition & 1 deletion src/registry_schemas/schemas/ppr/searchSummary.json
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
"type": "string",
"maxLength": 2,
"enum": ["SA", "RL", "FR", "LT", "MH", "SG", "FL", "FA", "FS", "MR", "CC", "CT", "DP", "ET", "FO", "FT", "HR", "IP", "LO", "MI", "OT"
, "PG", "PS", "IT", "RA", "SS", "TL", "HN", "ML", "MN", "PN", "WL", "TF", "TA", "TG", "TM", "MD", "PT", "SC", "TO", "SV"],
, "PG", "PS", "IT", "RA", "SS", "TL", "HN", "ML", "MN", "PN", "WL", "TF", "TA", "TG", "TM", "MD", "PT", "SC", "TO", "SV", "SE"],
"description": "Specifies the type of Financing Statement. Includes all legacy registration types."
},
"debtor": {
39 changes: 39 additions & 0 deletions src/registry_schemas/schemas/ppr/securitiesActNotice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActNotice",
"type": "object",
"title": "The PPR Securities Act Notice Information Schema. Only used when the registration type is SE.",
"properties": {
"securitiesActNoticeType": {
"type": "string",
"maxLength": 20,
"enum": ["LIEN", "PRESERVATION", "PROCEEDINGS"],
"description": "Required, specifies the type of Securities Act Notice: lien, preservation order, or order of proceedings."
},
"effectiveDateTime": {
"type": "string",
"format": "date-time",
"description": "Optional, the timestamp the registration is effective. The default is the PPR system generated createDateTime. The format is ISO 8601 YYYY-MM-DDThh:mm:ssTZD."
},
"description": {
"type": [ "string", "null" ],
"maxLength": 4000,
"description": "A note explaining the purpose of the registration."
},
"securitiesActOrders": {
"type": [ "array", "null" ],
"items": {
"$ref": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActOrder"
}
},
"noticeId": {
"type": "integer",
"minimum": 1,
"description": "The unique identifier generated by the system for the notice record. Returned in the API responses to maintain Amendment registration changes to Securities Act Notices."
}
},
"required": [
"securitiesActNoticeType"
]
}
45 changes: 45 additions & 0 deletions src/registry_schemas/schemas/ppr/securitiesActOrder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://bcrs.gov.bc.ca/.well_known/schemas/ppr/securitiesActOrder",
"type": "object",
"title": "The PPR Securities Act Order Information Schema",
"properties": {
"courtName": {
"type": "string",
"minLength": 5,
"maxLength": 256,
"description": "The name of the court that issued the order."
},
"courtRegistry": {
"type": "string",
"minLength": 5,
"maxLength": 64,
"description": "The location of the court that issued the order. If someone needs to request a copy of the order, this is where they will find it."
},
"fileNumber": {
"type": "string",
"minLength": 5,
"maxLength": 20,
"description": "The court assigns each order a unique file number up to 20 characters in length."
},
"orderDate": {
"type": "string",
"description": "The date of the order as a timestamp in the ISO 8601 format YYYY-MM-DDThh:mm:ssTZD.",
"format": "date-time"
},
"effectOfOrder": {
"type": "string",
"minLength": 5,
"maxLength": 512,
"description": "A brief note to explain the purpose of the order."
},
"courtOrder": {
"type": "boolean",
"description": "True if the order is a court order, otherwise false (commission order)."
}
},
"required": [
"courtOrder"
]
}
2 changes: 1 addition & 1 deletion src/registry_schemas/version.py
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '1.8.9' # pylint: disable=invalid-name
__version__ = '1.8.10' # pylint: disable=invalid-name
2 changes: 2 additions & 0 deletions tests/unit/mhr/test_admin_registration.py
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@
('Valid request NRED', True, 'NRED', True, True, None, None),
('Valid request NCAN', True, 'NCAN', True, True, None, None),
('Valid request STAT', True, 'STAT', True, True, None, None),
('Valid request EXRE', True, 'EXRE', True, True, None, None),
('Valid request REREGISTER_C', True, 'REREGISTER_C', 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),
('Valid response', True, 'THAW', True, False, '1234', 'JOHN SMITH'),
24 changes: 24 additions & 0 deletions tests/unit/mhr/test_note.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@

# testdata pattern is ({desc},{valid},{type},{doc_id},{has_create},{has_expiry},{remarks},{contact_name},{address})
LONG_NAME = '012345678901234567890123456789012345678901234567890'
OTHER_MAX = '01234567890123456789012345678901234567890123456789' + \
'01234567890123456789012345678901234567890123456789' + '0123456789012345678901234'
TEST_DATA_NOTE = [
('Valid all', True, 'type', '123456', True, True, 'remarks', 'contact', ADDRESS),
('Valid no expiry', True, 'type', '123456', True, False, 'remarks', 'contact', ADDRESS),
@@ -38,6 +40,18 @@
('Invalid doc id too long', False, '1234', '123456789', True, True, 'remarks', 'contact', ADDRESS),
('Invalid contact too long', False, '1234', '123456', True, True, 'remarks', LONG_NAME, ADDRESS)
]
# testdata pattern is ({valid},{reason},{other})
TEST_DATA_NON_RES_REASON = [
(True, 'BURNT', None),
(True, 'DISMANTLED', None),
(True, 'DILAPIDATED', None),
(True, 'OFFICE', None),
(True, 'STORAGE_SHED', None),
(True, 'BUNKHOUSE', None),
(True, 'OTHER', OTHER_MAX),
(False, 'JUNK', None),
(False, 'OTHER', OTHER_MAX + 'X')
]


@pytest.mark.parametrize('desc,valid,type,doc_id,has_create,has_expiry,remarks,contact,address', TEST_DATA_NOTE)
@@ -81,3 +95,13 @@ def test_note(desc, valid, type, doc_id, has_create, has_expiry, remarks, contac
assert is_valid
else:
assert not is_valid


@pytest.mark.parametrize('valid,reason,other', TEST_DATA_NON_RES_REASON)
def test_non_res_reason(valid, reason, other):
"""Assert that non residential note properties are performing as expected."""
data = copy.deepcopy(NOTE)
data['documentType'] = 'EXNR'
data['nonResidentialReason'] = reason
if other:
data['nonResidentialOther'] = other
90 changes: 90 additions & 0 deletions tests/unit/ppr/test_amendment_statement.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,47 @@
from registry_schemas.example_data.ppr import AMENDMENT_STATEMENT


ADD_SECURITIES_ACT_ORDERS = [
{
'courtName': 'Supreme Court of British Columbia',
'courtRegistry': 'KAMLOOPS',
'fileNumber': 'BC123445',
'orderDate': '2024-02-02T00:00:00-08:00',
'effectOfOrder': 'Court Order to remove James Smith as debtor.',
'courtOrder': True
},
{
'courtName': 'British Columbia Court of Appeal',
'courtRegistry': 'Vancouver',
'fileNumber': 'BCA123445',
'orderDate': '2024-02-02T00:00:00-08:00',
'effectOfOrder': 'Court Order to remove James Smith as debtor.',
'courtOrder': True
}
]
DELETE_SECURITIES_ACT_ORDERS = [
{
'courtName': 'Supreme Court of British Columbia.',
'courtRegistry': 'KAMLOOPS',
'fileNumber': 'BC123445',
'orderDate': '2024-02-02T00:00:00-08:00',
'effectOfOrder': 'Court Order to remove James Smith as debtor.',
'courtOrder': True
}
]
DELETE_SECURITIES_ACT_NOTICE = {
'noticeId': 1,
'securitiesActNoticeType': 'LIEN',
'effectiveDateTime': '2024-02-02T00:00:00-08:00',
'description': 'TEST DELETE LIEN NOTICE TYPE',
'securitiesActOrders': DELETE_SECURITIES_ACT_ORDERS
}
ADD_SECURITIES_ACT_NOTICE = {
'securitiesActNoticeType': 'LIEN',
'effectiveDateTime': '2024-04-12T00:00:00-08:00',
'description': 'TEST ADD LIEN NOTICE TYPE',
'securitiesActOrders': ADD_SECURITIES_ACT_ORDERS
}
# testdata pattern is ({change type}, {is valid})
TEST_DATA_CHANGE_TYPE = [
('AM', True),
@@ -31,6 +72,55 @@
('AU', True),
('XX', False)
]
# testdata pattern is ({desc}, {valid}, {add}, {delete}, {add_order}, {delete_order)
TEST_DATA_SEC_ACT = [
('Valid no notice changes', True, None, None, False, False),
('Valid add court order(s)', True, ADD_SECURITIES_ACT_NOTICE, None, True, False),
('Valid delete court order(s)', True, None, DELETE_SECURITIES_ACT_NOTICE, False, True),
('Valid change court orders', True, ADD_SECURITIES_ACT_NOTICE, DELETE_SECURITIES_ACT_NOTICE, True, True),
('Invalid add missing notice type', False, ADD_SECURITIES_ACT_NOTICE, None, True, False),
('Invalid add missing courtOrder', False, ADD_SECURITIES_ACT_NOTICE, None, True, False)
]


@pytest.mark.parametrize('desc,valid,add,delete,add_order,delete_order', TEST_DATA_SEC_ACT)
def test_sec_act_amendment(desc, valid, add, delete, add_order, delete_order):
"""Assert that the schema is performing as expected when amending a securities act base registration."""
statement = copy.deepcopy(AMENDMENT_STATEMENT)
statement['changeType'] = 'AM'
del statement['courtOrderInformation']
del statement['createDateTime']
del statement['amendmentRegistrationNumber']
del statement['payment']
add_notice = None
delete_notice = None
if add:
add_notice = copy.deepcopy(add)
if not add_order:
del add_notice['securitiesActOrders']
if delete:
delete_notice = copy.deepcopy(delete)
if not delete_order:
del delete_notice['securitiesActOrders']
if desc == 'Invalid add missing notice type':
del add_notice['securitiesActNoticeType']
elif desc == 'Invalid add missing courtOrder':
del add_notice['securitiesActOrders'][0]['courtOrder']
if add_notice:
statement['addSecuritiesActNotices'] = [add_notice]
if delete_notice:
statement['deleteSecuritiesActNotices'] = [delete_notice]

is_valid, errors = validate(statement, 'amendmentStatement', 'ppr')

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

if valid:
assert is_valid
else:
assert not is_valid


@pytest.mark.parametrize('change_type, valid', TEST_DATA_CHANGE_TYPE)
71 changes: 71 additions & 0 deletions tests/unit/ppr/test_financing_statement.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,22 @@
from registry_schemas.example_data.ppr import FINANCING_STATEMENT


SECURITIES_ACT_ORDERS = [
{
'courtName': 'Supreme Court of British Columbia.',
'courtRegistry': 'KAMLOOPS',
'fileNumber': 'BC123445',
'orderDate': '2024-02-02T00:00:00-08:00',
'effectOfOrder': 'Court Order to remove James Smith as debtor.',
'courtOrder': True
}
]
SECURITIES_ACT_NOTICE = {
'securitiesActNoticeType': 'LIEN',
'effectiveDateTime': '2024-02-02T00:00:00-08:00',
'description': 'TEST LIEN NOTICE TYPE',
'securitiesActOrders': SECURITIES_ACT_ORDERS
}
# testdata pattern is ({registration type}, {is valid})
TEST_DATA_REG_TYPE = [
('CC', True),
@@ -63,13 +79,68 @@
('SC', True),
('SV', True),
('TO', True),
('SE', True),
('XX', False),
]
# testdata pattern is ({other type description}, {is valid})
TEST_DATA_OT = [
('0123456789012345678901234567890123456789012345678901234567890123456789', True),
('01234567890123456789012345678901234567890123456789012345678901234567890', False),
]
# testdata pattern is ({desc}, {valid}, {reg_type}, {sec_type}, {has_orders}, {court_order})
TEST_DATA_SEC_ACT = [
('Valid LIEN', True, 'SE', 'LIEN', False, None),
('Valid PRESERVATION', True, 'SE', 'PRESERVATION', True, True),
('Valid PROCEEDINGS', True, 'SE', 'PROCEEDINGS', False, None),
('Invalid order', False, 'SE', 'PROCEEDINGS', True, None),
('Invalid SA type', False, 'SE', 'JUNK', False, None),
('Invalid missing SA type', False, 'SE', None, False, None),
('Invalid debtor name', False, 'SE', 'LIEN', False, None),
('Invalid secured name', False, 'SE', 'LIEN', False, None),
('Invalid missing collateral', False, 'SE', 'LIEN', False, None)
]


@pytest.mark.parametrize('desc,valid,reg_type,sec_type,has_orders,court_order', TEST_DATA_SEC_ACT)
def test_financing_sec_act(desc, valid, reg_type, sec_type, has_orders, court_order):
"""Assert the validation of a security act registration works as expected."""
statement = copy.deepcopy(FINANCING_STATEMENT)
statement['type'] = reg_type
statement['lifeInfinite'] = True
del statement['trustIndenture']
del statement['lienAmount']
del statement['surrenderDate']
del statement['createDateTime']
del statement['baseRegistrationNumber']
del statement['payment']
del statement['lifeYears']
notice = copy.deepcopy(SECURITIES_ACT_NOTICE)
if not sec_type:
del notice['securitiesActNoticeType']
else:
notice['securitiesActNoticeType'] = sec_type
if not has_orders:
del notice['securitiesActOrders']
elif not court_order:
del notice['securitiesActOrders'][0]['courtOrder']
statement['securitiesActNotices'] = [notice]
if desc == 'Invalid debtor name':
del statement['debtors'][0]['businessName']
elif desc == 'Invalid secured name':
del statement['securedParties'][0]['businessName']
elif desc == 'Invalid missing collateral':
del statement['vehicleCollateral']
del statement['generalCollateral']

is_valid, errors = validate(statement, 'financingStatement', 'ppr')

if errors:
for err in errors:
print(err.message)
if valid:
assert is_valid
else:
assert not is_valid


@pytest.mark.parametrize('registration_type, valid', TEST_DATA_REG_TYPE)
1 change: 1 addition & 0 deletions tests/unit/ppr/test_search_summary.py
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
('TL', True),
('TM', True),
('WL', True),
('SE', True),
('XX', False),
]

73 changes: 73 additions & 0 deletions tests/unit/ppr/test_securities_act_notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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 securities act notice information schema is valid."""
import copy

import pytest

from registry_schemas import validate
from registry_schemas.example_data.ppr import COURT_ORDER


SECURITIES_ACT_NOTICE = {
'securitiesActNoticeType': 'LIEN',
'effectiveDateTime': '2024-02-02T00:00:00-08:00',
'description': 'TEST LIEN NOTICE TYPE'
}


# testdata pattern is ({desc}, {valid}, {sec_type}, {effective_dt}, {has_orders}, {court_order})
TEST_DATA = [
('Valid LIEN', True, 'LIEN', '2024-04-12T06:59:59-07:00', True, True),
('Valid PRESERVATION', True, 'PRESERVATION', '2024-04-12T06:59:59-07:00', False, None),
('Valid PROCEEDINGS', True, 'PROCEEDINGS', '2024-04-12T06:59:59-07:00', True, True),
('Valid LIEN minimal', True, 'LIEN', None, False, None),
('Invalid notice type', False, 'JUNK', '2024-04-12T06:59:59-07:00', True, True),
('Invalid no notice type', False, None, '2024-04-12T06:59:59-07:00', True, True),
('Invalid missing courtOrder', False, 'LIEN', None, True, None)
]


@pytest.mark.parametrize('desc,valid,sec_type,effective_dt,has_orders,court_order', TEST_DATA)
def test_securities_act_notice(desc, valid, sec_type, effective_dt, has_orders, court_order):
"""Assert that the schema is performing as expected."""
notice = copy.deepcopy(SECURITIES_ACT_NOTICE)
if has_orders:
orders = []
order = copy.deepcopy(COURT_ORDER)
if court_order:
order['courtOrder'] = court_order
orders.append(order)
notice['securitiesActOrders'] = orders

if not sec_type:
del notice['securitiesActNoticeType']
else:
notice['securitiesActNoticeType'] = sec_type
if not effective_dt:
del notice['effectiveDateTime']
else:
notice['effectiveDateTime'] = effective_dt

is_valid, errors = validate(notice, 'securitiesActNotice', 'ppr')

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

if valid:
assert is_valid
else:
assert not is_valid
72 changes: 72 additions & 0 deletions tests/unit/ppr/test_securities_act_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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 securities act order information schema is valid."""
import copy

import pytest

from registry_schemas import validate
from registry_schemas.example_data.ppr import COURT_ORDER


# testdata pattern is ({desc}, {valid}, {name}, {registry}, {file_num}, {order_date}, {effect}, {court_order})
TEST_DATA = [
('Valid', True, 'default', 'default', 'default', 'default', 'default', True),
('Valid minimal', True, None, None, None, None, None, True),
('Invalid no court_order', False, 'default', 'default', 'default', 'default', 'default', None),
('Invalid name', False, 'XX', 'default', 'default', 'default', 'default', False),
('Invalid registry', False, 'default', 'XX', 'default', 'default', 'default', False),
('Invalid file number', False, 'default', 'default', 'FILE NUMBER TOO LONGXXXX', 'default', 'default', False),
('Invalid effect of order', False, 'default', 'default', 'default', 'default', 'XX', False)
]


@pytest.mark.parametrize('desc,valid,name,registry,file_num,order_date,effect,court_order', TEST_DATA)
def test_securities_act_order(desc, valid, name, registry, file_num, order_date, effect, court_order):
"""Assert that the schema is performing as expected."""
order = copy.deepcopy(COURT_ORDER)
if name and name != 'default':
order['courtName'] = name
elif not name:
del order['courtName']
if registry and registry != 'default':
order['courtRegistry'] = registry
elif not registry:
del order['courtRegistry']
if file_num and file_num != 'default':
order['fileNumber'] = file_num
elif not file_num:
del order['fileNumber']
if order_date and order_date != 'default':
order['orderDate'] = order_date
elif not order_date:
del order['orderDate']
if effect and effect != 'default':
order['effectOfOrder'] = effect
elif not effect:
del order['effectOfOrder']
if court_order is not None:
order['courtOrder'] = court_order

is_valid, errors = validate(order, 'securitiesActOrder', 'ppr')

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

if valid:
assert is_valid
else:
assert not is_valid