Commit Graph

174 Commits

Author SHA1 Message Date
Rebecca Law
3d41fa9634 Update mmg status code 2 to be a permanent failure. 2016-09-01 10:23:37 +01:00
Leo Hemsted
95e3f39c6f Merge pull request #632 from alphagov/readme-cleanup
cleaned up readme + environment file
2016-08-31 17:08:49 +01:00
Leo Hemsted
5ac4e630d8 remove some legacy code/tests relating to old invite/verification code 2016-08-31 14:49:26 +01:00
Chris Hill-Scott
e98a740dbf Fix test to expect correct db queue
Sending emails was moved to a different queue in:
https://github.com/alphagov/notifications-api/pull/647

At the time that
https://github.com/alphagov/notifications-api/pull/645
was written, the previous queues were still being used.

So when #645 got merged it was testing for the old queues, which broke
the tests.
2016-08-31 13:46:00 +01:00
Chris Hill-Scott
f3495f9dae Merge pull request #645 from alphagov/no-restrictions-on-test-key
Remove restrictions when using simulate API key
2016-08-31 13:25:12 +01:00
Martyn Inglis
f3c614634f Merge branch 'master' into seperate-queues-for-sending-and-for-db 2016-08-30 14:25:14 +01:00
minglis
4a078e3c61 Merge pull request #635 from alphagov/scheduled-delivery-of-jobs
Scheduled delivery of jobs
2016-08-30 12:48:48 +01:00
Martyn Inglis
b923392c49 Using UTC dates on API validation for scheduled jobs. 2016-08-30 12:47:33 +01:00
Chris Hill-Scott
7769923dda Allow test key to send irrespective of daily limit
When you use a simulate API key it should behave like a live service,
except for actually sending the messages. There should be no limits even
if the service is in trial mode.

This commit removes the restriction on sending messages when you’ve sent
up to your daily limit.
2016-08-30 11:06:38 +01:00
Chris Hill-Scott
5eaec8c235 Allow test key to send irrespective of trial mode
When you use a simulate API key it should behave like a live service,
except for actually sending the messages. There should be no limits even
if the service is in trial mode.

This commit removes the restriction on sending messages to peole outside
your team when you’re in trial mode.
2016-08-30 11:06:15 +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
8b9319ac7a Merge branch 'master' into scheduled-delivery-of-jobs
Conflicts:
	app/dao/jobs_dao.py
	tests/app/dao/test_jobs_dao.py
	tests/app/job/test_rest.py
2016-08-25 14:53:00 +01:00
Martyn Inglis
05abd15026 Merge branch 'master' into remove-contested-writes 2016-08-25 14:38:04 +01:00
Martyn Inglis
893164ae40 Removed contented updates the notifications stats table
- As before this is now driven from the notifications history table

- Removed from updates and create
- Signatures changes to removed unused params hits many files
- Also potential issue around rate limiting - we used to get the number sent per day from the stats table - which was a single row lookup, now we have to count this. This applies to EVERY API CALL. Probably not a good thing and should be addressed urgently.
2016-08-25 11:55:38 +01:00
Martyn Inglis
10f499805c Updates to create job to handle scheduling
- If the job JSON contains a scheduling date then the new 'job_status" column is set to "scheduled"
- the date is persisted on the JOB row in the database
- Also the job WILL NOT be placed onto the queue of jobs. This is deferred to a later celery beat task.
2016-08-24 16:00:21 +01:00
Leo Hemsted
00d19f63f0 group results by service using itertools
allows us to nicely reuse the existing format_statistics function
2016-08-24 15:00:51 +01:00
Leo Hemsted
132addb181 Merge branch 'master' into noti-stats-cleanup 2016-08-23 09:49:12 +01:00
Leo Hemsted
5418f65ae7 Merge pull request #599 from alphagov/version-500
fix GET /notifications 500 error
2016-08-22 10:59:46 +01:00
Leo Hemsted
f065b08db2 remove unused dao functions 2016-08-11 16:13:53 +01:00
Leo Hemsted
fff81b4910 remove unused notification-statistics endpoints 2016-08-11 11:55:28 +01:00
Chris Hill-Scott
ebfaa5dac2 Show separate error messages for team key
Although using a team key is functionally the same as your service being
restricted, conflating the two errors is not helpful. What we typically
saw in research was that someone was using a team key, got the error,
used a live key and got the _same_ error.

This commit adds a new error message that specifically mentions the type
of API key that you’re using.
2016-08-10 16:20:01 +01:00
Chris Hill-Scott
0a429e18b4 Give better error when sending to non-team member
Scenario we saw in research:
- trying to send a message to someone outside your team
- service is in trial mode

Result:
- error message was terrible, no-one understood it

Solution:
- better error message
2016-08-10 16:17:47 +01:00
Leo Hemsted
4dd924d438 Merge branch 'master' into version-500 2016-08-10 14:55:07 +01:00
Leo Hemsted
f184bb7996 add test for notification status return value
to ensure we never break compatibility
2016-08-09 17:31:38 +01:00
Leo Hemsted
5b7af00295 re-add content_char_count to public GET /notification endpoints
we shouldn't remove stuff from endpoints or we'll break clients
2016-08-09 17:30:38 +01:00
Leo Hemsted
648b4a17c8 remove xfail flag - the test passes properly now! 🎉 2016-08-09 16:57:18 +01:00
Leo Hemsted
4ba3745159 update schema to use template_history for accurate template details
only in the public notification endpoint so far for fear of breaking
things - in an ideal world i'd remove the template relationship
from models entirely and replace that with actual_template
2016-08-09 16:57:18 +01:00
Leo Hemsted
46c0728b12 add actual_template relationship to notification
also renamed the function to make it apparent that it'll join and grab personalisation
2016-08-09 16:57:18 +01:00
Martyn Inglis
fe54fa9f73 Final pass through existing statsd endpoints to ensure they match new naming strategy.
Updates accordingly.
2016-08-08 11:23:58 +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
Leo Hemsted
91393bdb0d ensure /notifications rather than service/:id/notifications in tests
for content merging
2016-07-26 15:09:25 +01:00
Leo Hemsted
c81b30dba1 separated schemas once more into "with template" and "with personalisation"
"with personalisation" should only be used by the public notification api
"with template" should be used when we want template name, etc details.

also added an xfail test for correctly constructing notification
personalisation
2016-07-26 14:34:59 +01:00
Leo Hemsted
3df0e8ee2d make tests run consistently
* tests on API endpoints that we do not explicitly sort should
  either sort the results or compare results in an orderless way
  (e.g. converting to a set)
* tests that touch the provider_details should reset values after
  running, since the provider_details table is not torn down and
  re-created between tests (unlike most tables)
2016-07-25 09:47:38 +01:00
Chris Hill-Scott
c38962e91a Only put a character limit on SMS notifications
We limit SMS to be a maximum of 495 characters at the point of an
API call being made.

We were also applying this limit to emails, which is wrong.
2016-07-21 16:33:21 +01:00
Adam Shimali
9f9040869d Daily message limit imposed for service api calls. 2016-07-14 11:25:45 +01:00
Chris Hill-Scott
aa12c88551 Add a test for sending email to provider
We had a test like this for sending sms, but not email. This meant that,
for example, we weren’t checking that the provider was getting passed
the HTML and plain text versions of the email.
2016-07-08 11:16:45 +01:00
Chris Hill-Scott
bb3c55ca6c Make send sms test use a template with a newline 2016-07-08 11:16:45 +01:00
Chris Hill-Scott
a8a556d02a Use PassThrough renderer
Implements and depends on:
- [ ] https://github.com/alphagov/notifications-utils/pull/49
2016-07-07 22:48:07 +01:00
Leo Hemsted
96513442fe notifications from test api keys dont send for real - a la research_mode
also added a bunch more tests around api keys to help ensure we're behaving in at least a consistent way
2016-07-05 16:29:53 +01:00
Leo Hemsted
eee98e3e52 move callback tests into separate file
also fix syntax errors
2016-07-05 16:20:03 +01:00
Leo Hemsted
011afa4b16 make tests parametrized for all three key types 2016-07-05 16:20:02 +01:00
Leo Hemsted
2cf1d22748 add filters to GET /notifications endpoints to only return for provided key_type
if api_key used to access endpoint is type team, endpoints only return that type -
will 404 if you provide a different ID. Same applies for normal (normal api keys
cannot see team notifications)
also, for convenience, set sample_notification to supply key_type of KEY_TYPE_NORMAL
by default
2016-07-01 14:35:02 +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
Leo Hemsted
5ae7ed1acb only send to team emails/phones if POST /notificaiton/<type> with team api_key
uses same restriction as a service in trial mode
2016-07-01 14:33:25 +01:00
Leo Hemsted
2b645f490a move get_all_notifications_for_service and get_all_notifications_for_job
moved from notifications/rest -> service/rest and job/rest respectively
endpoint routes not affected
removed requires_admin decorator - that should be set by nginx config
as opposed to python code
2016-06-30 10:44:21 +01:00
Rebecca Law
8435217808 Fix new test for the default status of a notification 2016-06-27 15:02:53 +01:00
Rebecca Law
48e64abd81 Merge branch 'master' into notification-created-status 2016-06-27 14:59:56 +01:00
Rebecca Law
8a0211b3eb Only send to the provider if the notification has a created status.
If the notification ends up in the retry queue and the delivery app is restarted the notification will get sent twice.
This is because when the app is restarted another message will be in the retry queue as message available which is a
duplicate of the one in the queue that is a  message in flight.

This should complete https://www.pivotaltracker.com/story/show/121844427
2016-06-27 14:47:20 +01:00
Adam Shimali
3423c0c44d Added subject for email templates 2016-06-23 15:21:03 +01:00
Adam Shimali
f65b86cfc9 Body of notification without placeholder should have been present. 2016-06-23 10:25:07 +01:00