def test_send_email_with_icn(notification_url, service_id, service_test_api_key, template_id): service_jwt = encode_jwt(service_id, service_test_api_key) email_response = send_email_with_icn(notification_url, service_jwt, template_id) assert email_response.status_code == 201 notification_id = get_notification_id(email_response) desired_status = 'delivered' notification_status_response = wait_for_status(notification_id, notification_url, service_id, service_test_api_key, desired_status) assert notification_status_response['status'] == desired_status assert notification_status_response['email_address'] is not None assert notification_status_response['sent_by'] is not None found_va_profile_ids = [ identifier for identifier in notification_status_response['recipient_identifiers'] if identifier['id_type'] == 'VAPROFILEID' ] assert len(found_va_profile_ids) == 1
def test_send_email(notification_url, service_id, service_api_key, template_id): service_jwt = encode_jwt(service_id, service_api_key) email_response = send_email_with_email_address(notification_url, service_jwt, template_id) assert email_response.status_code == 201 notification_id = get_notification_id(email_response) time_count = 0 notification_status = "" notification_sent_by = None while notification_status != "sending" and time_count < 30: service_jwt = encode_jwt(service_id, service_api_key) notification_status_response = get_notification_status( notification_id, notification_url, service_jwt) assert notification_status_response.status_code == 200 notification_status = notification_status_response.json()['status'] notification_sent_by = notification_status_response.json()['sent_by'] time.sleep(1) time_count = time_count + 1 assert notification_status == 'sending' assert notification_sent_by is not None
def test_send_email(notification_url, service_id, service_api_key, template_id): service_jwt = encode_jwt(service_id, service_api_key) email_response = send_email_with_email_address(notification_url, service_jwt, template_id) assert email_response.status_code == 201 notification_id = get_notification_id(email_response) desired_status = 'sending' notification_status_response = wait_for_status(notification_id, notification_url, service_id, service_api_key, desired_status) assert notification_status_response['status'] == desired_status assert notification_status_response['email_address'] is not None assert notification_status_response['sent_by'] == 'govdelivery'
def wait_for_status(notification_id: str, notification_url: str, service_id: str, service_test_api_key: str, desired_status: str) -> dict: notification_status_response = None for _ in range(30): service_jwt = encode_jwt(service_id, service_test_api_key) notification_status_response = get_notification_status( notification_id, notification_url, service_jwt) assert notification_status_response.status_code == 200 if notification_status_response.json()['status'] == desired_status: return notification_status_response.json() time.sleep(1) pytest.fail( f"Response did not reach desired status '{desired_status}': {notification_status_response.json()}" )
def test_send_text_with_profile_id(notification_url, service_test_api_key, service_id, sms_template_id): service_jwt = encode_jwt(service_id, service_test_api_key) sms_response = send_sms_with_va_profile_id(notification_url, service_jwt, sms_template_id) assert sms_response.status_code == 201 notification_id = get_notification_id(sms_response) desired_status = 'delivered' notification_status_response = wait_for_status(notification_id, notification_url, service_id, service_test_api_key, desired_status) assert notification_status_response['status'] == desired_status assert notification_status_response['phone_number'] is not None assert notification_status_response['sent_by'] is not None
def test_send_text(notification_url, service_test_api_key, service_id, sms_template_id): service_jwt = encode_jwt(service_id, service_test_api_key) sms_response = send_sms_with_phone_number( notification_url, service_jwt, sms_template_id, VALID_TEST_RECIPIENT_PHONE_NUMBER) assert sms_response.status_code == 201 notification_id = get_notification_id(sms_response) desired_status = 'delivered' notification_status_response = wait_for_status(notification_id, notification_url, service_id, service_test_api_key, desired_status) assert notification_status_response['status'] == desired_status assert notification_status_response[ 'phone_number'] == VALID_TEST_RECIPIENT_PHONE_NUMBER assert notification_status_response['sent_by'] is not None
def admin_jwt_token(environment) -> bytes: return encode_jwt('notify-admin', get_admin_client_secret(environment))