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_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.º 3
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.º 4
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.º 5
0
    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)
Exemplo n.º 6
0
def test_gc_legacy_current_json(session):
    """Assert that the financing statement JSON contains expected general collateral."""
    result = FinancingStatement.find_by_id(200000012)
    result.mark_update_json = False
    result.current_view_json = True
    json_data = result.json
    # print(json_data)
    assert len(json_data['generalCollateral']) >= 4
    for collateral in json_data['generalCollateral']:
        assert 'collateralId' in collateral
        assert 'addedDateTime' in collateral
        # print(collateral)
        if collateral['collateralId'] in (200000004, 200000005, 200000006):
            assert collateral['description']
            assert 'descriptionAdd' not in collateral
            assert 'descriptionDelete' not in collateral
        if collateral['collateralId'] == 200000007:
            assert collateral['descriptionAdd']
            assert 'descriptionDelete' not in collateral
            assert 'description' not in collateral
        if collateral['collateralId'] == 200000008:
            assert collateral['descriptionDelete']
            assert 'descriptionAdd' not in collateral
            assert 'description' not in collateral
        if collateral['collateralId'] == 200000009:
            assert collateral['descriptionAdd']
            assert collateral['descriptionDelete']
            assert 'description' not in collateral
Exemplo n.º 7
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.º 8
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.º 9
0
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'
Exemplo n.º 10
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.º 11
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.º 12
0
def test_find_all_by_account_id(session):
    """Assert that the financing statement summary list by account id first item contains all expected elements."""
    statement_list = FinancingStatement.find_all_by_account_id('PS12345', True)

    assert statement_list
    assert statement_list[0]['matchType']
    assert statement_list[0]['baseRegistrationNumber']
    assert statement_list[0]['registrationType']
    assert statement_list[0]['createDateTime']
Exemplo n.º 13
0
def test_find_debtor_names(session, reg_num, results_size):
    """Assert that finding debtor names by registration number works as expected."""
    names_json = FinancingStatement.find_debtor_names_by_registration_number(
        reg_num)
    if results_size == 0:
        assert not names_json or len(names_json) == 0
    else:
        assert names_json and len(names_json) == results_size
        if reg_num == 'TEST0001':
            assert names_json[0]['personName']['last'] == 'DEBTOR'
            assert names_json[1]['businessName'] == 'TEST BUS 2 DEBTOR'
            assert names_json[2]['businessName'] == 'TEST 7 AMEND DEBTOR'
            assert names_json[3]['businessName'] == 'TEST 8 TRANSFER DEBTOR'
Exemplo n.º 14
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.º 15
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.º 16
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.º 17
0
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)
Exemplo n.º 18
0
def test_gc_legacy_json(session):
    """Assert that the financing statement JSON contains expected general collateral."""
    result = FinancingStatement.find_by_id(200000012)
    result.mark_update_json = False
    result.current_view_json = False
    json_data = result.json
    # print(json_data)
    assert len(json_data['generalCollateral']) == 3
    for collateral in json_data['generalCollateral']:
        assert 'collateralId' in collateral
        assert 'addedDateTime' in collateral
        assert 'description' in collateral
        assert 'descriptionAdd' not in collateral
        assert 'descriptionDelete' not in collateral
Exemplo n.º 19
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.º 20
0
def test_find_by_id(session):
    """Assert that find financing statement by ID contains all expected elements."""
    result = FinancingStatement.find_by_id(200000000)
    assert result
    assert result.registration_num
    if result:
        json_data = result.json
        assert json_data['type'] == 'SA'
        assert json_data['baseRegistrationNumber'] == 'TEST0001'
        assert json_data['registeringParty']
        assert json_data['createDateTime']
        assert json_data['debtors'][0]
        assert json_data['securedParties'][0]
        assert json_data['generalCollateral'][0]
        assert json_data['vehicleCollateral'][0]
Exemplo n.º 21
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.º 22
0
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'
Exemplo n.º 23
0
def test_find_all_by_account_id(session):
    """Assert that the financing statement summary list by account id first item contains all expected elements."""
    statement_list = FinancingStatement.find_all_by_account_id('PS12345')

    assert statement_list
    assert statement_list[0]['registrationNumber']
    assert statement_list[0]['registrationType']
    assert statement_list[0]['registrationClass']
    assert statement_list[0]['registrationDescription']
    assert statement_list[0]['statusType']
    assert statement_list[0]['createDateTime']
    assert statement_list[0]['lastUpdateDateTime']
    assert statement_list[0]['expireDays']
    assert statement_list[0]['registeringParty']
    assert statement_list[0]['securedParties']
    # assert statement_list[0]['clientReferenceId']
    assert statement_list[0]['path']
Exemplo n.º 24
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.º 25
0
def test_current_json(session):
    """Assert that financing statement JSON contains expected current view elements."""
    result = FinancingStatement.find_by_id(200000000)
    result.mark_update_json = True
    result.current_view_json = True
    json_data = result.json
    assert len(json_data['debtors']) >= 2
    assert len(json_data['securedParties']) >= 2
    assert len(json_data['generalCollateral']) >= 2
    assert len(json_data['vehicleCollateral']) >= 2
    assert 'added' in json_data['debtors'][1]
    assert 'added' in json_data['securedParties'][1]
    assert 'added' not in json_data['generalCollateral'][1]
    assert 'added' in json_data['vehicleCollateral'][1]
    assert json_data['debtors'][1]['added']
    assert json_data['securedParties'][1]['added']
    assert json_data['vehicleCollateral'][1]['added']
Exemplo n.º 26
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.º 27
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.º 28
0
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
Exemplo n.º 29
0
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
Exemplo n.º 30
0
def test_find_by_financing_id(session):
    """Assert that find financing statement by financing statement ID contains all expected elements."""
    result = FinancingStatement.find_by_financing_id(200000000)
    assert result
    assert result.registration_num
    if result:
        result.mark_update_json = True
        json_data = result.json
        # print(json_data)
        assert json_data['type'] == 'SA'
        assert json_data['baseRegistrationNumber'] == 'TEST0001'
        assert json_data['registeringParty']
        assert json_data['createDateTime']
        assert json_data['debtors'][0]
        assert json_data['securedParties'][0]
        assert json_data['generalCollateral'][0]
        assert json_data['vehicleCollateral'][0]
        assert json_data['expiryDate']
        assert json_data['lifeYears']
        assert json_data['trustIndenture']