def test_get_application_window(prohib_type: str, date_served: str, today_is: str, min_expected: str, max_expected: str): iso = "%Y-%m-%d" date_served_object = helper.localize_timezone( datetime.strptime(date_served, iso)) today_object = helper.localize_timezone(datetime.strptime(today_is, iso)) prohibition = pro.prohibition_factory(prohib_type) result = prohibition.get_min_max_review_dates(date_served_object, today_object) assert result[0] == helper.localize_timezone( datetime.strptime(min_expected, iso)) assert result[1] == helper.localize_timezone( datetime.strptime(max_expected, iso))
def get_invoice_details(**args) -> tuple: vips_application = args.get('vips_application') vips_data = args.get('vips_data') prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) presentation_type = vips_application['presentationTypeCd'] args['amount_due'] = prohibition.amount_due(presentation_type) args['presentation_type'] = presentation_type args['service_date'] = vips.vips_str_to_datetime( vips_data['noticeServedDt']) args['prohibition'] = prohibition args['notice_type_verbose'] = prohibition.type_verbose() args['applicant_name'] = "{} {}".format(vips_application['firstGivenNm'], vips_application['surnameNm']) return True, args
def force_presentation_type_to_written_if_ineligible_for_oral(**args) -> tuple: """ Only ADP and certain kinds of IRP prohibitions are eligible for an oral review. If the user has requested an oral review when they're not eligible, change the presentation type to written. """ vips_data = args.get('vips_data') presentation_type = args.get('presentation_type') prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) if not prohibition.is_eligible_for_oral_review( vips_data) and presentation_type == 'ORAL': args['force_to_written_review'] = True args['presentation_type'] = 'WRIT' error = "Applicant has selected an oral review but they're not eligible. Changing the presentation_type to WRIT" logging.info(error) return True, args
def has_drivers_licence_been_seized(**args) -> tuple: """ Returns TRUE if VIPS indicates the driver's licence has been seized and the notice type (IRP & ADP) requires the licence to be taken. """ vips_data = args.get('vips_data') prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) if prohibition.DRIVERS_LICENCE_MUST_BE_SEIZED_BEFORE_APPLICATION_ACCEPTED: if vips_data['driverLicenceSeizedYn'] == "Y": return True, args error = 'drivers licence has not been seized' args[ 'error_string'] = "You can't proceed as your driver's licence was not surrendered to police." logging.info(error) return False, args return True, args
def applicant_is_eligible_to_reapply(**args) -> tuple: """ Check that an applicant is eligible to (re)apply. IRP and ADP prohibitions cannot reapply. For UL prohibitions, applicants can reapply if the previous review is complete and wasn't successful. """ failed_list = ['unknown', 'cancelled', 'unsuccessful'] vips_data = args.get('vips_data') prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) if prohibition.CAN_APPLY_FOR_REVIEW_MORE_THAN_ONCE: if 'status' in vips_data['reviews'][0]: # if the previous review was unsuccessful, the UL applicant is eligible to apply again return vips_data['reviews'][0]['status'] in failed_list, args error = 'the applicant not eligible to reapply' logging.info(error) args['error_string'] = "The applicant is not eligible to reapply" return False, args
def is_applicant_within_window_to_apply(**args) -> tuple: """ If the prohibition type is ADP or IRP then check that the date served is no older than 7 days. Prohibitions may not be appealed after 7 days. """ vips_data = args.get('vips_data') today = args.get('today_date') date_served_string = vips_data['noticeServedDt'] date_served = vips_str_to_datetime(date_served_string) prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) if prohibition.is_okay_to_apply(date_served, today): return True, args error = 'the prohibition is older than one week' args[ 'error_string'] = "The Notice of Prohibition was issued more than 7 days ago." logging.info(error) return False, args
def is_applicant_within_window_to_pay(**args) -> tuple: """ If the prohibition type is ADP or IRP then check that the date served is no older than 8 days. Prohibitions may not be appealed after 7 days, but we allow a one-day grace period to pay. """ vips_data = args.get('vips_data') today = args.get('today_date') date_served_string = vips_data['noticeServedDt'] date_served = vips_str_to_datetime(date_served_string) prohibition = pro.prohibition_factory(vips_data['noticeTypeCd']) args['deadline_date_string'] = prohibition.get_deadline_date_string( date_served) logging.info('deadline date string: ' + args.get('deadline_date_string')) if prohibition.is_okay_to_pay(date_served, today): return True, args error = 'the prohibition is older than eight days' args[ 'error_string'] = "The Notice of Prohibition was issued more than 7 days ago." logging.info(error) return False, args
def test_key_prohibition_functions_window(today_is: str, prohibition_type: str, service_date: str, okay_to_apply: str, okay_to_pay: str, min_expected: str, max_expected: str, comments: str): iso = "%Y-%m-%d" date_served_object = helper.localize_timezone( datetime.strptime(service_date, iso)) today_object = helper.localize_timezone(datetime.strptime(today_is, iso)) first_review_date = helper.localize_timezone( datetime.strptime(min_expected, iso)) last_review_date = helper.localize_timezone( datetime.strptime(max_expected, iso)) prohibition = pro.prohibition_factory(prohibition_type) result = prohibition.get_min_max_review_dates(date_served_object, today_object) assert prohibition.is_okay_to_apply( date_served_object, today_object) is (okay_to_apply == "Yes") assert prohibition.is_okay_to_apply(date_served_object, today_object) is (okay_to_pay == "Yes") assert result[0] == first_review_date assert result[1] == last_review_date
def test_prohibition_unknown_factory(): prohibition = pro.prohibition_factory('') assert prohibition is None
def test_prohibition_type_verbose(prohib_type: str, class_expected: str, verbose_type: str): prohibition = pro.prohibition_factory(prohib_type) assert verbose_type == prohibition.type_verbose()
def test_prohibition_factory(prohib_type: str, class_expected: str, verbose_type: str): prohibition = pro.prohibition_factory(prohib_type) assert class_expected in str(prohibition.__class__)
def test_is_oral_review_eligible(prohibition_type: str, original_cause: str, expected): vips_data = {"originalCause": original_cause} prohibition = pro.prohibition_factory(prohibition_type) result = prohibition.is_eligible_for_oral_review(vips_data=vips_data) assert result == expected