def test_check_service_email_reply_to_id_where_service_id_is_not_found(sample_service, fake_uuid): reply_to_address = create_reply_to_email(sample_service, "*****@*****.**") with pytest.raises(BadRequestError) as e: check_service_email_reply_to_id(fake_uuid, reply_to_address.id, EMAIL_TYPE) assert e.value.status_code == 400 assert e.value.message == 'email_reply_to_id {} does not exist in database for service id {}' \ .format(reply_to_address.id, fake_uuid)
def test_check_service_email_reply_to_id_where_reply_to_id_is_not_found( sample_service, fake_uuid): with pytest.raises(BadRequestError) as e: check_service_email_reply_to_id(sample_service.id, fake_uuid, EMAIL_TYPE) assert e.value.status_code == 400 assert e.value.message == "email_reply_to_id {} does not exist in database for service id {}".format( fake_uuid, sample_service.id)
def get_reply_to_text(notification_type, form, template, form_field=None): reply_to = None if notification_type == EMAIL_TYPE: service_email_reply_to_id = form.get(form_field or "email_reply_to_id") reply_to = ( check_service_email_reply_to_id( str(authenticated_service.id), service_email_reply_to_id, notification_type, ) or template.get_reply_to_text() ) elif notification_type == SMS_TYPE: service_sms_sender_id = form.get(form_field or "sms_sender_id") sms_sender_id = check_service_sms_sender_id(str(authenticated_service.id), service_sms_sender_id, notification_type) if sms_sender_id: reply_to = try_validate_and_format_phone_number(sms_sender_id) else: reply_to = template.get_reply_to_text() elif notification_type == LETTER_TYPE: reply_to = template.get_reply_to_text() return reply_to
def validate_sender_id(template, reply_to_id): notification_type = template.template_type if notification_type == EMAIL_TYPE: service_email_reply_to_id = reply_to_id check_service_email_reply_to_id( str(authenticated_service.id), service_email_reply_to_id, notification_type, ) return service_email_reply_to_id elif notification_type == SMS_TYPE: service_sms_sender_id = reply_to_id check_service_sms_sender_id( str(authenticated_service.id), service_sms_sender_id, notification_type, ) return service_sms_sender_id else: raise NotImplementedError("validate_sender_id only handles emails and text messages")
def test_check_service_email_reply_to_where_email_reply_to_is_found(sample_service): reply_to_address = create_reply_to_email(sample_service, "*****@*****.**") assert check_service_email_reply_to_id(sample_service.id, reply_to_address.id, EMAIL_TYPE) == "*****@*****.**"
def test_check_service_email_reply_to_id_where_reply_to_id_is_none(notification_type): assert check_service_email_reply_to_id(None, None, notification_type) is None