Exemplo n.º 1
0
def test_find_by_registration_number(session, desc, reg_number, account_id,
                                     status, staff, create):
    """Assert that a fetch financing statement by registration number works as expected."""
    if status == HTTPStatus.OK:
        statement = FinancingStatement.find_by_registration_number(
            reg_number, account_id, staff, create)
        assert statement
        result = statement.json
        assert result['type'] == 'SA'
        assert result['baseRegistrationNumber'] == reg_number
        assert result['registeringParty']
        assert result['createDateTime']
        assert result['debtors'][0]
        assert result['securedParties'][0]
        if reg_number == 'TEST0001':
            assert result['vehicleCollateral'][0]
        assert result['expiryDate']
        assert result['lifeYears']
        if reg_number == 'TEST0001':
            assert result['generalCollateral'][0]
            assert result['trustIndenture']
        if statement.current_view_json and reg_number == 'TEST0001':
            assert result['courtOrderInformation']
    else:
        with pytest.raises(BusinessException) as request_err:
            FinancingStatement.find_by_registration_number(
                reg_number, account_id, staff, create)

        # check
        assert request_err
        assert request_err.value.status_code == status
Exemplo n.º 2
0
def test_find_by_registration_number_historical(session):
    """Assert that a fetch a discharged financing statement on a valid registration number works as expected."""
    with pytest.raises(BusinessException) as historical_err:
        FinancingStatement.find_by_registration_number('TEST0003', False)

    # check
    assert historical_err
    assert historical_err.value.status_code == HTTPStatus.BAD_REQUEST
Exemplo n.º 3
0
def test_find_by_registration_number_invalid(session):
    """Assert that a fetch financing statement on a non-existent registration number works as expected."""
    with pytest.raises(BusinessException) as not_found_err:
        FinancingStatement.find_by_registration_number('X12345X', False)

    # check
    assert not_found_err
    assert not_found_err.value.status_code == HTTPStatus.NOT_FOUND
Exemplo n.º 4
0
def test_validate_base_debtor(session):
    """Assert that base debtor check on an existing registration works as expected."""
    json_data = copy.deepcopy(DISCHARGE_STATEMENT)
    json_data['baseDebtor']['businessName'] = 'TEST BUS 2 DEBTOR'

    #    statement = FinancingStatement.find_by_financing_id(200000000)
    statement = FinancingStatement.find_by_registration_number(
        'TEST0001', False)
    assert statement

    # valid business name
    valid = statement.validate_base_debtor(json_data['baseDebtor'], False)
    assert valid

    # invalid business name
    json_data['baseDebtor']['businessName'] = 'xxx debtor'
    valid = statement.validate_base_debtor(json_data['baseDebtor'], False)
    assert not valid

    # invalid individual name
    person = {'last': 'Debtor', 'first': 'Test ind', 'middle': '1'}
    del json_data['baseDebtor']['businessName']
    json_data['baseDebtor']['personName'] = person
    valid = statement.validate_base_debtor(json_data['baseDebtor'], False)
    assert not valid

    # invalid individual name
    json_data['baseDebtor']['personName']['first'] = 'John'
    valid = statement.validate_base_debtor(json_data['baseDebtor'], False)
    assert not valid
Exemplo n.º 5
0
    def get(registration_num):
        """Get 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)

            # Try to fetch financing statement by registration number
            # Not found or non-staff historical throws a business exception.
            statement = FinancingStatement.find_by_registration_number(registration_num,
                                                                       is_staff(jwt))
            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.º 6
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.º 7
0
def test_renewal_expiry(session, reg_num, reg_type, expiry_ts, renewal2_ts,
                        renewal1_ts):
    """Assert that a financing statement with renewal history returns the expected expiry dates."""
    statement = FinancingStatement.find_by_registration_number(
        reg_num, 'PS12345', True)
    statement.include_changes_json = True
    json_data = statement.json
    # print(json_data)
    assert 'expiryDate' in json_data
    assert json_data['expiryDate'] == expiry_ts
    assert 'changes' in json_data
    assert len(json_data['changes']) == 2
    assert json_data['changes'][0]['expiryDate'] == renewal1_ts
    assert json_data['changes'][1]['expiryDate'] == renewal2_ts
Exemplo n.º 8
0
def test_validate_renewal(session, base_reg_num, json_data, valid,
                          message_content):
    """Assert that renewal registration extra validation works as expected."""
    # setup
    statement = FinancingStatement.find_by_registration_number(
        base_reg_num, 'PS12345')
    if base_reg_num == 'TEST0012':
        statement.life = model_utils.LIFE_INFINITE
    # test
    error_msg = validator.validate_renewal(json_data, statement)
    if valid:
        assert error_msg == ''
    elif message_content:
        assert error_msg != ''
        assert error_msg.find(message_content) != -1
Exemplo n.º 9
0
def test_actual_collateral_ids(session):
    """Assert that delete collateral id validation works as expected on an existing financing statement."""
    json_data = copy.deepcopy(AMENDMENT_VALID)
    statement = FinancingStatement.find_by_registration_number(
        'TEST0001', False)
    # example registration collateral ID's are bogus
    error_msg = validator.validate_collateral_ids(json_data, statement)
    assert error_msg != ''
    assert error_msg.find('Invalid vehicleId') != -1
    json_data['deleteVehicleCollateral'][0][
        'vehicleId'] = statement.vehicle_collateral[0].id
    error_msg = validator.validate_collateral_ids(json_data, statement)
    if error_msg != '':
        print(error_msg)
    assert error_msg == ''
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_number_valid(session):
    """Assert that a fetch individual financing statement on a valid registration number works as expected."""
    statement = FinancingStatement.find_by_registration_number(
        'TEST0001', False)
    assert statement
    result = statement.json
    assert result['type'] == 'SA'
    assert result['baseRegistrationNumber'] == 'TEST0001'
    assert result['registeringParty']
    assert result['createDateTime']
    assert result['debtors'][0]
    assert result['securedParties'][0]
    assert result['generalCollateral'][0]
    assert result['vehicleCollateral'][0]
    assert result['expiryDate']
    assert result['lifeYears']
    assert result['trustIndenture']
    if statement.current_view_json:
        assert result['courtOrderInformation']
Exemplo n.º 12
0
def test_actual_party_ids(session):
    """Assert that delete party id validation works as expected on an existing financing statement."""
    json_data = copy.deepcopy(AMENDMENT_VALID)
    statement = FinancingStatement.find_by_registration_number(
        'TEST0001', False)
    # example registration party ID's are bogus
    error_msg = validator.validate_party_ids(json_data, statement)
    assert error_msg != ''
    assert error_msg.find('Invalid partyId') != -1

    for party in statement.parties:
        if not party.registration_id_end and party.party_type == 'SP':
            json_data['deleteSecuredParties'][0]['partyId'] = party.id
        elif not party.registration_id_end and party.party_type in ('DB',
                                                                    'DI'):
            json_data['deleteDebtors'][0]['partyId'] = party.id
    error_msg = validator.validate_party_ids(json_data, statement)
    if error_msg != '':
        print(error_msg)
    assert error_msg == ''
Exemplo n.º 13
0
def test_validate_debtor_name(session, desc, reg_number, type, debtor_name,
                              valid):
    """Assert that base debtor check on an existing registration works as expected."""
    json_data = copy.deepcopy(DISCHARGE_STATEMENT)
    if type == 'DB':
        json_data['debtorName']['businessName'] = debtor_name
    else:
        person = {'last': debtor_name, 'first': 'Test ind', 'middle': '1'}
        del json_data['debtorName']['businessName']
        json_data['debtorName']['personName'] = person

    statement = FinancingStatement.find_by_registration_number(
        reg_number, 'PS12345', False)
    assert statement

    # valid business name
    valid_debtor = statement.validate_debtor_name(json_data['debtorName'],
                                                  False)
    if valid:
        assert valid_debtor
    else:
        assert not valid_debtor
Exemplo n.º 14
0
def test_find_by_registration_number_historical_staff(session):
    """Assert that a fetch discharged financing statement on a registration number works as expected for staff."""
    result = FinancingStatement.find_by_registration_number('TEST0003', True)
    assert result