Ignore case and whitespace in personalisation keys

From a support ticket:

> it's possible to add a personalisation token with trailing whitespace
> (eg. "key " rather than "key"). Can this be trimmed in the UI to guard
> against this? (one of our devs copied and pasted it from a document
> and inadvertently included the space)

> Nothing major but caused a few hours of investigations!

Rather than trim the placeholder in the template, we should treat
placeholders in API calls the same way we do with CSV files, ie we
ignore case and spacing in the name of the placeholder. So
`(( First Name))` is equivalent to `((first_name))`, and both would be
populated with a dictionary like `{'firstName': 'Chris'}`.

Depends on:
- [x] https://github.com/alphagov/notifications-utils/pull/77
This commit is contained in:
Chris Hill-Scott
2016-11-01 15:19:56 +00:00
parent bec20d3854
commit 8474344c9a
3 changed files with 4 additions and 6 deletions

View File

@@ -72,10 +72,7 @@ def process_job(job_id):
'job': str(job.id), 'job': str(job.id),
'to': recipient, 'to': recipient,
'row_number': row_number, 'row_number': row_number,
'personalisation': { 'personalisation': dict(personalisation)
key: personalisation.get(key)
for key in template.placeholders
}
}) })
if template.template_type == SMS_TYPE: if template.template_type == SMS_TYPE:

View File

@@ -21,6 +21,6 @@ jsonschema==2.5.1
git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0 git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0
git+https://github.com/alphagov/notifications-utils.git@9.1.1#egg=notifications-utils==9.1.1 git+https://github.com/alphagov/notifications-utils.git@9.2.1#egg=notifications-utils==9.2.1
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3 git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3

View File

@@ -190,7 +190,8 @@ def sample_template(notify_db,
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def sample_template_with_placeholders(notify_db, notify_db_session): def sample_template_with_placeholders(notify_db, notify_db_session):
return sample_template(notify_db, notify_db_session, content="Hello ((name))\nYour thing is due soon") # deliberate space and title case in placeholder
return sample_template(notify_db, notify_db_session, content="Hello (( Name))\nYour thing is due soon")
@pytest.fixture(scope='function') @pytest.fixture(scope='function')