mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
Send request to api to check if reply-to address is working
This commit is contained in:
@@ -19,6 +19,7 @@ from app import (
|
|||||||
email_branding_client,
|
email_branding_client,
|
||||||
inbound_number_client,
|
inbound_number_client,
|
||||||
letter_branding_client,
|
letter_branding_client,
|
||||||
|
notification_api_client,
|
||||||
organisations_client,
|
organisations_client,
|
||||||
service_api_client,
|
service_api_client,
|
||||||
user_api_client,
|
user_api_client,
|
||||||
@@ -403,18 +404,29 @@ def service_add_email_reply_to(service_id):
|
|||||||
form = ServiceReplyToEmailForm()
|
form = ServiceReplyToEmailForm()
|
||||||
first_email_address = current_service.count_email_reply_to_addresses == 0
|
first_email_address = current_service.count_email_reply_to_addresses == 0
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
service_api_client.add_reply_to_email_address(
|
notification_id = service_api_client.verify_reply_to_email_address(form.email_address.data)["data"]["id"]
|
||||||
current_service.id,
|
return redirect(url_for('.verify_reply_to_address', service_id=service_id, notification_id=notification_id))
|
||||||
email_address=form.email_address.data,
|
# service_api_client.add_reply_to_email_address(
|
||||||
is_default=first_email_address if first_email_address else form.is_default.data
|
# current_service.id,
|
||||||
)
|
# email_address=form.email_address.data,
|
||||||
return redirect(url_for('.service_email_reply_to', service_id=service_id))
|
# is_default=first_email_address if first_email_address else form.is_default.data
|
||||||
|
# )
|
||||||
|
# return redirect(url_for('.service_email_reply_to', service_id=service_id))
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/service-settings/email-reply-to/add.html',
|
'views/service-settings/email-reply-to/add.html',
|
||||||
form=form,
|
form=form,
|
||||||
first_email_address=first_email_address)
|
first_email_address=first_email_address)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<service_id>/service-settings/email-reply-to/<notification_id>/verify", methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
@user_has_permissions('manage_service')
|
||||||
|
def verify_reply_to_address(service_id, notification_id):
|
||||||
|
return render_template(
|
||||||
|
'views/service-settings/email-reply-to/verify.html'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route(
|
@main.route(
|
||||||
"/services/<service_id>/service-settings/email-reply-to/<reply_to_email_id>/edit",
|
"/services/<service_id>/service-settings/email-reply-to/<reply_to_email_id>/edit",
|
||||||
methods=['GET', 'POST'],
|
methods=['GET', 'POST'],
|
||||||
|
|||||||
@@ -386,6 +386,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def verify_reply_to_email_address(self, email_address):
|
||||||
|
return self.post(
|
||||||
|
"/service/email-reply-to/verify",
|
||||||
|
data={"email": email_address}
|
||||||
|
)
|
||||||
|
|
||||||
@cache.delete('service-{service_id}')
|
@cache.delete('service-{service_id}')
|
||||||
def add_reply_to_email_address(self, service_id, email_address, is_default=False):
|
def add_reply_to_email_address(self, service_id, email_address, is_default=False):
|
||||||
return self.post(
|
return self.post(
|
||||||
|
|||||||
@@ -2029,6 +2029,44 @@ def test_add_reply_to_email_address(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('fixture, data, api_default_args', [
|
||||||
|
(no_reply_to_email_addresses, {}, True),
|
||||||
|
(multiple_reply_to_email_addresses, {}, False),
|
||||||
|
(multiple_reply_to_email_addresses, {"is_default": "y"}, True)
|
||||||
|
])
|
||||||
|
def test_add_reply_to_email_address_sends_test_notification(
|
||||||
|
mocker, client_request, fixture, data, api_default_args
|
||||||
|
):
|
||||||
|
fixture(mocker)
|
||||||
|
data['email_address'] = "test@example.com"
|
||||||
|
mock_verify = mocker.patch('app.service_api_client.verify_reply_to_email_address', return_value={"id": "123"})
|
||||||
|
client_request.post(
|
||||||
|
'main.service_add_email_reply_to',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
_data=data,
|
||||||
|
_expected_status=302,
|
||||||
|
_expected_redirect=url_for(
|
||||||
|
'main.verify_reply_to_address',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id="123",
|
||||||
|
_external=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
mock_verify.assert_called_once_with("test@example.com")
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_reply_to_email_address_waiting_page():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_reply_to_email_address_success():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_reply_to_email_address_failure():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('fixture, data, api_default_args', [
|
@pytest.mark.parametrize('fixture, data, api_default_args', [
|
||||||
(no_letter_contact_blocks, {}, True),
|
(no_letter_contact_blocks, {}, True),
|
||||||
(multiple_letter_contact_blocks, {}, False),
|
(multiple_letter_contact_blocks, {}, False),
|
||||||
|
|||||||
Reference in New Issue
Block a user