Make handling of None values in forms clearer

If the browser posts the value of `<input value='None'>` to the server
it does so as a string.

We want to post a value of `None` (actually JSON `null`) to the API. To
do this we:
- set the value in the form class to `'None'` (ie a string)
- convert to `None` (as a type) afterwards

However seeing `x = 'None'` in code looks a bit like a mistake. So to
make sure it looks deliberate and clear what is happening this commit:
- makes a reusable constant for `'None'`
- adds a comment explaining why it’s a string
This commit is contained in:
Chris Hill-Scott
2018-11-12 09:04:39 +00:00
parent 74a4400bc7
commit c18a38d4f1
3 changed files with 26 additions and 9 deletions

View File

@@ -2304,17 +2304,23 @@ def test_should_preview_email_branding(
app.service_api_client.get_service.assert_called_once_with(service_one['id'])
@pytest.mark.parametrize('posted_value, submitted_value', (
('1', '1'),
('None', None),
))
def test_should_set_branding_and_organisations(
logged_in_platform_admin_client,
service_one,
mock_update_service,
posted_value,
submitted_value,
):
response = logged_in_platform_admin_client.post(
url_for(
'main.service_preview_email_branding', service_id=service_one['id']
),
data={
'branding_style': '1'
'branding_style': posted_value
}
)
assert response.status_code == 302
@@ -2323,7 +2329,7 @@ def test_should_set_branding_and_organisations(
mock_update_service.assert_called_once_with(
service_one['id'],
email_branding='1'
email_branding=submitted_value
)