Exemplo n.º 1
0
def test_now_ts_offset():
    """Assert that adjusting UTC now by a number of days is performing as expected."""
    now_ts = model_utils.now_ts() + _timedelta(days=60)
    test_ts = model_utils.now_ts_offset(60, True)
    print('Now timestamp + 60 days: ' + model_utils.format_ts(test_ts))
    assert test_ts.day == now_ts.day
    assert test_ts.month == now_ts.month
    assert test_ts.year == now_ts.year

    now_ts = model_utils.now_ts() - _timedelta(days=60)
    test_ts = model_utils.now_ts_offset(60, False)
    print('Now timestamp - 60 days: ' + model_utils.format_ts(test_ts))
    assert test_ts.day == now_ts.day
    assert test_ts.month == now_ts.month
    assert test_ts.year == now_ts.year
Exemplo n.º 2
0
    def find_all_by_account_id(cls,
                               account_id: str = None,
                               staff: bool = False):
        """Return a summary list of recent financing statements belonging to an account."""
        statement_list = None
        if account_id:
            # No date range restriction for staff?
            if staff:
                statement_list = db.session.query(Registration.registration_ts,
                                                  Registration.registration_num,
                                                  Registration.registration_type_cd,
                                                  FinancingStatement.state_type_cd).\
                                filter(FinancingStatement.financing_id == Registration.financing_id,
                                       Registration.account_id == account_id,
                                       Registration.registration_type_cl.in_(['PPSALIEN', 'MISCLIEN', 'CROWNLIEN'])).\
                                order_by(FinancingStatement.financing_id).all()
            else:
                days_ago = model_utils.now_ts_offset(10, False)
                statement_list = db.session.query(Registration.registration_ts,
                                                  Registration.registration_num,
                                                  Registration.registration_type_cd,
                                                  FinancingStatement.state_type_cd).\
                                filter(FinancingStatement.financing_id == Registration.financing_id,
                                       Registration.account_id == account_id,
                                       Registration.registration_type_cl.in_(['PPSALIEN', 'MISCLIEN', 'CROWNLIEN']),
                                       Registration.registration_ts > days_ago).\
                                order_by(FinancingStatement.financing_id).all()

        results_json = []
        if not statement_list:
            return results_json
        #    raise BusinessException(
        #        error=f'No Financing Statements found for Account ID {account_id}.',
        #        status_code=HTTPStatus.NOT_FOUND
        #    )

        for statement in statement_list:
            if staff or statement.state_type_cd == model_utils.STATE_ACTIVE:
                statement_json = {
                    'matchType':
                    'EXACT',
                    'createDateTime':
                    model_utils.format_ts(statement.registration_ts),
                    'baseRegistrationNumber':
                    statement.registration_num,
                    'registrationType':
                    statement.registration_type_cd
                }
                results_json.append(statement_json)

        # Non-staff, all historical/discharged
        # if not results_json:
        #    raise BusinessException(
        #        error=f'No active Financing Statements found for Account ID {account_id}.',
        #        status_code=HTTPStatus.NOT_FOUND
        #    )
        return results_json
Exemplo n.º 3
0
def test_today_ts_offset():
    """Assert that adjusting UTC today by a number of days is performing as expected."""
    test_now_ts = model_utils.now_ts_offset(7, False)
    test_today_ts = model_utils.today_ts_offset(7, False)
    # print('test now - 7 days: ' + model_utils.format_ts(test_now_ts))
    # print('test today - 7 days: ' + model_utils.format_ts(test_today_ts))
    assert test_today_ts.hour == 0
    assert test_today_ts.minute == 0
    assert test_today_ts.second == 0
    assert test_today_ts < test_now_ts
Exemplo n.º 4
0
def test_valid_court_order_date(session, financing_ts, renewal_ts,
                                today_offset, valid):
    """Assert that checking a RL renewal court order date works as expected."""
    reg_ts = model_utils.ts_from_iso_format(financing_ts)
    test_renew_ts = renewal_ts
    if not test_renew_ts:
        now_offset = model_utils.now_ts_offset(today_offset, True)
        test_renew_ts = model_utils.format_ts(now_offset)
    test_valid = model_utils.valid_court_order_date(reg_ts, test_renew_ts)
    # print(financing_ts + ' ' + test_renew_ts)
    assert test_valid == valid
Exemplo n.º 5
0
    def create_from_json(json_data, account_id: str):
        """Create a draft object from a json Draft schema object: map json to db."""
        # Perform all addtional data validation checks.
        FinancingStatement.validate(json_data)

        statement = FinancingStatement()
        statement.state_type_cd = model_utils.STATE_ACTIVE

        # Do this early as it also checks the party codes and may throw an exception
        statement.parties = Party.create_from_financing_json(json_data, None)

        reg_type = json_data['type']
        if reg_type == model_utils.REG_TYPE_REPAIRER_LIEN:
            statement.expire_date = model_utils.now_ts_offset(
                model_utils.REPAIRER_LIEN_DAYS, True)
            statement.life = model_utils.REPAIRER_LIEN_YEARS
        elif 'lifeInfinite' in json_data and json_data['lifeInfinite']:
            statement.life = model_utils.LIFE_INFINITE
        else:
            if 'lifeYears' in json_data:
                statement.life = json_data['lifeYears']
                if statement.life > 0:
                    statement.expire_date = model_utils.expiry_dt_from_years(
                        statement.life)
            if 'expiryDate' in json_data and not statement.expire_date:
                statement.expire_date = model_utils.expiry_ts_from_iso_format(
                    json_data['expiryDate'])

        statement.registration = [
            Registration.create_financing_from_json(json_data, account_id)
        ]
        statement.registration_num = statement.registration[0].registration_num
        registration_id = statement.registration[0].registration_id
        statement.trust_indenture = TrustIndenture.create_from_json(
            json_data, registration_id)
        if 'vehicleCollateral' in json_data:
            statement.vehicle_collateral = VehicleCollateral.create_from_financing_json(
                json_data, registration_id)
        if 'generalCollateral' in json_data:
            statement.general_collateral = GeneralCollateral.create_from_financing_json(
                json_data, registration_id)

        for party in statement.parties:
            party.registration_id = registration_id

        return statement
Exemplo n.º 6
0
def test_search_query_invalid_start_datetime_400(session, client, jwt):
    """Assert that a valid search request with an invalid startDateTime returns a 400 status."""
    # setup
    json_data = {
        'type': 'REGISTRATION_NUMBER',
        'criteria': {
            'value': 'TEST0001'
        },
        'clientReferenceId': 'T-API-SQ-RN-6',
        'endDateTime': '2021-01-20T19:38:43+00:00'
    }
    ts_start = now_ts_offset(1, True)
    json_data['startDateTime'] = format_ts(ts_start)

    # test
    rv = client.post('/api/v1/searches',
                     json=json_data,
                     headers=create_header_account(jwt, [PPR_ROLE]),
                     content_type='application/json')

    # check
    assert rv.status_code == HTTPStatus.BAD_REQUEST
Exemplo n.º 7
0
def test_search_enddatatetime_invalid(session, client, jwt):
    """Assert that validation of a search with an invalid endDateTime throws a BusinessException."""
    # setup
    json_data = {
        'type': 'REGISTRATION_NUMBER',
        'criteria': {
            'value': 'TEST0001'
        },
        'clientReferenceId': 'T-API-SQ-RG-8',
        'startDateTime': '2021-01-20T19:38:43+00:00'
    }
    ts_end = now_ts_offset(1, True)
    json_data['endDateTime'] = format_ts(ts_end)

    # test
    with pytest.raises(BusinessException) as bad_request_err:
        SearchRequest.validate_query(json_data)

    # 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 test_validate_rl(session, desc, valid, lien_amount, surrender_date,
                     message_content):
    """Assert that financing statement RL registration type validation works as expected."""
    # setup
    json_data = copy.deepcopy(FINANCING)
    json_data['type'] = model_utils.REG_TYPE_REPAIRER_LIEN
    del json_data['lifeYears']
    del json_data['lifeInfinite']
    del json_data['trustIndenture']
    if lien_amount is not None:
        json_data['lienAmount'] = lien_amount
    if surrender_date == 'valid':
        json_data['surrenderDate'] = model_utils.format_ts(
            model_utils.now_ts())
    elif surrender_date == 'old':
        json_data['surrenderDate'] = model_utils.format_ts(
            model_utils.today_ts_offset(22, False))
    elif surrender_date == '21':
        json_data['surrenderDate'] = model_utils.format_ts(
            model_utils.now_ts_offset(21, False))
    elif surrender_date == 'junk':
        json_data['surrenderDate'] = 'invalid date'
    if desc != DESC_INCLUDES_GC:
        del json_data['generalCollateral']
    if desc == DESC_MISSING_VC:
        del json_data['vehicleCollateral']
    elif desc == DESC_VC_MH:
        json_data['vehicleCollateral'][0]['type'] = 'MH'

    error_msg = validator.validate(json_data)
    if valid:
        assert error_msg == ''
    elif message_content:
        # print(error_msg)
        assert error_msg != ''
        assert error_msg.find(message_content) != -1
Exemplo n.º 9
0
    def create_from_json(json_data,
                         registration_type_cl: str,
                         financing_statement,
                         base_registration_num: str,
                         account_id: str = None):
        """Create a registration object for an existing financing statement from dict/json."""
        # Perform all addtional data validation checks.
        Registration.validate(json_data, financing_statement, registration_type_cl)

        # Create or update draft.
        draft = Registration.find_draft(json_data, None, None)
        reg_vals = Registration.get_generated_values(draft)
        registration = Registration()
        registration.registration_id = reg_vals.registration_id
        registration.registration_num = reg_vals.registration_num
        registration.registration_ts = model_utils.now_ts()
        registration.financing_id = financing_statement.financing_id
        registration.financing_statement = financing_statement
        registration.account_id = account_id
        if not draft:
            registration.document_number = reg_vals.document_number
            draft = Draft.create_from_registration(registration, json_data)
        else:
            registration.document_number = draft.document_number
        registration.draft = draft
        registration.registration_type_cl = registration_type_cl
        if registration_type_cl in (model_utils.REG_CLASS_AMEND,
                                    model_utils.REG_CLASS_AMEND_COURT,
                                    model_utils.REG_CLASS_CHANGE):
            registration.registration_type_cd = json_data['changeType']
            if registration.registration_type_cd == model_utils.REG_TYPE_AMEND_COURT:
                registration.registration_type_cl = model_utils.REG_CLASS_AMEND_COURT
            if 'description' in json_data:
                registration.detail_description = json_data['description']
        if registration_type_cl == model_utils.REG_CLASS_RENEWAL:
            registration.registration_type_cd = model_utils.REG_TYPE_RENEWAL
        elif registration_type_cl == model_utils.REG_CLASS_DISCHARGE:
            registration.registration_type_cd = model_utils.REG_TYPE_DISCHARGE

        registration.base_registration_num = base_registration_num
        registration.ver_bypassed = 'Y'
        registration.draft.registration_type_cd = registration.registration_type_cd
        registration.draft.registration_type_cl = registration.registration_type_cl

        if 'clientReferenceId' in json_data:
            registration.client_reference_id = json_data['clientReferenceId']

        # All registrations have at least one party (registering).
        registration.parties = Party.create_from_statement_json(json_data,
                                                                registration_type_cl,
                                                                registration.financing_id)

        # If get to here all data should be valid: get reg id to close out updated entities.
        registration_id = registration.registration_id
        financing_reg_type = registration.financing_statement.registration[0].registration_type_cd
        if registration_type_cl == model_utils.REG_CLASS_DISCHARGE:
            registration.financing_statement.state_type_cd = model_utils.STATE_DISCHARGED
            registration.financing_statement.discharged = 'Y'
        elif registration_type_cl == model_utils.REG_CLASS_RENEWAL:
            if financing_reg_type == model_utils.REG_TYPE_REPAIRER_LIEN:
                registration.life = model_utils.REPAIRER_LIEN_YEARS
                registration.financing_statement.expire_date = \
                    model_utils.now_ts_offset(model_utils.REPAIRER_LIEN_DAYS, True)
            else:
                if 'lifeYears' in json_data:
                    registration.life = json_data['lifeYears']
                    registration.financing_statement.expire_date = model_utils.expiry_dt_from_years(registration.life)
                elif 'expiryDate' in json_data:
                    new_expiry_date = model_utils.expiry_ts_from_iso_format(json_data['expiryDate'])
                    registration.life = new_expiry_date.year - registration.financing_statement.expire_date.year
                    registration.financing_statement.expire_date = new_expiry_date

            # TODO: verify this is updated.
            registration.financing_statement.life = registration.life

        # Repairer's lien renewal or amendment can have court order information.
        if (registration.registration_type_cd == model_utils.REG_TYPE_AMEND_COURT or
                registration.registration_type_cd == model_utils.REG_TYPE_RENEWAL) and \
                'courtOrderInformation' in json_data:
            registration.court_order = CourtOrder.create_from_json(json_data['courtOrderInformation'],
                                                                   registration_id)

        if registration_type_cl in (model_utils.REG_CLASS_AMEND,
                                    model_utils.REG_CLASS_AMEND_COURT,
                                    model_utils.REG_CLASS_CHANGE):
            # Possibly add vehicle collateral
            registration.vehicle_collateral = VehicleCollateral.create_from_statement_json(json_data,
                                                                                           registration_id,
                                                                                           registration.financing_id)
            # Possibly add general collateral
            registration.general_collateral = GeneralCollateral.create_from_statement_json(json_data,
                                                                                           registration_id,
                                                                                           registration.financing_id)
            # Close out deleted parties and collateral
            Registration.delete_from_json(json_data, registration, financing_statement)

        return registration