Ensure updates on a research mode service or test key don't touch the history table

- note this is an unexpectedly big change.
- When we create a service we pass the service id to the persist method. This means that we don't have the service available to check if in research mode.
- All calling methods (expecting the one where we use the notify service) have the service available. So rather than reload it I changed the method signature to pass the service, not the ID to persist.
- Touches a few places.

Note this means that the update or create methods will fall over on a null service. But this seems correct.

Goes back to the story which we need to play to make the service available as the API user so that the need to load and pass around services is minimised.
This commit is contained in:
Martyn Inglis
2016-12-19 16:45:18 +00:00
parent 35aa888658
commit 0f37824b0c
9 changed files with 110 additions and 41 deletions

View File

@@ -48,7 +48,7 @@ def test_persist_notification_creates_and_save_to_db(sample_template, sample_api
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 0
notification = persist_notification(sample_template.id, sample_template.version, '+447111111111',
sample_template.service.id, {}, 'sms', sample_api_key.id,
sample_template.service, {}, 'sms', sample_api_key.id,
sample_api_key.key_type, job_id=sample_job.id,
job_row_number=100, reference="ref")
@@ -84,7 +84,7 @@ def test_persist_notification_throws_exception_when_missing_template(sample_api_
persist_notification(template_id=None,
template_version=None,
recipient='+447111111111',
service_id=sample_api_key.service_id,
service=sample_api_key.service,
personalisation=None,
notification_type='sms',
api_key_id=sample_api_key.id,
@@ -102,7 +102,7 @@ def test_exception_thown_by_redis_store_get_should_not_be_fatal(sample_template,
sample_template.id,
sample_template.version,
'+447111111111',
sample_template.service.id,
sample_template.service,
{},
'sms',
sample_api_key.id,
@@ -118,7 +118,7 @@ def test_cache_is_not_incremented_on_failure_to_persist_notification(sample_api_
persist_notification(template_id=None,
template_version=None,
recipient='+447111111111',
service_id=sample_api_key.service_id,
service=sample_api_key.service,
personalisation=None,
notification_type='sms',
api_key_id=sample_api_key.id,
@@ -136,7 +136,7 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key, mocker)
persist_notification(template_id=sample_job.template.id,
template_version=sample_job.template.version,
recipient='+447111111111',
service_id=sample_job.service.id,
service=sample_job.service,
personalisation=None, notification_type='sms',
api_key_id=sample_api_key.id,
key_type=sample_api_key.key_type,