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
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)
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)
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_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'
def test_pay_bc_date_transformation(pay_bc_date, expected, result): payload = dict() payload['receipt_date'] = pay_bc_date is_success, args = middleware.transform_receipt_date_from_pay_bc_format( payload=payload) date_object = args.get('receipt_date') if is_success: actual = vips.vips_datetime(date_object) assert actual == expected assert is_success == result assert is_success == result
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
def test_an_applicant_can_submit_evidence_happy_path(client, monkeypatch): tz = pytz.timezone('America/Vancouver') review_start_date = vips.vips_datetime(datetime.datetime.now(tz) + datetime.timedelta(days=3)) 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) 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 json_data['data']['is_valid'] is True
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_cannot_submit_evidence_if_the_review_date_is_less_than_48hrs_from_now(client, monkeypatch): iso_format = "%Y-%m-%d" tz = pytz.timezone('America/Vancouver') date_served = (datetime.datetime.now(tz) - datetime.timedelta(days=7)).strftime(iso_format) review_start_date = vips.vips_datetime(datetime.datetime.now(tz) + datetime.timedelta(hours=47)) 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) 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 logging.warning("review start date and time: {}".format(review_start_date)) assert response.status_code == 200 assert "You can't submit evidence less than 48 hours before your review." in json_data['data']['error'] assert json_data['data']['is_valid'] is False
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']
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']