Exemplo n.º 1
0
def test_an_unlicenced_applicant_that_applies_using_incorrect_last_name_gets_appropriate_email(
):
    date_served = "2020-09-23"
    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_has_never_applied(
                      "UL", date_served, "Wrong"),
                  status=404,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission("UL")

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Prohibition Number or Name Don't Match - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "You can re-apply at any time." in email_payload['body']
Exemplo n.º 2
0
def test_if_no_disclosure_add_back_to_hold_queue(monkeypatch):
    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/disclosure_payload.json')
    message_dict['hold_until'] = (datetime.datetime.now() -
                                  datetime.timedelta(hours=1)).isoformat()
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) - datetime.timedelta(days=1))

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_with_no_disclosure(
                      "IRP", review_start_date),
                  status=200,
                  match_querystring=True)

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"

    monkeypatch.setattr(Config, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)
Exemplo n.º 3
0
def test_an_unlicenced_applicant_that_had_a_successful_review_cannot_apply_again(
):

    responses.add(
        responses.GET,
        '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL, "21999344",
                                 "21999344"),
        json=vips_mock.status_previously_applied_review_successful("UL"),
        status=200,
        match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission("UL")

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Previous Review on File – Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
Exemplo n.º 4
0
def test_when_an_applicants_review_has_concluded_the_disclosure_event_is_deleted(
        monkeypatch):
    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/disclosure_payload.json')
    message_dict['hold_until'] = (datetime.datetime.now() -
                                  datetime.timedelta(hours=1)).isoformat()
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) - datetime.timedelta(days=1))

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_applied_paid_and_scheduled(
                      "IRP", review_start_date),
                  status=200,
                  match_querystring=True)

    def mock_any_disclosure(*args, **kwargs):
        # We should never call this method
        assert False

    monkeypatch.setattr(middleware, "is_any_unsent_disclosure",
                        mock_any_disclosure)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)
Exemplo n.º 5
0
def test_a_successful_applicant_gets_an_application_accepted_email(
        prohib, monkeypatch):
    date_served = "2021-02-19"

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_has_never_applied(prohib, date_served),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/{}/{}/application/{}'.format(Config.VIPS_API_ROOT_URL,
                                                   prohib, "21999344",
                                                   "21999344"),
                  json={},
                  status=200)

    responses.add(responses.POST,
                  "{}:{}/services/collector".format(Config.SPLUNK_HOST,
                                                    Config.SPLUNK_PORT),
                  status=200)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    def mock_datetime_now(**args):
        args['today_date'] = helper.localize_timezone(
            datetime.datetime.strptime("2021-02-23", "%Y-%m-%d"))
        return True, args

    monkeypatch.setattr(middleware, "determine_current_datetime",
                        mock_datetime_now)
    message_dict = get_sample_application_submission(prohib)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[4].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Application Accepted - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "Your application for a review of driving prohibition 21999344 has been accepted." in email_payload[
        'body']
    assert "You must pay in full by credit card by February 27, 2021" in email_payload[
        'body']
    assert "If you don't pay by February 27, 2021, your review will not go ahead." in email_payload[
        'body']
    assert "http://link-to-paybc" in email_payload['body']
Exemplo n.º 6
0
def test_when_one_document_not_disclosed_one_document_is_emailed_to_applicant(
        monkeypatch):
    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/disclosure_payload.json')
    message_dict['hold_until'] = (datetime.datetime.now() -
                                  datetime.timedelta(hours=1)).isoformat()
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) + datetime.timedelta(days=2))

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_with_one_sent_on_unsent_disclosure(
                      "IRP", review_start_date),
                  status=200,
                  match_querystring=True)

    responses.add(responses.GET,
                  '{}/{}/disclosure/{}'.format(Config.VIPS_API_ROOT_URL, "111",
                                               "20123456"),
                  json=vips_mock.disclosure_get(),
                  status=200,
                  match_querystring=True)

    responses.add(responses.PATCH,
                  '{}/disclosure/{}'.format(Config.VIPS_API_ROOT_URL,
                                            "20123456"),
                  json=vips_mock.disclosure_get(),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"sample": "test"},
                  status=200)

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    monkeypatch.setattr(Config, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)

    email_payload = json.loads(responses.calls[3].request.body.decode())
    assert '*****@*****.**' in email_payload['to']
    assert len(email_payload['attachments']) == 1
def test_application_form_received(prohibition_type, date_served, today_is,
                                   seized, last_name, is_valid, is_applied,
                                   email_text, monkeypatch):
    def mock_status_get(*args, **kwargs):
        print('inside mock_status_get()')
        is_response_successful, data = status_gets(is_valid == "True",
                                                   prohibition_type,
                                                   date_served, last_name,
                                                   seized, "N/A", is_applied)
        if is_response_successful and 'resp' in data:
            return True, data
        return False, dict({})

    def mock_send_email(*args, **kwargs):
        print('inside mock_send_email()')
        assert "*****@*****.**" in args[0]
        print("Subject: {}".format(args[1]))
        assert email_text in args[3]
        return True

    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 mock_application_save(**args):
        print('inside mock_application_save()')
        return True, args

    def mock_add_to_hold(**args):
        print('inside mock_add_to_hold()')
        return True, args

    monkeypatch.setattr(actions, "add_to_hold_queue", mock_add_to_hold)
    monkeypatch.setattr(middleware, "determine_current_datetime",
                        mock_datetime_now)
    monkeypatch.setattr(middleware, "save_application_to_vips",
                        mock_application_save)
    monkeypatch.setattr(vips, "status_get", mock_status_get)
    monkeypatch.setattr(common_email_services, "send_email", mock_send_email)

    message_dict = helper.load_json_into_dict(
        'python/tests/sample_data/form/irp_form_submission.json')

    # For the prohibition_not_found and the prohibition_not_found_yet emails, we rely on users entering
    # correct prohibition number prefix to determine the correct letter type.
    if prohibition_type == "UL":
        message_dict['prohibition_review']['form']['prohibition-information'][
            'control-is-ul'] = "true"
        message_dict['prohibition_review']['form']['prohibition-information'][
            'control-is-irp'] = "false"

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)
Exemplo n.º 8
0
def test_disclosure_event_processing(
        prohibition_type, today_is, review_start_date, is_valid, disclosure, attachments_expected, monkeypatch):

    def mock_status_get(*args, **kwargs):
        print('inside mock_status_get()')
        return status_gets(is_valid == "True", prohibition_type, review_start_date, disclosure)

    def mock_send_email(*args, **kwargs):
        print('inside mock_send_email()')
        assert "*****@*****.**" in args[0]
        print("Subject: {}".format(args[1]))
        return True

    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 mock_add_to_hold(**args):
        print("inside mock_add_to_hold")
        return True, args

    def mock_disclosure_get(*args):
        print("inside mock_disclosure_get()")
        data = dict({
                "resp": "success",
                "data": {
                    "document": {
                        "document": "base64_string_of_encoded_document",
                        "mimeType": "application/pdf"
                    }
                }
            })
        return True, data

    def mock_patch(*args):
        return True, dict({})

    monkeypatch.setattr(middleware, "determine_current_datetime", mock_datetime_now)
    monkeypatch.setattr(vips, "status_get", mock_status_get)
    monkeypatch.setattr(vips, "patch", mock_patch)
    monkeypatch.setattr(common_email_services, "send_email", mock_send_email)
    monkeypatch.setattr(actions, "add_to_hold_queue", mock_add_to_hold)
    monkeypatch.setattr(vips, "disclosure_get", mock_disclosure_get)

    message_dict = helper.load_json_into_dict('python/tests/sample_data/form/disclosure_payload.json')

    results = helper.middle_logic(helper.get_listeners(business.process_incoming_form(), message_dict['event_type']),
                        message=message_dict,
                        config=Config,
                        writer=None)

    if attachments_expected > 0:
        assert 'disclosure_for_applicant' in results
        assert len(results.get('disclosure_for_applicant')) == attachments_expected
    else:
        assert 'disclosure_for_applicant' not in results
Exemplo n.º 9
0
def test_an_applicant_that_was_served_7_days_ago_but_not_in_vips_gets_still_not_found_email(
        prohib, monkeypatch):
    def mock_datetime_now(**args):
        args['today_date'] = helper.localize_timezone(
            datetime.datetime.strptime("2020-09-29", "%Y-%m-%d"))
        print('inside mock_datetime_now: {}'.format(args.get('today_date')))
        return True, args

    def mock_add_to_hold(**args):
        print('inside mock_add_to_hold()')
        return True, args

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344", "21999344"),
                  json=vips_mock.status_not_found(),
                  status=404,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    monkeypatch.setattr(actions, "add_to_hold_queue", mock_add_to_hold)
    monkeypatch.setattr(middleware, "determine_current_datetime",
                        mock_datetime_now)
    message_dict = get_sample_application_submission(prohib)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Prohibition Still Not Found - Driving Prohibition 21-999344" in email_payload[
        'subject']
    assert "If it's not in our system by the next time we check, your online" in email_payload[
        'body']
    assert "You can't get a review extension if you miss the deadline" in email_payload[
        'body']
    assert "http://link-to-icbc" in email_payload['body']
    assert "http://link-to-service-bc" in email_payload['body']
Exemplo n.º 10
0
def test_an_unlicenced_successful_applicant_gets_an_application_accepted_email(
):
    date_served = (datetime.datetime.now() -
                   datetime.timedelta(days=6)).strftime("%Y-%m-%d")
    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_has_never_applied("UL", date_served),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/{}/{}/application/{}'.format(Config.VIPS_API_ROOT_URL,
                                                   "UL", "21999344",
                                                   "21999344"),
                  json={},
                  status=200)

    responses.add(responses.POST,
                  "{}:{}/services/collector".format(Config.SPLUNK_HOST,
                                                    Config.SPLUNK_PORT),
                  status=200)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission("UL")

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[4].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Application Accepted - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "Your application for a review of driving prohibition 21999344 has been accepted." in email_payload[
        'body']
    assert "You must pay in full by credit card within 7 days of applying for this review." in email_payload[
        'body']
    assert "http://link-to-paybc" in email_payload['body']
Exemplo n.º 11
0
def test_an_unlicenced_applicant_that_has_previously_applied_gets_application_accepted(
):
    """
    UL applicants can apply multiple times, other prohibition types can only apply once
    """

    responses.add(
        responses.GET,
        '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL, "21999344",
                                 "21999344"),
        json=vips_mock.status_previously_applied_review_unsuccessful("UL"),
        status=200,
        match_querystring=True)

    responses.add(responses.POST,
                  '{}/{}/{}/application/{}'.format(Config.VIPS_API_ROOT_URL,
                                                   "UL", "21999344",
                                                   "21999344"),
                  json={},
                  status=200)

    responses.add(responses.POST,
                  "{}:{}/services/collector".format(Config.SPLUNK_HOST,
                                                    Config.SPLUNK_PORT),
                  status=200)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission("UL")

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[4].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Application Accepted - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
Exemplo n.º 12
0
def test_verify_schedule_event_that_has_not_reached_the_hold_until_datetime_is_placed_back_on_hold(
        monkeypatch):
    future_date = datetime.datetime.now() + datetime.timedelta(hours=1)
    message_dict = get_verify_schedule_event(future_date)

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    monkeypatch.setattr(BaseConfig, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=BaseConfig,
                                  writer=RabbitMQ)
Exemplo n.º 13
0
    def callback(self, ch, method, properties, body):
        # convert body (in bytes) to string
        message_dict = decode_message(body, self.config.ENCRYPT_KEY)

        logging.info("callback() invoked: {}".format(json.dumps(message_dict)))
        helper.middle_logic(helper.get_listeners(
            business.process_incoming_form(), message_dict['event_type']),
                            message=message_dict,
                            config=self.config,
                            writer=self.writer)

        # Regardless of whether the process above follows the happy path or not,
        # we need to acknowledge receipt of the message to RabbitMQ below. This
        # acknowledgement deletes it from the queue. The logic above
        # must have saved / handled the message before we get here.

        ch.basic_ack(delivery_tag=method.delivery_tag)
Exemplo n.º 14
0
def test_applicant_sent_email_confirming_evidence_received(monkeypatch):
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) + datetime.timedelta(days=1))

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_applied_paid_and_scheduled(
                      "IRP", review_start_date),
                  status=200,
                  match_querystring=True)

    responses.add(responses.GET,
                  '{}/{}/application/{}'.format(
                      Config.VIPS_API_ROOT_URL,
                      "bb71037c-f87b-0444-e054-00144ff95452", "20123456"),
                  json=vips_mock.application_get(),
                  status=200)

    def mock_send_email(*args, **kwargs):
        print('inside mock_send_email()')
        assert "*****@*****.**" in args[0]
        print("Subject: {}".format(args[1]))
        assert "Evidence Received - Driving Prohibition 20-123456 Review" in args[
            3]
        assert "we received the evidence that will be considered for your review." in args[
            3]
        assert "http://link-to-evidence-form" in args[3]
        return True

    monkeypatch.setattr(common_email_services, "send_email", mock_send_email)

    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/document_submission.json')

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    if "error_string" in results:
        print(results.get('error_string'))
    assert 'error_string' not in results
def test_an_applicant_that_was_served_recently_and_where_prohibition_is_not_in_vips_gets_not_yet_email(
        monkeypatch):
    def mock_status_get(*args, **kwargs):
        return True, dict({
            "resp": "fail",
            "error": {
                "message": "Record not found",
                "httpStatus": 404
            }
        })

    def mock_send_email(*args, **kwargs):
        template_content = args[3]
        print('inside mock_send_email()')
        assert "*****@*****.**" in args[0]
        print("Subject: {}".format(args[1]))
        assert "issued on September 22, 2020 isn't in our" in template_content
        return True

    def mock_datetime_now(**args):
        args['today_date'] = helper.localize_timezone(
            datetime.datetime.strptime("2020-09-23", "%Y-%m-%d"))
        print('inside mock_datetime_now: {}'.format(args.get('today_date')))
        return True, args

    def mock_add_to_hold(**args):
        print('inside mock_add_to_hold()')
        return True, args

    monkeypatch.setattr(actions, "add_to_hold_queue", mock_add_to_hold)
    monkeypatch.setattr(middleware, "determine_current_datetime",
                        mock_datetime_now)
    monkeypatch.setattr(vips, "status_get", mock_status_get)
    monkeypatch.setattr(common_email_services, "send_email", mock_send_email)

    message_dict = helper.load_json_into_dict(
        'python/tests/sample_data/form/irp_form_submission.json')

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)
Exemplo n.º 16
0
def test_disclosure_that_has_not_reached_the_hold_until_datetime_is_placed_back_on_hold(
        monkeypatch):
    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/disclosure_payload.json')
    message_dict['hold_until'] = (datetime.datetime.now() +
                                  datetime.timedelta(hours=1)).isoformat()

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    monkeypatch.setattr(Config, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)
Exemplo n.º 17
0
def test_evidence_form_received(prohibition_type, date_served, today_is,
                                seized, last_name, is_valid, is_applied,
                                email_text, monkeypatch):
    def mock_status_get(*args, **kwargs):
        print('inside mock_status_get()')
        return status_gets(is_valid == "True", prohibition_type, date_served,
                           last_name, seized, "N/A", is_applied)

    def mock_application_get(*args, **kwargs):
        print('inside mock_application_get()')
        return application_get()

    def mock_send_email(*args, **kwargs):
        print('inside mock_send_email()')
        assert "*****@*****.**" in args[0]
        print("Subject: {}".format(args[1]))
        assert email_text in args[3]
        return True

    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

    monkeypatch.setattr(middleware, "determine_current_datetime",
                        mock_datetime_now)
    monkeypatch.setattr(vips, "status_get", mock_status_get)
    monkeypatch.setattr(vips, "application_get", mock_application_get)
    monkeypatch.setattr(common_email_services, "send_email", mock_send_email)

    message_dict = helper.load_json_into_dict(
        'python/tests/sample_data/form/document_submission.json')

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    if "error_string" in results:
        print(results.get('error_string'))
    assert 'error_string' not in results
Exemplo n.º 18
0
def test_an_irp_applicant_that_applies_at_icbc_gets_already_applied_email():
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) + datetime.timedelta(days=2))
    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_applied_at_icbc(
                      "IRP", review_start_date),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission("IRP")

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Dear Applicant," in email_payload['body']
    assert "Applied at ICBC - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "Our records show that an application to review prohibition 21999344" in email_payload[
        'body']
    assert "has been paid and scheduled at ICBC" in email_payload['body']
    assert "Please do not respond to this email." in email_payload['body']
Exemplo n.º 19
0
def test_an_applicant_without_a_valid_prohibition_gets_appropriate_email(
        prohib, monkeypatch):
    """
    Applicant gets the "Not Found" email if the date served (as entered by the applicant)
    has allowed sufficient time for the prohibition to be entered into VIPS
    """

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_not_found(),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission(prohib)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Prohibition Not Found and 7-day Application Window Missed - Driving Prohibition 21-999344 Review" in email_payload[
        'subject']
    assert "Your application for a review of the prohibition can't be accepted." in email_payload[
        'body']
Exemplo n.º 20
0
def test_an_applicant_that_has_missed_the_window_to_apply_gets_appropriate_email(
        prohib, monkeypatch):
    tz = pytz.timezone('America/Vancouver')
    date_served = (datetime.datetime.now(tz) -
                   datetime.timedelta(days=8)).strftime("%Y-%m-%d")

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_has_never_applied(prohib, date_served),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission(prohib)
    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "7-day Application Window Missed - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "Your application for a review of driving prohibition 21999344 can't be accepted." in email_payload[
        'body']
    assert "Our records show your Notice of Prohibition was issued more than 7 days ago." in email_payload[
        'body']
Exemplo n.º 21
0
def test_verify_schedule_event_sends_email_to_business_if_applicant_has_not_scheduled(
        monkeypatch):
    past_date = datetime.datetime.now() - datetime.timedelta(hours=1)
    message_dict = get_verify_schedule_event(past_date)
    business_email_address = "*****@*****.**"

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(BaseConfig.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_applied_and_paid_not_scheduled("IRP"),
                  status=200,
                  match_querystring=True)

    def mock_send_business_email(*args, **kwargs):
        assert "Did Not Schedule - Driving Prohibition 20-123456 Review" in args[
            0]
        assert "Appeals Registry," in args[2]
        assert "Charlie Brown, the applicant of prohibition 20123456," in args[
            2]
        assert "did not schedule the review within 24 hours of payment." in args[
            2]
        assert "Number: ABCD-1234" in args[2]
        assert "Amount: 50.00" in args[2]
        assert "Date: 2020-10-22" in args[2]
        assert "Order Number: 1010100" in args[2]
        return True

    monkeypatch.setattr(BaseConfig, "BCC_EMAIL_ADDRESSES",
                        business_email_address)
    monkeypatch.setattr(common_email, "send_to_business",
                        mock_send_business_email)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=BaseConfig,
                                  writer=RabbitMQ)
Exemplo n.º 22
0
def test_an_irp_or_adp_applicant_that_has_previously_applied_gets_appropriate_email(
        prohib, monkeypatch):
    date_served = datetime.datetime.now().strftime("%Y-%m-%d")
    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_applied_not_paid(prohib, date_served),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission(prohib)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Already Applied – Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "An application to review prohibition 21999344 has already been submitted." in email_payload[
        'body']
    assert "You must call to make changes to your application." in email_payload[
        'body']
Exemplo n.º 23
0
def test_an_applicant_that_has_not_surrendered_their_licence_gets_appropriate_email(
        prohib, monkeypatch):
    date_served = datetime.datetime.now().strftime("%Y-%m-%d")

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "21999344", "21999344"),
                  json=vips_mock.status_has_never_applied(
                      prohib, date_served, "Gordon", "N"),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"response": "ignored"},
                  status=200)

    message_dict = get_sample_application_submission(prohib)
    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=None)

    email_payload = json.loads(responses.calls[2].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Licence Not Surrendered - Driving Prohibition 21-999344 Review" == email_payload[
        'subject']
    assert "You're ineligible to apply online because your licence wasn't surrendered" in email_payload[
        'body']
Exemplo n.º 24
0
def test_verify_schedule_check_placed_back_on_hold_if_vips_not_available(
        monkeypatch):
    past_date = datetime.datetime.now() + datetime.timedelta(hours=1)
    message_dict = get_verify_schedule_event(past_date)

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(BaseConfig.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_returns_html_response(),
                  status=200,
                  match_querystring=True)

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    monkeypatch.setattr(BaseConfig, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=BaseConfig,
                                  writer=RabbitMQ)
Exemplo n.º 25
0
def test_verify_no_email_sent_to_business_if_applicant_scheduled(monkeypatch):
    past_date = datetime.datetime.now() - datetime.timedelta(hours=1)
    message_dict = get_verify_schedule_event(past_date)

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(BaseConfig.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_applied_paid_and_scheduled(
                      "IRP", "2021-03-24 12:00:00 -0700"),
                  status=200,
                  match_querystring=True)

    def mock_send_business_email(*args, **kwargs):
        # this method should never be called
        assert False

    monkeypatch.setattr(common_email, "send_to_business",
                        mock_send_business_email)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=BaseConfig,
                                  writer=RabbitMQ)
Exemplo n.º 26
0
def test_disclosure_email_template_has_unique_text_for_ul_prohibitions(
        monkeypatch):
    message_dict = helper.load_json_into_dict(
        'python/common/tests/sample_data/form/disclosure_payload.json')
    message_dict['hold_until'] = (datetime.datetime.now() -
                                  datetime.timedelta(hours=1)).isoformat()
    tz = pytz.timezone('America/Vancouver')
    review_start_date = vips.vips_datetime(
        datetime.datetime.now(tz) + datetime.timedelta(days=2))

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL,
                                           "20123456", "20123456"),
                  json=vips_mock.status_with_two_unsent_disclosures(
                      "UL", review_start_date),
                  status=200,
                  match_querystring=True)

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    #
    # def mock_send_email(*args, **kwargs):
    #     print('inside mock_send_email()')
    #     assert "*****@*****.**" in args[0]
    #     assert "Disclosure Documents Attached - Driving Prohibition 20-123456 Review" in args[1]
    #     assert "Attached is the police evidence the RoadSafetyBC adjudicator will consider in your review." in args[3]
    #     assert '<a href="http://localhost">get a copy from ICBC</a>' in args[3]
    #     return True

    responses.add(responses.GET,
                  '{}/{}/disclosure/{}'.format(Config.VIPS_API_ROOT_URL, "111",
                                               "20123456"),
                  json=vips_mock.disclosure_get(),
                  status=200,
                  match_querystring=True)

    responses.add(responses.GET,
                  '{}/{}/disclosure/{}'.format(Config.VIPS_API_ROOT_URL, "222",
                                               "20123456"),
                  json=vips_mock.disclosure_get(),
                  status=200,
                  match_querystring=True)

    responses.add(responses.PATCH,
                  '{}/disclosure/{}'.format(Config.VIPS_API_ROOT_URL,
                                            "20123456"),
                  json=dict({}),
                  status=200,
                  match_querystring=True)

    responses.add(responses.POST,
                  '{}/realms/{}/protocol/openid-connect/token'.format(
                      Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM),
                  json={"access_token": "token"},
                  status=200)

    responses.add(responses.POST,
                  '{}/api/v1/email'.format(Config.COMM_SERV_API_ROOT_URL),
                  json={"sample": "test"},
                  status=200)

    monkeypatch.setattr(Config, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    results = helper.middle_logic(helper.get_listeners(
        business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)

    email_payload = json.loads(responses.calls[4].request.body.decode())
    assert '*****@*****.**' in email_payload['to']
    assert email_payload[
        'subject'] == "Disclosure Documents Attached - Driving Prohibition 20-123456 Review"
    assert "Attached is the police evidence the RoadSafetyBC adjudicator will consider in your review." in email_payload[
        'body']
    assert '<a href="http://localhost">get a copy from ICBC</a>' in email_payload[
        'body']
def test_an_applicant_can_schedule_a_written_review(monkeypatch):
    today = "2020-09-23"
    payment_date = "2020-12-05"
    application_id = "bb71037c-f87b-0444-e054-00144ff95452"
    prohibtion_num = "21900040"
    time_slot = vips.encode_time_slot({
                "reviewStartDtm": "2020-12-09 11:00:00 -08:00",
                "reviewEndDtm": "2020-12-09 11:30:00 -08:00",
            })

    responses.add(responses.GET,
                  '{}/{}/status/{}'.format(Config.VIPS_API_ROOT_URL, prohibtion_num, prohibtion_num, prohibtion_num),
                  json=vips_mock.status_applied_and_paid_not_scheduled("IRP"),
                  status=200, match_querystring=True)

    responses.add(responses.GET,
                  '{}/{}/payment/status/{}'.format(
                      Config.VIPS_API_ROOT_URL, application_id , prohibtion_num),
                  json=vips_mock.payment_get(payment_date),
                  status=200)

    responses.add(responses.GET,
                  '{}/{}/application/{}'.format(
                      Config.VIPS_API_ROOT_URL, application_id, prohibtion_num),
                  json=vips_mock.application_get("WRIT"),
                  status=200)

    responses.add(responses.POST,
                  '{}/{}/review/schedule/{}'.format(
                      Config.VIPS_API_ROOT_URL, application_id, prohibtion_num),
                  json={"timeSlot": time_slot},
                  status=201)

    responses.add(responses.POST, "{}:{}/services/collector".format(
        Config.SPLUNK_HOST, Config.SPLUNK_PORT), status=200)

    responses.add(responses.POST, '{}/realms/{}/protocol/openid-connect/token'.format(
        Config.COMM_SERV_AUTH_URL, Config.COMM_SERV_REALM), json={"access_token": "token"}, status=200)

    responses.add(responses.POST, '{}/api/v1/email'.format(
        Config.COMM_SERV_API_ROOT_URL), json={"response": "ignored"}, status=201)

    def mock_datetime_now(**args):
        args['today_date'] = helper.localize_timezone(datetime.datetime.strptime(today, "%Y-%m-%d"))
        print('inside mock_datetime_now: {}'.format(args.get('today_date')))
        return True, args

    def mock_publish(queue_name: str, payload: bytes):
        assert queue_name == "DF.hold"
        return True

    monkeypatch.setattr(BaseConfig, "ENCRYPT_KEY", "something-secret")
    monkeypatch.setattr(RabbitMQ, "publish", mock_publish)

    monkeypatch.setattr(middleware, "determine_current_datetime", mock_datetime_now)
    message_dict = get_sample_schedule_review_submission("21999344", "Gordon", time_slot)

    results = helper.middle_logic(helper.get_listeners(business.process_incoming_form(), message_dict['event_type']),
                                  message=message_dict,
                                  config=Config,
                                  writer=RabbitMQ)

    email_payload = json.loads(responses.calls[6].request.body.decode())
    assert "*****@*****.**" in email_payload['to']
    assert "Review Date Confirmed - Driving Prohibition 21-900040 Review" in email_payload['subject']
    assert "We can only change the review date or time in special situations." in email_payload['body']
    assert "Your written review has been scheduled for:" in email_payload['body']
    assert "Wed, Dec 9, 2020 at 9:30AM (Pacific Time)" in email_payload['body']