Esempio 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']
Esempio n. 2
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']
Esempio n. 3
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']
Esempio n. 4
0
def test_an_applicant_cannot_submit_evidence_if_they_have_not_applied(client, monkeypatch):

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

    monkeypatch.setattr(routes, "RabbitMQ", mock_rabbitmq)

    response = client.post('/evidence',
                           headers=get_basic_authentication_header(monkeypatch),
                           data=get_evidence_form_data())
    json_data = response.json
    assert response.status_code == 200
    assert "You must apply before you can submit evidence." in json_data['data']['error']
    assert json_data['data']['is_valid'] is False
Esempio n. 5
0
def test_an_applicant_must_have_applied_before_scheduling(client, monkeypatch):
    iso_format = "%Y-%m-%d"

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

    monkeypatch.setattr(routes, "RabbitMQ", mock_rabbitmq)

    response = client.post('/schedule',
                           headers=get_basic_authentication_header(monkeypatch),
                           data=get_evidence_form_data())
    json_data = response.json
    logging.warning(json_data)
    assert response.status_code == 200
    assert json_data['data']['is_success'] is False
    assert json_data['data']['error'] == "You must submit an application before you can schedule."
Esempio n. 6
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']
Esempio n. 7
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']