def test_life_expiry(session, reg_type, life, life_infinite, expected_life): """Assert that creating a financing statment with different registration types sets life and expiry as expected.""" json_data = copy.deepcopy(FINANCING_STATEMENT) json_data['type'] = reg_type if life is None: del json_data['lifeYears'] else: json_data['lifeYears'] = life json_data['lifeInfinite'] = life_infinite if reg_type == model_utils.REG_TYPE_OTHER: json_data['otherTypeDescription'] = 'TEST OTHER DESC' statement = FinancingStatement.create_from_json(json_data, 'PS12345', 'TESTID') assert statement.life == expected_life if statement.life != model_utils.LIFE_INFINITE: assert statement.expire_date if reg_type == model_utils.REG_TYPE_REPAIRER_LIEN: expire_date = model_utils.expiry_dt_repairer_lien() assert model_utils.format_ts( statement.expire_date) == model_utils.format_ts(expire_date) else: expire_date = model_utils.expiry_dt_from_years(statement.life) assert model_utils.format_ts( statement.expire_date) == model_utils.format_ts(expire_date) else: assert statement.expire_date is None if reg_type == model_utils.REG_TYPE_OTHER: assert statement.crown_charge_other == 'TEST OTHER DESC'
def post(): """Create a new financing statement.""" try: # Quick check: must be staff or provide an account ID. account_id = get_account_id(request) if not is_staff(jwt) and account_id is None: return account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return unauthorized_error_response(account_id) request_json = request.get_json(silent=True) # Validate request data against the schema. valid_format, errors = schema_utils.validate(request_json, 'financingStatement', 'ppr') if not valid_format: return validation_error_response(errors, VAL_ERROR) # TODO: charge a fee. # Try to save the financing statement: failure throws a business exception. statement = FinancingStatement.create_from_json(request_json, account_id) statement.save() return statement.json, HTTPStatus.CREATED except BusinessException as exception: return business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return default_exception_response(default_exception)
def test_financing_client_code_invalid(session): """Assert that the financing statement json with an invalid RP client code validates correctly.""" json_data = copy.deepcopy(FINANCING_STATEMENT) del json_data['createDateTime'] del json_data['baseRegistrationNumber'] del json_data['payment'] del json_data['lifeInfinite'] del json_data['trustIndenture'] del json_data['generalCollateral'] del json_data['expiryDate'] del json_data['registeringParty'] del json_data['documentId'] party = {'code': '900000000'} sp = {'code': '900000001'} json_data['registeringParty'] = party json_data['securedParties'].append(sp) with pytest.raises(BusinessException) as bad_request_err: FinancingStatement.create_from_json(json_data, 'PS12345') # check assert bad_request_err assert bad_request_err.value.status_code == HTTPStatus.BAD_REQUEST print(bad_request_err.value.error)
def test_save(session, reg_type, account_id, create_draft): """Assert that saveing a valid financing statement works as expected.""" json_data = copy.deepcopy(FINANCING_STATEMENT) json_data['type'] = reg_type del json_data['createDateTime'] del json_data['baseRegistrationNumber'] del json_data['payment'] del json_data['lifeInfinite'] del json_data['expiryDate'] del json_data['documentId'] if reg_type != model_utils.REG_TYPE_REPAIRER_LIEN: del json_data['lienAmount'] del json_data['surrenderDate'] if reg_type != model_utils.REG_TYPE_SECURITY_AGREEMENT: del json_data['trustIndenture'] del json_data['generalCollateral'] if reg_type == model_utils.REG_TYPE_OTHER: json_data['otherTypeDescription'] = 'TEST OTHER DESC' if create_draft: draft_json = copy.deepcopy(DRAFT_FINANCING_STATEMENT) draft = Draft.create_from_json(draft_json, account_id) draft.save() assert draft.document_number json_data['documentId'] = draft.document_number statement = FinancingStatement.create_from_json(json_data, account_id, 'UNIT_TEST') statement.save() assert statement.id assert statement.registration[0].account_id == account_id assert statement.registration[0].user_id == 'UNIT_TEST' result = statement.json assert result assert result['baseRegistrationNumber'] assert result['registrationDescription'] assert result['registrationAct'] assert result['createDateTime'] assert result['registeringParty'] assert result['debtors'][0] assert result['securedParties'][0] assert result['vehicleCollateral'][0] if reg_type == model_utils.REG_TYPE_SECURITY_AGREEMENT: assert result['generalCollateral'][0] assert 'documentId' not in result if reg_type == model_utils.REG_TYPE_OTHER: assert result['otherTypeDescription'] == 'TEST OTHER DESC'
def test_get_payment_type_financing(session, client, jwt, reg_type, life_years, quantity, pay_trans_type): """Assert that a valid financing statement request payment transaction type setup works as expected.""" # setup json = copy.deepcopy(FINANCING_VALID) json['type'] = reg_type if life_years == 99: json['lifeYears'] = 1 json['lifeInfinite'] = True else: json['lifeYears'] = life_years statement = FinancingStatement.create_from_json(json, 'PS12345') pay_type, pay_quantity = get_payment_type_financing( statement.registration[0]) assert pay_type assert pay_quantity assert pay_type == pay_trans_type assert pay_quantity == quantity
def test_get_payment_details_financing(session, client, jwt, reg_type, reg_num, detail_desc, life): """Assert that a valid financing statement request payment details setup works as expected.""" # setup json_data = copy.deepcopy(FINANCING_VALID) json_data['type'] = reg_type json_data['lifeYears'] = life statement = FinancingStatement.create_from_json(json_data, 'PS12345', 'TESTID') statement.registration[0].registration_num = reg_num # test details = get_payment_details_financing(statement.registration[0]) # check # print(details) assert details assert details[ 'label'] == 'Register Financing Statement ' + reg_num + ' Type:' assert details['value'] == detail_desc
def test_save(session, reg_type, account_id, create_draft): """Assert that saveing a valid financing statement works as expected.""" json_data = copy.deepcopy(FINANCING_STATEMENT) json_data['type'] = reg_type del json_data['createDateTime'] del json_data['baseRegistrationNumber'] del json_data['payment'] del json_data['lifeInfinite'] del json_data['expiryDate'] del json_data['documentId'] if reg_type != 'RL': del json_data['lienAmount'] del json_data['surrenderDate'] if reg_type != 'SA': del json_data['trustIndenture'] del json_data['generalCollateral'] if create_draft: draft_json = copy.deepcopy(DRAFT_FINANCING_STATEMENT) draft = Draft.create_from_json(draft_json, account_id) draft.save() assert draft.document_number json_data['documentId'] = draft.document_number statement = FinancingStatement.create_from_json(json_data, account_id) statement.save() assert statement.financing_id result = statement.json assert result assert result['baseRegistrationNumber'] assert result['registrationDescription'] assert result['registrationAct'] assert result['createDateTime'] assert result['registeringParty'] assert result['debtors'][0] assert result['securedParties'][0] assert result['vehicleCollateral'][0] if reg_type == 'SA': assert result['generalCollateral'][0] assert 'documentId' not in result