def validate_rl(json_data, reg_type: str): """Validate Repairer's Lien.""" error_msg = '' if reg_type != model_utils.REG_TYPE_REPAIRER_LIEN: if 'lienAmount' in json_data and json_data['lienAmount']: error_msg = LA_NOT_ALLOWED if 'surrenderDate' in json_data and json_data['surrenderDate']: error_msg += SD_NOT_ALLOWED return error_msg if 'lienAmount' not in json_data or str( json_data['lienAmount']).strip() == '': error_msg = RL_AMOUNT_REQUIRED if 'surrenderDate' not in json_data or str( json_data['surrenderDate']).strip() == '': error_msg += RL_DATE_REQUIRED else: try: surrender_date = model_utils.ts_from_date_iso_format( json_data['surrenderDate']) if surrender_date: test_date = model_utils.today_ts_offset(21, False) if surrender_date.timestamp() < test_date.timestamp(): error_msg += RL_DATE_INVALID except ValueError: error_msg += RL_DATE_INVALID return error_msg
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
def find_by_search_id(cls, search_id: int, limit_by_date: bool = False): """Return the search detail record matching the search_id.""" search_detail = None error_msg = '' if search_id and not limit_by_date: search_detail = db.session.query(SearchResult).filter( SearchResult.search_id == search_id).one_or_none() elif search_id and limit_by_date: min_allowed_date = model_utils.today_ts_offset( GET_DETAIL_DAYS_LIMIT, False) search_detail = db.session.query(SearchResult).filter( SearchResult.search_id == search_id).one_or_none() if search_detail and search_detail.search and \ search_detail.search.search_ts.timestamp() < min_allowed_date.timestamp(): min_ts = model_utils.format_ts(min_allowed_date) error_msg = f'Search get details search ID {search_id} timestamp too old: must be after {min_ts}.' if error_msg != '': raise BusinessException(error=error_msg, status_code=HTTPStatus.BAD_REQUEST) return search_detail
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