mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 18:22:37 -04:00
Convert radios on SMS prefix page
Includes changing form.enabled to use OnOffField, for consistency with other on/off fields. OnOffField's data is a boolean, not a string, so some of the logic using it needed to be changed.
This commit is contained in:
+1
-7
@@ -1942,13 +1942,7 @@ class CallbackForm(StripWhitespaceForm):
|
|||||||
|
|
||||||
|
|
||||||
class SMSPrefixForm(StripWhitespaceForm):
|
class SMSPrefixForm(StripWhitespaceForm):
|
||||||
enabled = RadioField(
|
enabled = OnOffField('') # label is assigned on instantiation
|
||||||
'',
|
|
||||||
choices=[
|
|
||||||
('on', 'On'),
|
|
||||||
('off', 'Off'),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_placeholder_form_instance(
|
def get_placeholder_form_instance(
|
||||||
|
|||||||
@@ -630,15 +630,13 @@ def service_set_inbound_number(service_id):
|
|||||||
@user_has_permissions('manage_service')
|
@user_has_permissions('manage_service')
|
||||||
def service_set_sms_prefix(service_id):
|
def service_set_sms_prefix(service_id):
|
||||||
|
|
||||||
form = SMSPrefixForm(enabled=(
|
form = SMSPrefixForm(enabled=current_service.prefix_sms)
|
||||||
'on' if current_service.prefix_sms else 'off'
|
|
||||||
))
|
|
||||||
|
|
||||||
form.enabled.label.text = 'Start all text messages with ‘{}:’'.format(current_service.name)
|
form.enabled.label.text = 'Start all text messages with ‘{}:’'.format(current_service.name)
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
current_service.update(
|
current_service.update(
|
||||||
prefix_sms=(form.enabled.data == 'on')
|
prefix_sms=form.enabled.data
|
||||||
)
|
)
|
||||||
return redirect(url_for('.service_settings', service_id=service_id))
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{% extends "withnav_template.html" %}
|
{% extends "withnav_template.html" %}
|
||||||
{% from "components/radios.html" import radios %}
|
|
||||||
{% from "components/page-header.html" import page_header %}
|
{% from "components/page-header.html" import page_header %}
|
||||||
{% from "components/page-footer.html" import page_footer %}
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
{% from "components/form.html" import form_wrapper %}
|
{% from "components/form.html" import form_wrapper %}
|
||||||
@@ -16,7 +15,7 @@
|
|||||||
) }}
|
) }}
|
||||||
|
|
||||||
{% call form_wrapper() %}
|
{% call form_wrapper() %}
|
||||||
{{ radios(form.enabled) }}
|
{{ form.enabled }}
|
||||||
{{ page_footer('Save') }}
|
{{ page_footer('Save') }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
|
|||||||
@@ -4450,22 +4450,21 @@ def test_show_sms_prefixing_setting_page(
|
|||||||
)
|
)
|
||||||
radios = page.select('input[type=radio]')
|
radios = page.select('input[type=radio]')
|
||||||
assert len(radios) == 2
|
assert len(radios) == 2
|
||||||
assert radios[0]['value'] == 'on'
|
assert radios[0]['value'] == 'True'
|
||||||
assert radios[0]['checked'] == ''
|
assert radios[0]['checked'] == ''
|
||||||
assert radios[1]['value'] == 'off'
|
assert radios[1]['value'] == 'False'
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
assert radios[1]['checked']
|
assert radios[1]['checked']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('post_value, expected_api_argument', [
|
@pytest.mark.parametrize('post_value', [
|
||||||
('on', True),
|
True,
|
||||||
('off', False),
|
False,
|
||||||
])
|
])
|
||||||
def test_updates_sms_prefixing(
|
def test_updates_sms_prefixing(
|
||||||
client_request,
|
client_request,
|
||||||
mock_update_service,
|
mock_update_service,
|
||||||
post_value,
|
post_value,
|
||||||
expected_api_argument,
|
|
||||||
):
|
):
|
||||||
client_request.post(
|
client_request.post(
|
||||||
'main.service_set_sms_prefix', service_id=SERVICE_ONE_ID,
|
'main.service_set_sms_prefix', service_id=SERVICE_ONE_ID,
|
||||||
@@ -4477,7 +4476,7 @@ def test_updates_sms_prefixing(
|
|||||||
)
|
)
|
||||||
mock_update_service.assert_called_once_with(
|
mock_update_service.assert_called_once_with(
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
prefix_sms=expected_api_argument,
|
prefix_sms=post_value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user