コード例 #1
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
コード例 #2
0
    def find_all_by_account_id(cls, account_id):
        """Return a summary list of recent financing statements belonging to an account."""
        results_json = []
        if not account_id:
            return results_json

        max_results_size = int(current_app.config.get('ACCOUNT_REGISTRATIONS_MAX_RESULTS'))
        results = db.session.execute(model_utils.QUERY_ACCOUNT_FINANCING_STATEMENTS,
                                     {'query_account': account_id, 'max_results_size': max_results_size})
        rows = results.fetchall()
        if rows is not None:
            for row in rows:
                mapping = row._mapping  # pylint: disable=protected-access; follows documentation
                result = {
                    'registrationNumber': str(mapping['registration_number']),
                    'baseRegistrationNumber': str(mapping['registration_number']),
                    'createDateTime': model_utils.format_ts(mapping['registration_ts']),
                    'registrationType': str(mapping['registration_type']),
                    'registrationClass': str(mapping['registration_type_cl']),
                    'registrationDescription': str(mapping['registration_desc']),
                    'statusType': str(mapping['state']),
                    'expireDays': int(mapping['expire_days']),
                    'lastUpdateDateTime': model_utils.format_ts(mapping['last_update_ts']),
                    'registeringParty': str(mapping['registering_party']),
                    'securedParties': str(mapping['secured_party']),
                    'clientReferenceId': str(mapping['client_reference_id']),
                    'path': '/ppr/api/v1/financing-statements/' + str(mapping['registration_number'])
                }
                results_json.append(result)
        return results_json
コード例 #3
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
def test_ts_from_iso_format():
    """Assert that creating a UTC datetime object from an ISO date-time formatted string is performing as expected."""
    test_ts = model_utils.ts_from_iso_format('2021-02-16T23:00:00-08:00')
    print('Test timestamp: ' + model_utils.format_ts(test_ts))
    assert test_ts.day == 17
    assert test_ts.month == 2
    assert test_ts.year == 2021
    assert test_ts.hour == 7
    assert test_ts.minute == 0
    assert test_ts.second == 0

    test_ts = model_utils.ts_from_iso_format('2021-02-16T23:00:00+00:00')
    print('Test timestamp: ' + model_utils.format_ts(test_ts))
    assert test_ts.day == 16
    assert test_ts.hour == 23

    test_ts = model_utils.ts_from_iso_format('2021-02-16T13:00:00-08:00')
    # print('Test timestamp: ' + model_utils.format_ts(test_ts))
    assert test_ts.day == 16
    assert test_ts.hour == 21

    test_ts = model_utils.ts_from_iso_format('2021-03-31T23:00:00-08:00')
    # print('Test timestamp: ' + model_utils.format_ts(test_ts))
    assert test_ts.month == 4
    assert test_ts.day == 1
    assert test_ts.hour == 7
コード例 #4
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'
コード例 #5
0
ファイル: test_utils.py プロジェクト: pwei1018/ppr
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
コード例 #6
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))
コード例 #7
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
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
コード例 #8
0
    def search_by_registration_number(self):
        """Execute a search by registration number query."""
        reg_num = self.request_json['criteria']['value']
        result = db.session.execute(search_utils.REG_NUM_QUERY,
                                    {'query_value': reg_num.strip().upper()})
        row = result.first()
        if row is not None:
            mapping = row._mapping  # pylint: disable=protected-access; follows documentation
            registration_type = str(mapping['registration_type'])
            # Remove state check for now - let the DB view take care of it.
            timestamp = mapping['base_registration_ts']
            result_json = [{
                'baseRegistrationNumber':
                str(mapping['base_registration_num']),
                'matchType':
                str(mapping['match_type']),
                'createDateTime':
                model_utils.format_ts(timestamp),
                'registrationType':
                registration_type
            }]
            if reg_num != str(mapping['base_registration_num']):
                result_json[0]['registrationNumber'] = reg_num

            self.returned_results_size = 1
            self.total_results_size = 1
            self.search_response = result_json
        else:
            self.returned_results_size = 0
            self.total_results_size = 0
コード例 #9
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
def test_expiry_date_rl(session, registration_ts, expiry_ts):
    """Assert that computing an RL expiry ts from registraton ts works as expected."""
    reg_ts = model_utils.ts_from_iso_format(registration_ts)
    expiry_test = model_utils.expiry_dt_repairer_lien(reg_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
コード例 #10
0
    def search_by_registration_number(self):
        """Execute a search by registration number query."""
        reg_num = self.request_json['criteria']['value']
        query = search_utils.REG_NUM_QUERY.replace('?', reg_num)
        result = db.session.execute(query)
        row = result.first()
        if row is not None:
            values = row.values()
            registration_type = str(values[0])
            # Remove state check for now - let the DB view take care of it.
            timestamp = values[1]
            result_json = [{
                'baseRegistrationNumber': str(values[2]),
                'matchType': str(values[3]),
                'createDateTime': model_utils.format_ts(timestamp),
                'registrationType': registration_type
            }]
            if reg_num != str(values[2]):
                result_json[0]['registrationNumber'] = reg_num

            self.returned_results_size = 1
            self.total_results_size = 1
            self.search_response = json.dumps(result_json)
        else:
            self.returned_results_size = 0
            self.total_results_size = 0
コード例 #11
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
コード例 #12
0
    def search_by_business_name(self):
        """Execute a search query debtor business_name search type."""
        search_value = self.request_json['criteria']['debtorName']['business']
        query = search_utils.BUSINESS_NAME_QUERY.replace(
            '?',
            search_value.strip().upper())
        result = db.session.execute(query)
        rows = result.fetchall()
        if rows is not None:
            results_json = []
            for row in rows:
                values = row.values()
                registration_type = str(values[0])
                timestamp = values[1]
                debtor = {
                    'businessName': str(values[2]),
                    'partyId': int(values[7])
                }
                result_json = {
                    'baseRegistrationNumber': str(values[3]),
                    'matchType': str(values[4]),
                    'createDateTime': model_utils.format_ts(timestamp),
                    'registrationType': registration_type,
                    'debtor': debtor
                }
                results_json.append(result_json)

            self.returned_results_size = len(results_json)
            self.total_results_size = self.returned_results_size
            if self.returned_results_size > 0:
                self.search_response = json.dumps(results_json)
        else:
            self.returned_results_size = 0
            self.total_results_size = 0
コード例 #13
0
    def search_by_serial_type(self):
        """Execute a search query for either an aircraft DOT, MHR number, or serial number search type."""
        search_value = self.request_json['criteria']['value']
        query = search_utils.SERIAL_NUM_QUERY
        if self.search_type == 'MH':
            query = search_utils.MHR_NUM_QUERY
            query = query.replace('CASE WHEN serial_number',
                                  'CASE WHEN mhr_number')
        elif self.search_type == 'AC':
            query = search_utils.AIRCRAFT_DOT_QUERY

        max_results_size = int(
            current_app.config.get('ACCOUNT_SEARCH_MAX_RESULTS'))
        result = db.session.execute(
            query, {
                'query_value': search_value.strip().upper(),
                'max_results_size': max_results_size
            })
        rows = result.fetchall()
        if rows is not None:
            results_json = []
            for row in rows:
                mapping = row._mapping  # pylint: disable=protected-access; follows documentation
                registration_type = str(mapping['registration_type'])
                timestamp = mapping['base_registration_ts']
                collateral = {
                    'type': str(mapping['serial_type']),
                    'serialNumber': str(mapping['serial_number'])
                }
                value = mapping['year']
                if value is not None:
                    collateral['year'] = int(value)
                value = mapping['make']
                if value is not None:
                    collateral['make'] = str(value)
                value = mapping['model']
                if value is not None:
                    collateral['model'] = str(value)
                match_type = str(mapping['match_type'])
                if self.search_type == 'MH':
                    collateral['manufacturedHomeRegistrationNumber'] = str(
                        mapping['mhr_number'])
                result_json = {
                    'baseRegistrationNumber':
                    str(mapping['base_registration_num']),
                    'matchType': match_type,
                    'createDateTime': model_utils.format_ts(timestamp),
                    'registrationType': registration_type,
                    'vehicleCollateral': collateral
                }
                results_json.append(result_json)

            self.returned_results_size = len(results_json)
            self.total_results_size = self.returned_results_size
            if self.returned_results_size > 0:
                self.search_response = results_json
        else:
            self.returned_results_size = 0
            self.total_results_size = 0
コード例 #14
0
    def find_all_by_account_id(cls, account_id: str = None):
        """Return a summary list of drafts belonging to an account."""
        drafts_json = []
        if account_id:
            max_results_size = int(
                current_app.config.get('ACCOUNT_DRAFTS_MAX_RESULTS'))
            results = db.session.execute(model_utils.QUERY_ACCOUNT_DRAFTS, {
                'query_account': account_id,
                'max_results_size': max_results_size
            })
            rows = results.fetchall()
            if rows is not None:
                for row in rows:
                    mapping = row._mapping  # pylint: disable=protected-access; follows documentation
                    registering_name = str(mapping['registering_name'])
                    if not registering_name or registering_name == 'None':
                        registering_name = ''
                    ref_id = str(mapping['client_reference_id'])
                    if not ref_id or ref_id == 'None':
                        ref_id = ''
                    draft_json = {
                        'createDateTime':
                        model_utils.format_ts(mapping['create_ts']),
                        'documentId':
                        str(mapping['document_number']),
                        'baseRegistrationNumber':
                        str(mapping['base_reg_num']),
                        'registrationType':
                        str(mapping['registration_type']),
                        'registrationDescription':
                        str(mapping['registration_desc']),
                        'type':
                        str(mapping['draft_type']),
                        'lastUpdateDateTime':
                        model_utils.format_ts(mapping['last_update_ts']),
                        'path':
                        '/ppr/api/v1/drafts/' +
                        str(mapping['document_number']),
                        'registeringName':
                        registering_name,
                        'client_reference_id':
                        ref_id
                    }
                    drafts_json.append(draft_json)

        return drafts_json
コード例 #15
0
ファイル: search_result.py プロジェクト: pwei1018/ppr
    def update_selection(self, search_select):
        """Update the set of search details from the search query selection.

        Remove any original similar match financing statements that are not in the current search query selection.
        """
        # Nothing to do if search had no results.
        if self.search.total_results_size < 1:
            return

        # Build default summary information
        detail_response = {
            'searchDateTime': model_utils.format_ts(self.search.search_ts),
            'exactResultsSize': self.exact_match_count,
            'similarResultsSize': self.similar_match_count,
            'searchQuery': json.loads(self.search.search_criteria),
            'details': []
        }
        if self.search.pay_invoice_id and self.search.pay_path:
            payment = {
                'invoiceId': str(self.search.pay_invoice_id),
                'receipt': self.search.pay_path
            }
            detail_response['payment'] = payment

        results = json.loads(self.search_response)
        new_results = []
        exact_count = 0
        similar_count = 0
        for result in results:
            # Always include exact matches.
            if result['matchType'] == model_utils.SEARCH_MATCH_EXACT:
                new_results.append(result)
                exact_count += 1
            else:
                found = False
                reg_num = result['financingStatement'][
                    'baseRegistrationNumber']
                for select in search_select:
                    if select['baseRegistrationNumber'] == reg_num and \
                       ('selected' not in select or select['selected']):
                        found = True
                        similar_count += 1
                if found:
                    new_results.append(result)

        # current_app.logger.debug('exact_count=' + str(exact_count) + ' similar_count=' + str(similar_count))
        self.search_select = json.dumps(search_select)
        self.exact_match_count = exact_count
        self.similar_match_count = similar_count
        # current_app.logger.debug('saving updates')
        # Update summary information and save.
        detail_response['exactResultsSize'] = self.exact_match_count
        detail_response['similarResultsSize'] = self.similar_match_count
        detail_response['totalResultsSize'] = (self.exact_match_count +
                                               self.similar_match_count)
        detail_response['details'] = new_results
        self.search_response = json.dumps(detail_response)
        self.save()
コード例 #16
0
ファイル: financing_statement.py プロジェクト: pwei1018/ppr
    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
コード例 #17
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
def test_expiry_dt_from_registration(session, desc, registration_ts,
                                     life_years, hour):
    """Assert that creating an expiry timestamp from a registration timestamp is performing as expected."""
    test_ts = model_utils.ts_from_iso_format(registration_ts)
    expiry_ts = model_utils.expiry_dt_from_registration(test_ts, life_years)
    print(model_utils.format_ts(expiry_ts))
    assert expiry_ts.year - test_ts.year == life_years
    assert expiry_ts.hour == hour
    assert expiry_ts.minute == 59
    assert expiry_ts.second == 59
コード例 #18
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
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
コード例 #19
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
def test_ts_from_date_iso_format():
    """Assert that creating a UTC datetime object from an ISO date-time formatted string is performing as expected."""
    test_ts = model_utils.ts_from_date_iso_format('2021-02-16')
    print('Test timestamp: ' + model_utils.format_ts(test_ts))
    assert test_ts.day in (16, 17)
    assert test_ts.month == 2
    assert test_ts.year == 2021
    if test_ts.day == 16:
        assert test_ts.hour >= 8
    else:
        assert test_ts.hour <= 7
コード例 #20
0
ファイル: general_collateral.py プロジェクト: kialj876/ppr
 def json(self) -> dict:
     """Generate the default financing statement view of the general collateral as json/a dict."""
     collateral = {
         'collateralId': self.id,
         'description': self.description,
         'addedDateTime': ''
     }
     if self.registration:
         collateral['addedDateTime'] = model_utils.format_ts(
             self.registration.registration_ts)
     return collateral
コード例 #21
0
    def json(self) -> dict:
        """Return the draft as a json object."""
        draft = json.loads(self.draft)

        draft['createDateTime'] = model_utils.format_ts(self.create_ts)
        if self.update_ts:
            draft['lastUpdateDateTime'] = model_utils.format_ts(self.update_ts)
        if self.document_number:
            if self.registration_type_cl in (
                    model_utils.REG_CLASS_AMEND,
                    model_utils.REG_CLASS_AMEND_COURT):
                draft['amendmentStatement'][
                    'documentId'] = self.document_number
            elif self.registration_type_cl == model_utils.REG_CLASS_CHANGE:
                draft['changeStatement']['documentId'] = self.document_number
            elif self.registration_type_cl in (model_utils.REG_CLASS_FINANCING,
                                               model_utils.REG_CLASS_MISC):
                draft['financingStatement'][
                    'documentId'] = self.document_number

        return draft
コード例 #22
0
    def search_by_serial_type(self):
        """Execute a search query for either an aircraft DOT, MHR number, or serial number search type."""
        search_value = self.request_json['criteria']['value']
        query = search_utils.SERIAL_NUM_QUERY
        if self.search_type_cd == 'MH':
            query = search_utils.MHR_NUM_QUERY
            query = query.replace('DECODE(serial_number', 'DECODE(mhr_number')
        elif self.search_type_cd == 'AC':
            query = search_utils.AIRCRAFT_DOT_QUERY

        query = query.replace('?', search_value)
        result = db.session.execute(query)
        rows = result.fetchall()
        if rows is not None:
            results_json = []
            for row in rows:
                values = row.values()
                registration_type = str(values[0])
                timestamp = values[1]
                collateral = {
                    'type': str(values[2]),
                    'serialNumber': str(values[3])
                }
                value = values[4]
                if value is not None:
                    collateral['year'] = int(value)
                value = values[5]
                if value is not None:
                    collateral['make'] = str(value)
                value = values[6]
                if value is not None:
                    collateral['model'] = str(value)
                match_type = str(values[8])
                if self.search_type_cd == 'MH':
                    collateral['manufacturedHomeRegistrationNumber'] = str(
                        values[12])
                result_json = {
                    'baseRegistrationNumber': str(values[7]),
                    'matchType': match_type,
                    'createDateTime': model_utils.format_ts(timestamp),
                    'registrationType': registration_type,
                    'vehicleCollateral': collateral
                }
                results_json.append(result_json)

            self.returned_results_size = len(results_json)
            self.total_results_size = self.returned_results_size
            if self.returned_results_size > 0:
                self.search_response = json.dumps(results_json)
        else:
            self.returned_results_size = 0
            self.total_results_size = 0
コード例 #23
0
    def __get_renewal_rl_expiry(self):
        """Build a repairer's lien expiry date as the sum of previous registrations."""
        expiry_ts = None
        for registration in self.financing_statement.registration:
            if registration.registration_type_cl in (model_utils.REG_CLASS_CROWN, model_utils.REG_CLASS_MISC,
                                                     model_utils.REG_CLASS_PPSA):
                expiry_ts = model_utils.expiry_dt_repairer_lien(registration.registration_ts)

        for registration in self.financing_statement.registration:
            if registration.registration_type == model_utils.REG_TYPE_RENEWAL and registration.id <= self.id:
                expiry_ts = model_utils.expiry_dt_repairer_lien(expiry_ts)

        return model_utils.format_ts(expiry_ts)
コード例 #24
0
ファイル: test_utils.py プロジェクト: kialj876/ppr
def test_expiry_date_renew_rl(session, desc, registration_ts, renew_count,
                              expiry_ts):
    """Assert that computing multiple RL renewal expiry ts from registration ts works as expected."""
    reg_ts = model_utils.ts_from_iso_format(registration_ts)
    expiry_test = model_utils.expiry_dt_repairer_lien(reg_ts)
    # print(model_utils.format_ts(expiry_test))
    if renew_count > 0:
        for x in range(renew_count):
            expiry_test = model_utils.expiry_dt_repairer_lien(expiry_test)
            # print(model_utils.format_ts(expiry_test))

    expiry_iso = model_utils.format_ts(expiry_test)
    assert expiry_ts == expiry_iso
コード例 #25
0
ファイル: general_collateral.py プロジェクト: kialj876/ppr
 def current_json(self) -> dict:
     """Generate the current Financing Statement view of the general collateral as json/dict."""
     collateral = {'collateralId': self.id, 'addedDateTime': ''}
     if self.status and self.status == GeneralCollateralLegacy.StatusTypes.ADDED:
         collateral['descriptionAdd'] = self.description
     elif self.status and self.status == GeneralCollateralLegacy.StatusTypes.DELETED:
         collateral['descriptionDelete'] = self.description
     else:
         collateral['description'] = self.description
     if self.registration:
         collateral['addedDateTime'] = model_utils.format_ts(
             self.registration.registration_ts)
     return collateral
コード例 #26
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
コード例 #27
0
    def __get_renewal_expiry(self):
        """Build a non-repairer's lien expiry date as the sum of previous registrations."""
        if self.life == model_utils.LIFE_INFINITE:
            return 'Never'

        expiry_ts = None
        for registration in self.financing_statement.registration:
            if registration.registration_type_cl in (model_utils.REG_CLASS_CROWN, model_utils.REG_CLASS_MISC,
                                                     model_utils.REG_CLASS_PPSA):
                expiry_ts = model_utils.expiry_dt_from_registration(registration.registration_ts,
                                                                    registration.life)
        for registration in self.financing_statement.registration:
            if registration.registration_type == model_utils.REG_TYPE_RENEWAL and registration.id <= self.id:
                expiry_ts = model_utils.expiry_dt_add_years(expiry_ts, registration.life)

        return model_utils.format_ts(expiry_ts)
コード例 #28
0
    def json(self) -> dict:
        """Return the event tracking record as a json object."""
        event_tracking = {
            'eventTrackingId': self.id,
            'keyId': self.key_id,
            'type': self.event_tracking_type,
            'createDateTime': model_utils.format_ts(self.event_ts)
        }
        if self.status:
            event_tracking['status'] = self.status
        if self.message:
            event_tracking['message'] = self.message
        if self.email_id:
            event_tracking['emailAddress'] = self.email_id

        return event_tracking
コード例 #29
0
    def find_all_by_account_id(cls, account_id: str = None):
        """Return a search history summary list of searches executed by an account."""
        history_list = []
        if account_id:
            query = search_utils.ACCOUNT_SEARCH_HISTORY_DATE_QUERY.replace(
                '?', account_id)
            if search_utils.GET_HISTORY_DAYS_LIMIT <= 0:
                query = search_utils.ACCOUNT_SEARCH_HISTORY_QUERY.replace(
                    '?', account_id)

            result = db.session.execute(query)
            rows = result.fetchall()
            if rows is not None:
                for row in rows:
                    mapping = row._mapping  # pylint: disable=protected-access; follows documentation
                    search_id = str(mapping['id'])
                    # Set to pending if async report is not yet available.
                    callback_url = str(mapping['callback_url'])
                    doc_storage_url = str(mapping['doc_storage_url'])
                    if callback_url is not None and callback_url.lower() != 'none' and \
                            (doc_storage_url is None or doc_storage_url.lower() == 'none'):
                        search_id = REPORT_STATUS_PENDING
                    search = {
                        'searchId':
                        search_id,
                        'searchDateTime':
                        model_utils.format_ts(mapping['search_ts']),
                        'searchQuery':
                        mapping['api_criteria'],
                        'totalResultsSize':
                        int(mapping['total_results_size']),
                        'returnedResultsSize':
                        int(mapping['returned_results_size'])
                    }
                    exact_value = mapping['exact_match_count']
                    if exact_value is not None:
                        search['exactResultsSize'] = int(exact_value)
                    similar_value = mapping['similar_match_count']
                    if similar_value is not None:
                        search['selectedResultsSize'] = (int(similar_value) +
                                                         int(exact_value))
                    else:
                        search['selectedResultsSize'] = int(exact_value)
                    history_list.append(search)

        return history_list
コード例 #30
0
ファイル: test_court_order.py プロジェクト: pwei1018/ppr
def test_court_order_json(session):
    """Assert that the court order model renders to a json format correctly."""
    court_order = CourtOrder(court_order_id=1000,
                             court_name='name',
                             court_registry='registry',
                             file_number='file',
                             effect_of_order='effect',
                             court_date=now_ts())

    court_json = {
        'courtName': court_order.court_name,
        'courtRegistry': court_order.court_registry,
        'fileNumber': court_order.file_number,
        'orderDate': format_ts(court_order.court_date),
        'effectOfOrder': court_order.effect_of_order
    }

    assert court_order.json == court_json