Commit Graph

129 Commits

Author SHA1 Message Date
Leo Hemsted
bdb4da4976 tests n stuff 2016-10-07 13:08:41 +01:00
Leo Hemsted
27c7a08523 use assert rather than relying on mock functions
mocks create any property you access, so calling functions on them is
inherently risky due to typos quietly doing nothing. instead assert
`.called is False`, which will fail noisily if you typo
2016-10-07 12:48:58 +01:00
Rebecca Law
6065ed57cf Fix for the job status
- It seems that when we changed the name of the job.status column that we didn't update the code to use job.job_status.
- Therefore none of the jobs since then have had the job status updated.
- Now that this is fix we can show the job status when there is an error like "sending exceeds limits"
  - This could happen if a job is scheduled to run at the top of the hour, so at the time of the job creation the limit was not exceed, but at the time of processing the job the limit is exceed.
2016-10-05 14:56:32 +01:00
Martyn Inglis
ad5222442a Fixed build
- passing a single param to a celery task must be done as a list not a tuple.
2016-09-30 13:34:44 +01:00
Martyn Inglis
e3ed8fad1a Merge branch 'master' into research-mode-csv-file-queues
Conflicts:
	tests/app/celery/test_tasks.py
	tests/app/notifications/rest/test_send_notification.py
2016-09-30 11:07:32 +01:00
Imdad Ahad
8f74d9a122 Fix issue with test where team key does not check sending elegibility 2016-09-28 17:02:57 +01:00
Martyn Inglis
b9f0659eaa Ensure that when an API call is made on
- a TEST key
- a research-mode service

We put the task into the research-mode queue NOT the production delivery queue.
2016-09-28 15:48:12 +01:00
Martyn Inglis
3618a3967c Creating notification tasks should write send tasks to the research-mode queue if research mode service. 2016-09-28 15:29:10 +01:00
Martyn Inglis
c13ead77e4 Ensures that both the CSV processing and the API both use the new deliver_email and deliver_sms tasks not the old ones with the redundant parameter. 2016-09-28 15:05:50 +01:00
Martyn Inglis
9233ffa3d4 When processing a CSV file don't put the DB tasks into the live queue when service is in research mode. 2016-09-28 13:53:05 +01:00
Martyn Inglis
0ecd6f2737 Removed the 'delete job' tasks from the tasks.py file
- this was called after processing a job.
- now to be called  on a schedule.
2016-09-07 15:35:12 +01:00
Imdad Ahad
840b99b277 Fix issue where test key cannot send messages to external numbers 2016-09-07 09:57:20 +01:00
Leo Hemsted
6ceb80d32f Merge pull request #651 from alphagov/contract-tests
Contract tests
2016-09-05 11:31:29 +01:00
Leo Hemsted
7240df0641 replace mock with unittest.mock 2016-08-31 12:39:11 +01:00
Martyn Inglis
e640e048e5 Pushed the notifications from the CSV in the DB queue 2016-08-30 17:27:01 +01:00
Martyn Inglis
486697d07c New queues for the sms/email tasks
Previously there were 4 queues for sending messages

The was based on the fact that each notification has 2 actions - persist in the database and send to provider.

Two queues supported the CSV upload - for the first of these tasks
- bulk-email
- build-sms

And there were two more queues for the tasks that make the 3rd party client calls.
- sms
- email

API Calls just used the latter two queues for both tasks

Added four new queues
- db-email
- db-sms
- send-sms
- send-email

So an API call puts a notification into the db-[type] queue first, which then puts the notification into the send-[type] queue

Build queues stay as before.

This will allow us to target processing of these tasks with separate workers to manage these differently.
2016-08-30 10:42:24 +01:00
Martyn Inglis
f223446f73 Refactor statsd logging
Removed all existing statsd logging and replaced with:

- statsd decorator. Infers the stat name from the decorated function call. Delegates statsd call to statsd client. Calls incr and timing for each decorated method. This is applied to all tasks and all dao methods that touch the notifications/notification_history tables

- statsd client changed to prefix all stats with "notification.api."

- Relies on https://github.com/alphagov/notifications-utils/pull/61 for request logging. Once integrated we pass the statsd client to the logger, allowing us to statsd all API calls. This passes in the start time and the method to be called (NOT the url) onto the global flask object. We then construct statsd counters and timers in the following way

	notifications.api.POST.notifications.send_notification.200

This should allow us to aggregate to the level of

	- API or ADMIN
	- POST or GET etc
	- modules
	- methods
	- status codes

Finally we count the callbacks received from 3rd parties to mapped status.
2016-08-05 10:44:43 +01:00
Rebecca Law
8bea8b6a8f Fix bug where all notifications were getting a type = email.
Includes a fix to notification and notification_statistics data.
2016-07-06 14:31:52 +01:00
Leo Hemsted
242be97bfa remove reply_to_addresses from task kwargs
also added a test for aws_ses.send_email to prove it handles reply_to_address correctly
2016-07-04 17:29:41 +01:00
Leo Hemsted
f5e14f043d dont pass reply-to-addresses about
dont send reply_to_addresses around from process_job and send_email -
take it from the service in send_email_to_provider. also clean up
the kwarg in aws_ses.send_email to more accurately reflect what we
might pass in
2016-07-04 15:04:43 +01:00
Leo Hemsted
4e2a14ed28 Merge branch 'master' into notifications-get-api-key-filter 2016-07-01 17:12:03 +01:00
Leo Hemsted
01419e7894 store api_key_id and key_type on notification
pass through from POST /notification/<type> to the celery task
also removed a couple of asserts that can fail (based on unfrozen time comparisons)
2016-07-01 14:35:02 +01:00
Rebecca Law
f52755742c Split send_email task into one task to create the notification and one to send it to the provider.
Is there is an exception the task will go to the retry queue.
2016-07-01 14:14:28 +01:00
Rebecca Law
60e159e3c0 Add notification_type to notification table.
It seems like an oversight not to include the notification type in the notifcation.
When updating statistics a query to the template table is required to get the type, this update will mean that query does not have to happen.
2016-06-29 11:23:02 +01:00
Rebecca Law
8f19ad19f8 Stop sending the encrypted message to the send_sms_to_provider task.
Everything the task needs is now stored in the db.
2016-06-23 09:41:21 +01:00
Rebecca Law
fcb5ca9ef4 The send_sms task will created the notification with a status = created.
The encrypted_notification for the send_sms_to_provider task has been made optional.
2016-06-22 13:32:27 +01:00
Rebecca Law
b17aaaabfb Set a notification.status=created in the send_sms task 2016-06-21 14:38:17 +01:00
Rebecca Law
6c81d0f465 Merge branch 'master' into move-scheduler-tasks
Conflicts:
	tests/app/celery/test_tasks.py
2016-06-21 11:24:26 +01:00
Adam Shimali
731bb19a9c Template and personalisation content is now merged and returned with
notifications, when retrieved by notification id, or service id (i.e.
all notifications for service).

There is a new element returned at top level of notification json called
body, which is the template content merged with personalisation. This
is consistent with api to endpoint to create notification which returns
what was sent as 'body' in json response.

Merging of template with personalisation is done in the
NotificationStatusSchema.

Personalisation data in encrypted before storing in db.
2016-06-20 16:49:17 +01:00
Rebecca Law
316b5d0e64 Move scheduled tasks into their own module.
There is no change to the functionality - only moving the code around.
2016-06-20 13:33:53 +01:00
Martyn Inglis
838bf1d7d4 Merge branch 'master' into split-sms-and-retry
Conflicts:
	app/celery/tasks.py
	tests/app/celery/test_tasks.py
2016-06-17 16:39:03 +01:00
Rebecca Law
fa6ae864d6 Remove the invitation email and reset password email tasks. 2016-06-17 13:49:33 +01:00
Martyn Inglis
0a933021d6 Merge branch 'master' into split-sms-and-retry 2016-06-14 12:55:16 +01:00
Martyn Inglis
f143aade71 Added new tests/code to ensure failure stats recorded 2016-06-13 16:40:46 +01:00
Rebecca Law
a6ce109c62 Rename first send_email to send_email_v1.
Fix the tests
2016-06-13 16:16:56 +01:00
Rebecca Law
5fc14940f3 Let the send_email task set the from address 2016-06-13 14:58:00 +01:00
Martyn Inglis
bec882ba41 Merge branch 'master' into split-sms-and-retry 2016-06-13 11:39:13 +01:00
Martyn Inglis
6b5b40b953 Added tests for statsd and provider stats outcomes with the new provider stats tasks
- note large change to DAO to remove provider from create notification. Added on send now not creation.
2016-06-13 11:38:25 +01:00
Rebecca Law
50ec2eb7fc Remove task send_sms_code.
We use a notify service to send the sms code via using a template.
2016-06-09 11:54:34 +01:00
Nicholas Staples
8a1f4de217 Task added to update 'sending' notifications after 72 hours, set task to temporary-failure. 2016-06-08 15:25:57 +01:00
Martyn Inglis
92e4c0872b Pulled out the tests that send SMSs into provider_tasks file/tests
- updated tests to validate creation of next task, not sending direct to provider
2016-06-07 12:53:31 +01:00
Martyn Inglis
642aa2890e Starting to implement tests across the new tasks file 2016-06-07 11:09:54 +01:00
Martyn Inglis
754ccbe9af Removed update reference from updating the provider stats
- single focus method
- allows not to pollute DAO with research mode
2016-06-02 09:52:47 +01:00
Martyn Inglis
099c17192d Merged provider stats only on success branch
- ensures that don't raise stats in research mode
2016-06-02 09:30:01 +01:00
Martyn Inglis
b08f906662 Added 2 tests to ensure provider stats not updated when in research nmode 2016-06-02 09:28:21 +01:00
Martyn Inglis
97e29b9039 Merge branch 'master' into research-mode-implementation 2016-06-01 17:06:38 +01:00
Martyn Inglis
290f416485 Various tidy ups and changes
- use new queue
- remove some new lines in AWS response data
- migration script to populate new fields
2016-06-01 16:57:57 +01:00
Martyn Inglis
909fac3c05 Added research mode tasks
- if a service is in research mode the don't send the notifications via the providers (MMG/SES/etc)
- instead set up a task to mimic those services callbacks - this completes the loop, and show stats, delivery receipts and so on.
- Use the "to" field to choose the response, allows users to create successful and errored notifications

temp fail sms, uses  "07833333333"
perm fail sms, uses = "07822222222"
success = "07811111111" (or anything else)

success email = "delivered@simulator.notify"
perm fail = "perm-fail@simulator.notify"
temp fail = "temp-fail@simulator.notify"
2016-05-31 16:55:26 +01:00
Nicholas Staples
79dfc360f2 Notification not created in send_sms or send_email when service is in restricted mode. 2016-05-31 14:55:06 +01:00
Nicholas Staples
0fe0c1d2b4 Added job row number to the notification for csv jobs. All tests passing. 2016-05-19 10:46:03 +01:00