Commit Graph

25 Commits

Author SHA1 Message Date
Rebecca Law
a8cdabcecd - Refactor v2 post_notification to use a single method for sms and email.
- Added the `simulate` notification logic to version 2. We have 3 email addresses and phone numbers that are used
to simulate a successful post to /notifications. This was missed out of the version 2 endpoint.
- Added a test to template_dao to check for the default value of normal for new templates
- in v2 get_notifications, casted the path param to a uuid, if not uuid abort(404)
2017-01-17 12:08:24 +00:00
Martyn Inglis
0f37824b0c 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.
2016-12-19 16:45:18 +00:00
Rebecca Law
7a623de171 Added boby and subject to the get_notifications schema 2016-12-15 16:19:55 +00:00
Chris Hill-Scott
59af44d7ab Update utils to 12.0.0
Includes:

- [x] https://github.com/alphagov/notifications-utils/pull/94 (breaking
      changes which are responsible for all the changes to the API in
      this PR)

The test for `get_sms_fragment_count` has been removed because this
method is already tested in utils here:

ac20f7e99e/tests/test_base_template.py (L140-L159)
2016-12-13 10:57:01 +00:00
Jenny Duckett
d5d079a150 Add optional queue param to send_notification_to_queue
We want to use this function for sending internal notifications to a different
queue.
2016-12-09 16:46:49 +00:00
Chris Hill-Scott
d449475dd5 Incorporate breaking utils changes
The `.replaced…` methods on instances of `Template` were removed in
https://github.com/alphagov/notifications-utils/pull/84
2016-12-02 10:42:11 +00:00
Martyn Inglis
7260561ad5 Makes the app use the redis and statsd clients from utils 2016-12-01 17:20:05 +00:00
Rebecca Law
be113e031f Sometimes a message is picked up twice of the SQS queue, we need to safe gaurd ourselves for that.
In this PR the id for the notification is passed in and used to created the notification, which causes a integrity error.
Normally when we get a SQLAlchemy error here we send the message to the retry queue, but if the notification already exists
we just ignore it.
2016-11-25 17:32:01 +00:00
Martyn Inglis
2a2ef34339 Merge branch 'master' into caching-with-redis
Conflicts:
	app/__init__.py
2016-11-23 09:12:11 +00:00
Martyn Inglis
0c7d9e33aa Merge branch 'master' into caching-with-redis
Conflicts:
	tests/app/notifications/test_process_notification.py
2016-11-22 13:00:37 +00:00
Martyn Inglis
9e2ba9ee81 Pushed the cache increment into the shared code that persists notifications.
Much simpler implementation, inc code removed from tasks and V1/V2 rest clients.
2016-11-22 12:53:20 +00:00
Rebecca Law
46beece158 For the post_sms_response and post_email_response the reference property is always present but the value can be null.
Added a test for an empty reference.
Remove datetime format on the created_at attribute of a notification, it is not needed.
2016-11-21 17:32:36 +00:00
Martyn Inglis
58bbc5a5aa Now that we have discovered that the catch all Exception handler doesn't work, I've created a custom exception (SendNotificationQueueError) that handles this case and an error handler for it.
Talked these through with @becca as an approach.
2016-11-21 15:11:19 +00:00
Martyn Inglis
7cfc58c994 Merge branch 'master' into caching-with-redis
Conflicts:
	app/celery/tasks.py
	tests/app/celery/test_tasks.py
2016-11-21 13:10:22 +00:00
Rebecca Law
bc434f1736 Create new column in notifications and notification_history to store the client_reference because I remembered that reference is used for email providers. 2016-11-17 13:42:34 +00:00
Rebecca Law
924cec05b4 Included reference when persisting the notification.
This was already part of the data model.
Not included in the send_sms|email task because there is no reference from the job.
2016-11-16 15:44:16 +00:00
Rebecca Law
c00eb0f5a4 Remove from_request method on the Notification db model, was not needed anymore.
Use Notifications.query.one(), rather than assert count is 1 and query for all and get first item in list.
2016-11-14 14:41:32 +00:00
Rebecca Law
4fe8d700ae Fix the send_sms and send_email code to send the notification id that has been persisted. 2016-11-11 16:00:31 +00:00
Rebecca Law
c45d1f63a7 Use the same method to persist a notification.
Refactored the send_sms task to use this method.
2016-11-11 14:56:33 +00:00
Rebecca Law
eafbbd9809 Refactor send_sms and send_email to use common code to persist the notificaiton. 2016-11-11 10:41:39 +00:00
Rebecca Law
fc298367c5 Updated test_validators to test the contents of the error messages.
Added some tests to the test_post_notifications.
Added a errorhandler for AuthErrors.

This endpoint is not being used anywhere, however there is some common code being used in the v1 post endpoint. The only thing that may be affected is the error response, hopefully they are the same.
2016-10-31 12:22:26 +00:00
Rebecca Law
8cf2fc72a8 - Refactor version 1 of post notificaitons to use the common persist_notificaiton and send_notification_to_queue methods.
- It would be nice to refactor the send_sms and send_email tasks to use these common functions as well, that way I can get rid of the new Notifications.from_v2_api_request method.
- Still not happy with the format of the errors. Would like to find a happy place, where the message is descript enough that we do not need external documentation to explain the error. Perhaps we still only need documentation to explain the trial mode concept.
2016-10-28 17:10:00 +01:00
Rebecca Law
6e4bad135a - Implemented persist_notification and send_notification_to_queue in the process_notifications module
- Not sure I want to create a new classmethod on Notifications to create from v2 request. Will take another look at that.
2016-10-27 17:34:54 +01:00
Rebecca Law
c2eecdae36 - Add validation methods for post notification.
- Use these validation methods in post_sms_notification and the version 1 of post_notification.
- Create a v2 error handlers.
- InvalidRequest has a to_dict method for private and v1 error responses and a to_dict_v2 method to create the v2 of the error responses.
- Each validation method has extensive unit tests, so the unit test for the endpoint do not need to check every error case, but check that the error handle formats the message correctly.
- The format of the error messages is still a work on progress.
- This version of the api could be deployed without causing a problem to the application.
- The new endpoing is still a work in progress and is not being used yet.
2016-10-27 11:46:37 +01:00
Rebecca Law
23a4f00e56 New package structure for the version 2 of the public api.
Start building up the validators required for post notificaiton.
The app/v2/errors.py is a rough sketch, will be passed a code, the error can look up the message and link for the error message.
2016-10-25 18:04:03 +01:00