Exemplo n.º 1
0
def test_amendment_collateral_id_invalid(session):
    """Assert that the amendment statement json with an invalid delete general collateral ID validates correctly."""
    registration = Registration.find_by_id(200000008)
    assert registration

    json_data = registration.json
    del json_data['createDateTime']
    del json_data['amendmentRegistrationNumber']
    del json_data['addGeneralCollateral']
    del json_data['addVehicleCollateral']
    del json_data['deleteVehicleCollateral']
    del json_data['addDebtors']
    del json_data['addSecuredParties']
    del json_data['deleteDebtors']
    del json_data['deleteSecuredParties']
    json_data['deleteGeneralCollateral'][0]['collateralId'] = 300000000

    financing_statement = FinancingStatement.find_by_financing_id(200000000)
    with pytest.raises(BusinessException) as bad_request_err:
        Registration.create_from_json(json_data, 'AMENDMENT',
                                      financing_statement, 'TEST0001',
                                      'PS12345')

    # check
    assert bad_request_err
    assert bad_request_err.value.status_code == HTTPStatus.BAD_REQUEST
    print(bad_request_err.value.error)
Exemplo n.º 2
0
def test_find_by_id_as(session):
    """Assert that find an amemdment registration by ID contains all expected elements."""
    registration = Registration.find_by_id(200000008)
    assert registration
    assert registration.registration_id == 200000008
    assert registration.registration_num
    assert registration.registration_type_cd == 'CO'
    assert registration.financing_id
    json_data = registration.json
    assert json_data['changeType'] == 'CO'
    assert json_data['courtOrderInformation']
    assert json_data['addDebtors']
    assert len(json_data['addDebtors']) == 1
    assert json_data['addSecuredParties']
    assert len(json_data['addSecuredParties']) == 1
    assert json_data['addGeneralCollateral']
    assert len(json_data['addGeneralCollateral']) == 1
    assert json_data['addVehicleCollateral']
    assert len(json_data['addVehicleCollateral']) == 1
    assert json_data['deleteDebtors']
    assert len(json_data['deleteDebtors']) == 1
    assert json_data['deleteSecuredParties']
    assert len(json_data['deleteSecuredParties']) == 1
    assert json_data['deleteGeneralCollateral']
    assert len(json_data['deleteGeneralCollateral']) == 1
    assert json_data['deleteVehicleCollateral']
    assert len(json_data['deleteVehicleCollateral']) == 1
    assert 'documentId' not in json_data
Exemplo n.º 3
0
def test_save_renewal_rl(session):
    """Assert that creating a renewal statement on a RL financing statement contains all expected elements."""
    json_data = copy.deepcopy(RENEWAL_STATEMENT)
    del json_data['createDateTime']
    del json_data['renewalRegistrationNumber']
    del json_data['payment']
    del json_data['expiryDate']

    financing_statement = FinancingStatement.find_by_financing_id(200000001)
    assert financing_statement

    registration = Registration.create_from_json(json_data, 'RENEWAL',
                                                 financing_statement,
                                                 'TEST0002', 'PS12345')
    #    print(registration.financing_id)
    #    print(registration.json)
    registration.save()
    assert registration.financing_id == 200000001
    assert registration.registration_id
    assert registration.registration_num
    assert registration.registration_type_cd
    assert registration.registration_ts
    assert registration.account_id
    assert registration.client_reference_id

    result = registration.json
    assert result
    assert result['baseRegistrationNumber']
    assert result['renewalRegistrationNumber']
    assert result['createDateTime']
    assert result['registeringParty']
    assert result['courtOrderInformation']
Exemplo n.º 4
0
def test_save_discharge(session):
    """Assert that creating a discharge statement contains all expected elements."""
    json_data = copy.deepcopy(DISCHARGE_STATEMENT)
    del json_data['createDateTime']
    del json_data['dischargeRegistrationNumber']
    del json_data['payment']

    financing_statement = FinancingStatement.find_by_financing_id(200000003)
    assert financing_statement

    registration = Registration.create_from_json(json_data, 'DISCHARGE',
                                                 financing_statement,
                                                 'TEST0003', 'PS12345')
    print(str(registration.registration_id))
    print(registration.document_number)
    print(registration.registration_num)
    #    print(registration.json)
    registration.save()
    assert registration.financing_id == 200000003
    assert registration.registration_id
    assert registration.registration_num
    assert registration.registration_type_cd
    assert registration.registration_ts
    assert registration.account_id
    assert registration.client_reference_id

    result = registration.json
    assert result
    assert result['baseRegistrationNumber']
    assert result['dischargeRegistrationNumber']
    assert result['createDateTime']
    assert result['registeringParty']
Exemplo n.º 5
0
def test_find_by_id(session):
    """Assert that find registration by ID contains all expected elements."""
    registration = Registration.find_by_id(200000000)
    assert registration
    assert registration.registration_id == 200000000
    assert registration.registration_num == 'TEST0001'
    assert registration.registration_type_cd
    assert registration.registration_ts
    assert registration.account_id
    assert registration.client_reference_id
Exemplo n.º 6
0
def test_find_by_registration_num_fs(session):
    """Assert that find a financing statement by registration number contains all expected elements."""
    registration = Registration.find_by_registration_number('TEST0001')
    assert registration
    assert registration.registration_id == 200000000
    assert registration.registration_num == 'TEST0001'
    assert registration.registration_type_cd
    assert registration.registration_ts
    assert registration.account_id
    assert registration.client_reference_id
Exemplo n.º 7
0
def test_renewal_client_code_invalid(session):
    """Assert that the renewal statement json with an invalid RP client code validates correctly."""
    json_data = copy.deepcopy(RENEWAL_STATEMENT)
    del json_data['createDateTime']
    del json_data['renewalRegistrationNumber']
    del json_data['payment']
    del json_data['courtOrderInformation']
    del json_data['registeringParty']
    party = {'code': '900000000'}
    json_data['registeringParty'] = party

    financing_statement = FinancingStatement.find_by_financing_id(200000004)
    assert financing_statement

    with pytest.raises(BusinessException) as bad_request_err:
        Registration.create_from_json(json_data, 'RS', financing_statement,
                                      'TEST0001', 'PS12345')

    # check
    assert bad_request_err
    assert bad_request_err.value.status_code == HTTPStatus.BAD_REQUEST
    print(bad_request_err.value.error)
Exemplo n.º 8
0
    def post(registration_num):
        """Renew a financing statement by registration number."""
        try:
            if registration_num is None:
                return path_param_error_response('registration number')

            # 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, 'renewalStatement', 'ppr')
            if not valid_format:
                return validation_error_response(errors, VAL_ERROR_RENEWAL)

            # payload base registration number must match path registration number
            if registration_num != request_json['baseRegistrationNumber']:
                return path_data_mismatch_error_response(registration_num,
                                                         'base registration number',
                                                         request_json['baseRegistrationNumber'])

            # Fetch base registration information: business exception thrown if not
            # found or historical.
            statement = FinancingStatement.find_by_registration_number(registration_num, False)

            # Verify base debtor (bypassed for staff)
            if not statement.validate_base_debtor(request_json['baseDebtor'], is_staff(jwt)):
                return base_debtor_invalid_response()

            # TODO: charge a fee.

            # Try to save the renewal statement: failure throws a business exception.
            statement = Registration.create_from_json(request_json,
                                                      model_utils.REG_CLASS_RENEWAL,
                                                      statement,
                                                      registration_num,
                                                      account_id)
            statement.save()

            return statement.json, HTTPStatus.OK

        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)
Exemplo n.º 9
0
def test_save_amendment(session):
    """Assert that creating an amendment statement on a non-RL financing statement contains all expected elements."""
    json_data = copy.deepcopy(AMENDMENT_STATEMENT)
    del json_data['createDateTime']
    del json_data['amendmentRegistrationNumber']
    del json_data['payment']
    del json_data['documentId']
    json_data['changeType'] = 'CO'

    financing_statement = FinancingStatement.find_by_financing_id(200000000)
    assert financing_statement
    for party in financing_statement.parties:
        if party.registration_id != 200000000 and not party.registration_id_end:
            if party.party_type_cd == 'DB' or party.party_type_cd == 'DI':
                json_data['deleteDebtors'][0]['partyId'] = party.party_id
            elif party.party_type_cd == 'SP':
                json_data['deleteSecuredParties'][0][
                    'partyId'] = party.party_id

    for gc in financing_statement.general_collateral:
        if gc.registration_id != 200000000 and not gc.registration_id_end:
            json_data['deleteGeneralCollateral'][0][
                'collateralId'] = gc.collateral_id

    for vc in financing_statement.vehicle_collateral:
        if vc.registration_id != 200000000 and not vc.registration_id_end:
            json_data['deleteVehicleCollateral'][0][
                'vehicleId'] = vc.vehicle_id

    registration = Registration.create_from_json(json_data, 'AMENDMENT',
                                                 financing_statement,
                                                 'TEST0001', 'PS12345')
    #    print(registration.financing_id)
    #    print(registration.json)
    registration.save()
    result = registration.json
    assert result
    assert result['baseRegistrationNumber']
    assert result['amendmentRegistrationNumber']
    assert result['createDateTime']
    assert result['registeringParty']
    assert result['courtOrderInformation']
    assert result['addDebtors']
    assert result['deleteDebtors']
    assert result['addSecuredParties']
    assert result['deleteSecuredParties']
    assert result['addGeneralCollateral']
    assert result['deleteGeneralCollateral']
    assert result['addVehicleCollateral']
    assert result['deleteVehicleCollateral']
    assert 'documentId' not in result
Exemplo n.º 10
0
def test_get_payment_details_registration(session, client, jwt):
    """Assert that a valid renewal request payment details setup works as expected."""
    # setup
    json_data = copy.deepcopy(STATEMENT_VALID)
    registration_num = 'TEST0001'
    statement = FinancingStatement.find_by_registration_number(
        registration_num, False)
    registration = Registration.create_from_json(json_data, 'RENEWAL',
                                                 statement, registration_num,
                                                 'PS12345')
    # test
    details = get_payment_details(registration)

    # check
    assert details
    assert details['label'] == 'Renew Registration:'
    assert details['value'].startswith('TEST0001 for ')
Exemplo n.º 11
0
def test_find_by_registration_num_ds(session):
    """Assert that find a discharge statement by registration number contains all expected elements."""
    registration = Registration.find_by_registration_number('TEST00D4')
    assert registration
    assert registration.registration_id == 200000004
    assert registration.registration_num == 'TEST00D4'
    assert registration.registration_type_cd == 'DC'
    assert registration.registration_ts
    assert registration.account_id
    assert registration.client_reference_id
    assert registration.parties
    assert len(registration.parties) == 1
    assert registration.financing_statement

    json_data = registration.json
    assert json_data['dischargeRegistrationNumber']
    assert json_data['createDateTime']
    assert json_data['registeringParty']
Exemplo n.º 12
0
def test_save_amendment_from_draft(session):
    """Assert that creating an amendment statement from a draft on a non-RL financing statement.

    Verify it contains all expected elements.
    """
    json_data = copy.deepcopy(AMENDMENT_STATEMENT)
    del json_data['createDateTime']
    del json_data['amendmentRegistrationNumber']
    del json_data['payment']

    financing_statement = FinancingStatement.find_by_financing_id(200000000)
    assert financing_statement
    for party in financing_statement.parties:
        if party.registration_id != 200000000 and not party.registration_id_end:
            if party.party_type_cd == 'DB' or party.party_type_cd == 'DI':
                json_data['deleteDebtors'][0]['partyId'] = party.party_id
            elif party.party_type_cd == 'SP':
                json_data['deleteSecuredParties'][0][
                    'partyId'] = party.party_id

    for gc in financing_statement.general_collateral:
        if gc.registration_id != 200000000 and not gc.registration_id_end:
            json_data['deleteGeneralCollateral'][0][
                'collateralId'] = gc.collateral_id

    for vc in financing_statement.vehicle_collateral:
        if vc.registration_id != 200000000 and not vc.registration_id_end:
            json_data['deleteVehicleCollateral'][0][
                'vehicleId'] = vc.vehicle_id

    # Now create a draft amendment
    draft_json = copy.deepcopy(DRAFT_AMENDMENT_STATEMENT)
    draft = Draft.create_from_json(draft_json, 'PS12345')
    draft.save()
    assert draft.document_number
    json_data['documentId'] = draft.document_number
    registration = Registration.create_from_json(json_data, 'AMENDMENT',
                                                 financing_statement,
                                                 'TEST0001', 'PS12345')
    registration.save()
    assert registration.draft
    result = registration.json
    assert result
Exemplo n.º 13
0
def test_find_by_id_cs_st(session):
    """Assert that find an change registration ST by ID contains all expected elements."""
    registration = Registration.find_by_id(200000010)
    assert registration
    assert registration.registration_id == 200000010
    assert registration.registration_num
    assert registration.registration_type_cd == 'ST'
    assert registration.financing_id
    json_data = registration.json
    assert json_data['changeType'] == 'ST'
    assert json_data['addSecuredParties']
    assert len(json_data['addSecuredParties']) == 1
    assert json_data['deleteSecuredParties']
    assert len(json_data['deleteSecuredParties']) == 1
    assert 'addDebtors' not in json_data
    assert 'addGeneralCollateral' not in json_data
    assert 'addVehicleCollateral' not in json_data
    assert 'deleteDebtors' not in json_data
    assert 'deleteGeneralCollateral' not in json_data
    assert 'deleteVehicleCollateral' not in json_data
Exemplo n.º 14
0
def test_get_payment_details(session, client, jwt, reg_type, reg_class,
                             reg_num, label, value, life):
    """Assert that a valid registration statement request payment details setup works as expected."""
    # setup
    registration = Registration()
    registration.base_registration_num = reg_num
    registration.registration_type = reg_type
    registration.registration_type_cl = reg_class
    registration.life = life
    # test
    details = get_payment_details(registration)

    # check
    assert details
    assert details['label'] == label
    assert details['value'] == value
Exemplo n.º 15
0
def test_find_by_reg_num_invalid(session):
    """Assert that find registration by non-existent registration number returns the expected result."""
    registration = Registration.find_by_registration_number('100000234')
    assert not registration
Exemplo n.º 16
0
def test_find_by_id_invalid(session):
    """Assert that find registration by non-existent ID returns the expected result."""
    registration = Registration.find_by_id(100000234)
    assert not registration