예제 #1
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'
예제 #2
0
파일: test_utils.py 프로젝트: kialj876/ppr
def test_expiry_date(session, registration_ts, offset, expiry_ts):
    """Assert that computing expiry ts from registraton ts works as expected."""
    # reg_ts = model_utils.ts_from_iso_format(registration_ts)
    expiry_test = model_utils.expiry_dt_from_years(offset, registration_ts)
    expiry_iso = model_utils.format_ts(expiry_test)
    # print(registration_ts + ', ' + model_utils.format_ts(reg_ts) + ', '  + expiry_iso)
    assert expiry_ts == expiry_iso
예제 #3
0
파일: test_utils.py 프로젝트: pwei1018/ppr
def test_expiry_dt_add_years():
    """Assert that adding years to an expiry date is performing as expected."""
    expiry_ts = model_utils.expiry_dt_from_years(1)
    add_ts = model_utils.expiry_dt_add_years(expiry_ts, 4)
    print('Initial expiry: ' + model_utils.format_ts(expiry_ts))
    print('Updated expiry: ' + model_utils.format_ts(add_ts))
    assert (add_ts.year - expiry_ts.year) == 4
예제 #4
0
    def create_from_json(json_data, account_id: str, user_id: str = None):
        """Create a financing statement object from a json Financing Statement schema object: map json to db."""
        statement = FinancingStatement()
        statement.state_type = 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']
        statement.registration = [Registration.create_financing_from_json(json_data, account_id, user_id)]
        statement.life = statement.registration[0].life
        if reg_type == model_utils.REG_TYPE_REPAIRER_LIEN:
            statement.expire_date = model_utils.expiry_dt_repairer_lien()
        elif statement.life and statement.life != model_utils.LIFE_INFINITE:
            statement.expire_date = model_utils.expiry_dt_from_years(statement.life)

        if reg_type == model_utils.REG_TYPE_OTHER and 'otherTypeDescription' in json_data:
            statement.crown_charge_other = json_data['otherTypeDescription']

        registration_id = statement.registration[0].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
예제 #5
0
파일: test_utils.py 프로젝트: kialj876/ppr
def test_expiry_dt_from_years():
    """Assert that generating an expiry date from life years is performing as expected."""
    expiry_ts = model_utils.expiry_dt_from_years(5)
    now_ts = model_utils.now_ts()
    print('Expiry timestamp: ' + model_utils.format_ts(expiry_ts))
    print('Now timestamp: ' + model_utils.format_ts(now_ts))
    assert (expiry_ts.year - now_ts.year) == 5
    assert expiry_ts.hour in (6, 7)
    assert expiry_ts.minute == 59
    assert expiry_ts.second == 59
    assert expiry_ts.day in (1, now_ts.day, (now_ts.day + 1))
    assert expiry_ts.month in (now_ts.month, (now_ts.month + 1))
예제 #6
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
예제 #7
0
파일: test_utils.py 프로젝트: kialj876/ppr
def test_expiry_date_add(session, registration_ts, add_1, add_2, add_3,
                         expiry_ts):
    """Assert that computing an renewal non-RL expiry ts from registraton ts works as expected."""
    reg_ts = model_utils.ts_from_iso_format(registration_ts)
    expiry_add_1 = model_utils.expiry_dt_from_years(add_1, registration_ts)
    assert expiry_add_1.year - add_1 == reg_ts.year
    assert expiry_add_1.hour in (6, 7)
    assert expiry_add_1.minute == 59
    assert expiry_add_1.second == 59
    expiry_add_2 = model_utils.expiry_dt_add_years(expiry_add_1, add_2)
    assert expiry_add_2.year - expiry_add_1.year == add_2
    assert expiry_add_2.hour in (6, 7)
    assert expiry_add_2.minute == 59
    assert expiry_add_2.second == 59
    expiry_add_3 = model_utils.expiry_dt_add_years(expiry_add_2, add_3)
    assert expiry_add_3.year - expiry_add_2.year == add_3
    assert expiry_add_3.hour in (6, 7)
    assert expiry_add_3.minute == 59
    assert expiry_add_3.second == 59
    expiry_iso = model_utils.format_ts(expiry_add_3)
    # print(registration_ts + ', ' + model_utils.format_ts(reg_ts) + ', '  + expiry_iso)
    assert expiry_ts == expiry_iso
예제 #8
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