mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-27 02:41:56 -04:00
Preserve message in session if we go out of hours
This is a real edge case, but it seems worth handling. How you’d get to this case: - it’s 5:29pm and you start to describe the problem you’re having - it’s 5:31pm and you click ‘submit’ - you’re redirected to the triage page because we’re now out of hours - you click ‘this is a serious problem’ What would be bad thing to happen: - you’re back on the message page and all the stuff you’ve written is gone What would be a good thing to happen: - we save the message in a session so that you can check it again before sending it
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import requests
|
||||
import pytz
|
||||
from flask import render_template, url_for, redirect, flash, current_app, abort, request
|
||||
from flask import render_template, url_for, redirect, flash, current_app, abort, request, session
|
||||
from flask_login import current_user
|
||||
from app import convert_to_boolean, current_service, service_api_client
|
||||
from app.main import main
|
||||
@@ -41,6 +41,9 @@ def feedback(ticket_type):
|
||||
abort(404)
|
||||
|
||||
form = Support()
|
||||
if not form.feedback.data:
|
||||
form.feedback.data = session.pop('feedback_message', '')
|
||||
|
||||
severe = request.args.get('severe')
|
||||
|
||||
urgent = any((
|
||||
@@ -54,6 +57,7 @@ def feedback(ticket_type):
|
||||
))
|
||||
|
||||
if needs_triage(ticket_type, severe):
|
||||
session['feedback_message'] = form.feedback.data
|
||||
return redirect(url_for('.triage'))
|
||||
|
||||
if needs_escalation(ticket_type, severe):
|
||||
|
||||
@@ -254,6 +254,33 @@ def test_redirects_to_triage(
|
||||
assert response.location == expected_redirect(_external=True)
|
||||
|
||||
|
||||
def test_doesnt_lose_message_if_post_across_closing(
|
||||
logged_in_client,
|
||||
mocker,
|
||||
):
|
||||
|
||||
mocker.patch('app.main.views.feedback.has_live_services', return_value=True)
|
||||
mocker.patch('app.main.views.feedback.in_business_hours', return_value=False)
|
||||
|
||||
response = logged_in_client.post(
|
||||
url_for('main.feedback', ticket_type='problem'),
|
||||
data={'feedback': 'foo'},
|
||||
)
|
||||
with logged_in_client.session_transaction() as session:
|
||||
assert session['feedback_message'] == 'foo'
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('.triage', _external=True)
|
||||
|
||||
response = logged_in_client.get(
|
||||
url_for('main.feedback', ticket_type='problem', severe=True)
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
with logged_in_client.session_transaction() as session:
|
||||
assert page.find('textarea', {'name': 'feedback'}).text == 'foo'
|
||||
assert 'feedback_message' not in session
|
||||
|
||||
|
||||
@pytest.mark.parametrize('get_services_mock, expected_return_value', [
|
||||
(mock_get_services, True),
|
||||
(mock_get_services_with_no_services, False),
|
||||
|
||||
Reference in New Issue
Block a user