示例#1
0
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))
示例#2
0
def applicant_prohibition_not_found_yet(**args):
    config = args.get('config')
    prohibition_number = args.get('prohibition_number')
    date_served_string = args.get('date_of_service')
    date_served = helper.localize_timezone(datetime.strptime(date_served_string, '%Y-%m-%d'))
    human_friendly_date_served = date_served.strftime("%B %d, %Y")
    notice_type = args.get('user_entered_notice_type')
    t = "{}_prohibition_not_found_yet.html".format(notice_type)
    args['email_template'] = t
    content = get_email_content(t, prohibition_number)
    template = get_jinja2_env().get_template(t)

    # Note: we rely on the date_served as submitted by the user -- not the date in VIPS
    # Check to see if enough time has elapsed to enter the prohibition into VIPS
    return common_email_services.send_email(
        [args.get('applicant_email_address')],
        content["subject"],
        config,
        template.render(
            link_to_icbc=config.LINK_TO_ICBC,
            link_to_service_bc=config.LINK_TO_SERVICE_BC,
            date_of_service=human_friendly_date_served,
            full_name=args.get('driver_full_name'),
            prohibition_number=prohibition_number,
            subject=content["subject"])), args
def test_is_requested_time_slot_okay(min_review_date, max_review_date,
                                     requested_start_datetime, expected):
    iso = "%Y-%m-%d"
    min_review = localize_timezone(datetime.strptime(min_review_date, iso))
    max_review = localize_timezone(datetime.strptime(max_review_date, iso))
    timeslot = dict({
        "reviewStartDtm": requested_start_datetime + " -07:00",
        "reviewEndDtm": 'this attribute ignored in this test'
    })
    response, args = middleware.is_selected_timeslot_inside_schedule_window(
        min_review_date=min_review,
        max_review_date=max_review,
        requested_time_slot=timeslot)
    print("{} | {} | {}".format(min_review.isoformat(), max_review.isoformat(),
                                requested_start_datetime))
    assert response is expected
示例#4
0
def test_prohibition_served_within_past_week_method(
        number_of_days_before_today, expected):
    today_unaware = datetime.strptime("2021-02-11", "%Y-%m-%d")
    date_served = (
        today_unaware -
        timedelta(days=number_of_days_before_today)).strftime("%Y-%m-%d")
    today_date = localize_timezone(today_unaware)
    result, args = middleware.prohibition_served_within_past_week(
        today_date=today_date, date_of_service=date_served, config=Config)
    assert result is expected
示例#5
0
def test_applicant_has_more_than_one_day_to_apply(number_of_days_before_today,
                                                  expected):
    today_unaware = datetime.strptime("2021-02-11", "%Y-%m-%d")
    date_served = (
        today_unaware -
        timedelta(days=number_of_days_before_today)).strftime("%Y-%m-%d")
    today_date = localize_timezone(today_unaware)
    result, args = middleware.applicant_has_more_than_one_day_to_apply(
        today_date=today_date, date_of_service=date_served, config=Config)
    assert result is expected
示例#6
0
 def test_datetime_to_vips_string():
     tz = pytz.timezone('America/Vancouver')
     date_under_test = localize_timezone(
         datetime.strptime("2020-11-22", "%Y-%m-%d"))
     vips_date_string = vips.vips_datetime(date_under_test)
     components = vips_date_string.split(":")
     print(date_under_test.strftime("%z"))
     print(vips_date_string)
     assert len(components) == 4
     assert vips_date_string[0:22] == '2020-11-22 00:00:00 -0'
示例#7
0
def status_with_one_sent_on_unsent_disclosure(prohibition_type,
                                              review_start_date: str) -> dict:
    data = json.loads(
        json.dumps(
            status_applied_paid_and_scheduled(prohibition_type,
                                              review_start_date)))  # deep copy
    yesterday = help.localize_timezone(datetime.today()) - timedelta(days=1)
    del data['data']['status']['disclosure'][0]['disclosedDtm']
    data['data']['status']['disclosure'][1][
        'disclosedDtm'] = vips.vips_datetime(yesterday)
    return data
示例#8
0
def test_date_served_not_older_than_one_week_method(prohibition_type,
                                                    notice_serve_date,
                                                    today_is, expected):
    today_unaware = datetime.strptime(today_is + " 00:00:00",
                                      "%Y-%m-%d %H:%M:%S")
    today_date = localize_timezone(today_unaware)
    vips_data = dict()
    vips_data['noticeTypeCd'] = prohibition_type
    vips_data['noticeServedDt'] = notice_serve_date + " 00:00:00 -08:00"
    (result, args) = middleware.is_applicant_within_window_to_apply(
        vips_data=vips_data, today_date=today_date)
    assert result is expected
示例#9
0
def status_with_two_disclosures_sent_last_month(
        prohibition_type, review_start_date: str) -> dict:
    data = json.loads(
        json.dumps(
            status_applied_paid_and_scheduled(prohibition_type,
                                              review_start_date)))  # deep copy
    last_month = help.localize_timezone(datetime.today() - timedelta(days=35))
    data['data']['status']['disclosure'][0][
        'disclosedDtm'] = vips.vips_datetime(last_month)
    data['data']['status']['disclosure'][1][
        'disclosedDtm'] = vips.vips_datetime(last_month)
    return data
示例#10
0
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
示例#11
0
def _recently_served(delay_days: int, **args) -> tuple:
    date_served_string = args.get('date_of_service')

    # Note: we have to rely on the date_served as submitted by the user -- not the date in VIPS
    # Check to see if enough time has elapsed to enter the prohibition into VIPS
    today = args.get('today_date')
    date_served = helper.localize_timezone(
        datetime.strptime(date_served_string, '%Y-%m-%d'))
    very_recently_served = (today - date_served).days < delay_days
    if very_recently_served:
        return True, args
    error = 'prohibition not served within the past {} days'.format(delay_days)
    args['error_string'] = error
    logging.info(error)
    logging.debug("date_served: {}, very_recently_served: {}".format(
        date_served, very_recently_served))
    return False, args
示例#12
0
def applicant_evidence_received(**args) -> tuple:
    config = args.get('config')
    prohibition_number = args.get('prohibition_number')
    email_address = args.get('email_address')
    vips_application = args.get('vips_application')
    full_name = "{} {}".format(vips_application['firstGivenNm'], vips_application['surnameNm'])
    t = 'evidence_received.html'
    args['email_template'] = t
    content = get_email_content(t, prohibition_number)
    template = get_jinja2_env().get_template(t)
    return common_email_services.send_email(
        [email_address],
        content["subject"],
        config,
        template.render(
            link_to_evidence_form=config.LINK_TO_EVIDENCE_FORM,
            full_name=full_name,
            today_date=helper.localize_timezone(datetime.now()).strftime("%B %d, %Y %H:%M:%S"),
            prohibition_number=prohibition_number,
            subject=content["subject"])), args
示例#13
0
def prohibition_served_recently(**args) -> tuple:
    """
    Returns TRUE if the prohibition was served within the previous 3 days;
    otherwise returns FALSE
    """
    date_served_string = args.get('date_of_service')
    config = args.get('config')
    delay_days = int(config.DAYS_TO_DELAY_FOR_VIPS_DATA_ENTRY)

    # Note: we have to rely on the date_served as submitted by the user -- not the date in VIPS
    # Check to see if enough time has elapsed to enter the prohibition into VIPS
    today = args.get('today_date')
    date_served = helper.localize_timezone(
        datetime.strptime(date_served_string, '%Y-%m-%d'))
    very_recently_served = (today - date_served).days < delay_days
    if very_recently_served:
        return True, args
    error = 'prohibition not served within the past {} days'.format(delay_days)
    args['error_string'] = error
    logging.info(error)
    print("date_served: {}, very_recently_served: {}".format(
        date_served, very_recently_served))
    return False, args
示例#14
0
 def mock_datetime_now(**args):
     args['today_date'] = helper.localize_timezone(
         datetime.datetime.strptime(today_is, "%Y-%m-%d"))
     print('inside mock_datetime_now: {}'.format(args.get('today_date')))
     return True, args
def test_prohibition_served_recently_method(today_is, date_served, expected):
    today_unaware = datetime.strptime(today_is, "%Y-%m-%d")
    today_date = localize_timezone(today_unaware)
    result, args = middleware.prohibition_served_recently(
        today_date=today_date, date_of_service=date_served, config=Config)
    assert result is expected
示例#16
0
 def mock_datetime_now(**args):
     args['today_date'] = helper.localize_timezone(
         datetime.datetime.strptime("2021-02-23", "%Y-%m-%d"))
     return True, args