Commit Graph

92 Commits

Author SHA1 Message Date
Chris Hill-Scott
1802c84b8a Add handling for data types other than list/string
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/135

Also adds extra tests for:
- the exact issue that we saw in production when #867 was deployed
- what happens when `None` is passed as a placeholder value, because
  this should never get as far as the relevant bit of utils
2017-04-05 09:28:17 +01:00
Chris Hill-Scott
7943b6819b Revert "Revert "Bump utils to allow lists as placeholder values"" 2017-04-05 09:18:58 +01:00
Chris Hill-Scott
cb208473c6 Revert "Bump utils to allow lists as placeholder values" 2017-04-04 15:19:53 +01:00
Martyn Inglis
ac445114c7 When using a priority template put the notification in the priority queue.
- there is now a dedicated worker to handle priority queues. We don't now bundle this in the default worker.
2017-04-04 13:44:11 +01:00
Chris Hill-Scott
585ef8e66a Bump utils to allow lists as placeholder values
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/128

Also adds a test to make sure that passing a dictionary as a value in
the `personalisation` argument works.
2017-03-31 17:02:54 +01:00
Martyn Inglis
7dcd3164e2 Revert "Reinstating the 2 task model for API submitted notifications."
This reverts commit 1c154c4113.
2017-03-30 10:46:23 +01:00
Martyn Inglis
9ee26e0b67 Revert "update notification rest tests"
This reverts commit 11919d9810.
2017-03-30 10:38:51 +01:00
Leo Hemsted
11919d9810 update notification rest tests 2017-03-28 13:51:42 +01:00
Martyn Inglis
1c154c4113 Reinstating the 2 task model for API submitted notifications.
This is being done for the PaaS migration to allow us to keep traffic coming in whilst we migrate the database.

uses the same tasks as the CSV uploaded notifications. Simple changes to not persist the notification, and call into a different task.
2017-03-23 14:41:00 +00:00
Rebecca Law
78242812ef Register a before_request event for all blueprints, that defines the authentication requirement.
There are three authentication methods:
 - requires_no_auth - public endpoint that does not require an Authorisation header
 - requires_auth - public endpoints that need an API key in the Authorisation header
 - requires_admin_auth - private endpoint that requires an Authorisation header which contains the API key for the defined as the client admin user
2017-03-16 18:15:49 +00:00
Chris Hill-Scott
e507fed152 Quietly ignore extra personalisation
> If a user makes an API request with additional personalisation fields,
> we should simply discard any fields that the template doesn't have.
>
> This gives a couple of related advantages:
>
> - modifying template parameters no longer requires downtime for
>   clients - as they can pass in extra new parameters before a template
>   change, or continue passing in old unused parameters after removing
>   them from a template
>
> - services can pass in large user objects, for example, and then play
>   around with templates adding and removing fields at will
>
> we should make sure we still return an error if a user doesn't pass in
> a required parameter.

– https://www.pivotaltracker.com/story/show/140774195
2017-03-07 16:09:17 +00:00
Rebecca Law
458adefcb8 Added a redis cache for the template usage stats.
Cache expires every 10 minutes, but will help with the every 2 second query, especially when a job is running.
There is some clean up and qa to do for this yet
2017-02-13 18:47:29 +00:00
Rebecca Law
c6eb284218 Small change to include the reference that ses send us on the callback. 2017-01-30 14:09:30 +00:00
Rebecca Law
27b6aa736c Update info log to waring.
Removed duplicate test
2017-01-27 12:20:54 +00:00
Rebecca Law
67657ced26 Return success of the callback is a duplicate or for an id that does not exist
This PR changes the response to POST /notifications/sms/<mmg | firetext> from a 400 response to a 200 response.
If we get a callback for a notification more than once or for a notification we log that but we return a 200 success response to the provider.
We have found that there is a situation where the send to provider throws a timeout exception but the provider did get the message, but we still send it to them again.
In which case they send the message twice, and callback for the message twice.
Another case where we may get duplicate callbacks is that the network gave the provider two callbacks meaning they pass those two callbacks onto us.

So it is really difficult to know if we sent to the provider twice or just got two callbacks.

The test_callback has many changes because I took the opportunity to use the client conftest fixture rather than the notify_api fixture.
The only 2 tests really changed are test_mmg_callback_returns_200_when_notification_id_not_found_or_already_updated and test_firetext_callback_returns_200_when_notification_id_not_found_or_already_updated
2017-01-25 14:37:11 +00:00
Rebecca Law
b34c5f0bcd If the template.process_type = PRIROITY send the message to the notify queue.
We are using the notify queue in this iteration because that queue is a low volume queue with it's own dedicated workers. This just saves us from building a new queue at this point, and a new queue may not be necessary.
2017-01-17 13:16:26 +00:00
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
Leo Hemsted
d550893377 update tests to use create_user instead of sample_user
note that all of these tests have to be checked to ensure that they
still call through to notify_db_session (notify_db not required) to
tear down the database after the test runs - since it's no longer
required to pass it in to the function just to invoke the sample_user
function
2017-01-10 15:04:28 +00:00
Leo Hemsted
501187a9f4 bump utils to 13.0.1
brings in a fix to InvalidEmail/Phone/AddressExceptions not being
instantiated correctly. `exception.message` is not a python standard,
so we shouldn't be relying on it to transmit exception reasons -
rather we should be using `str(exception)` instead. This involved a
handful of small changes to the schema validation
2017-01-09 16:37:58 +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
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
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
Martyn Inglis
ac6609e653 Couple of bugs squashed.
1) It's incr not inc on the redis client, so renamed the calls everywhere
2) Redis returns bytes/string rather than an int if the value stored is an int. Cast the result to an int before use. Not you can set up the GET to do this transparently but I've not done this as we *may * use GETS for non-int and  the callback sets up the cast for the connection not the call.
2016-11-12 15:37:57 +00:00
Martyn Inglis
033a3e530b Increment the redis cache on a successful API call.
These means that the cache count is on Notifications in the database NOT notifications sent to providers. If the provider fails to accept the notification, it still counts.

I think this is correct, as they have done the work to send it so we should count it, though there is an argument that we should count them on sending?
2016-11-11 17:19:27 +00:00
Martyn Inglis
88f04a46cf Implemented the rate limiting from Redis
- Uses Redis cache to check for current count
- If not present then sets the value based on the database state
- Any Redis errors are swallowed. Cache failures should NOT fail  the request.
2016-11-11 16:47:52 +00:00
Chris Hill-Scott
d51c63cb6b Merge pull request #722 from alphagov/whitepace-in-personalisation
Ignore case and whitespace in personalisation keys
2016-11-11 11:33:37 +01:00
Chris Hill-Scott
988bf06132 Update error message for invalid email addresses
It has a trailing full stop since:
https://github.com/alphagov/notifications-utils/pull/76
2016-11-10 11:40:00 +00:00
Leo Hemsted
f842a8c893 update test to pytest.raises instaed of assert response == 500 2016-11-04 17:04:51 +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
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
Imdad Ahad
9bbd4713e4 Fix PEP issueFix PEP issueFix PEP issueFix PEP issueFix PEP issueFix PEP
issueFix PEP issueFix PEP issue
2016-10-10 10:27:57 +01:00
Imdad Ahad
ed203e33ea Refactor test for sending to non-whitelist member 2016-10-10 10:24:33 +01:00
Chris Hill-Scott
74be99e7c7 Let team key send to whitelist
There is an overlap between team key/trial mode/whitelist. But it’s not
a complete overlap. So it’s hard to understand all the different
permutations of which key lets you send to which people when.

This commit tries to reduce the differences between these concepts. So
for a user of the API

**In trial mode**

- You can send to anyone in your team or whitelist, using the team key
- You can simulate sending to anyone, using the simulate key

**When you’re live**

- You can send to anyone in your team or whitelist, using the team key
- You can simulate sending to anyone, using the simulate key
- You can send to anyone with the live key

So doing a `git diff` on that list, the only difference between being in
trial mode and live mode is now:

`+` You can send to anyone with the live key

**(How trial mode used to work)**
- You can send to anyone in your team or whitelist, using the normal key
- You can simulate sending to anyone, using the simulate key
- You can send to _just_ people in your team using the team key
2016-10-07 15:38:36 +01:00
Rebecca Law
c66d4c3c59 fix checkstyle 2016-10-03 14:48:06 +01:00
Rebecca Law
f0772fe06b Updates for review comments.
Simplify mocker in parameterised tests.
Fix duplicate test name.
2016-10-03 14:26:36 +01:00
Rebecca Law
9e7a7b1857 Merge branch 'master' into refactor-send_notifications
Conflicts:
	tests/app/notifications/rest/test_send_notification.py
2016-10-03 11:40:31 +01:00
Rebecca Law
e3d418506a Create query to sum notificaitons for the message limit check, this is a bit more efficient.
Refactored send_notifications method so that it is more readible.
Refectored the test_send_notificaitons so that it uses parametrized test to avoid duplication.
2016-10-03 10:57:10 +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
Martyn Inglis
4e03f81fcf Updated mock import 2016-09-30 10:31:50 +01:00
Imdad Ahad
a7d42896cd Refactor tests 2016-09-28 17:03:17 +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
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
Imdad Ahad
f9b539d71e Fix conflict 2016-09-27 16:54:00 +01:00
Imdad Ahad
af2cbaa9c5 Fix PEP8 issues 2016-09-27 14:16:35 +01:00
Imdad Ahad
7b0cbca89b Enable sending to whitelist users if using a normal api key 2016-09-27 13:48:51 +01:00
Rebecca Law
0ef43ab1dc Fix the wording on the message a little bit. 2016-09-23 16:03:11 +01:00
Rebecca Law
09e6e6198b Fixing a bug that allows a sms notification to be sent with an email template and vice versa.
This has been resolved for the post notifications endpoint
2016-09-23 15:46:48 +01:00
Imdad Ahad
afd381badf Update links schema to be more strict and fix import 2016-09-20 10:39:15 +01:00
imdadahad
b07bbbbe16 Merge pull request #673 from alphagov/provide-simulated-numbers-live-keys
Add capability for simulated numbers and email addresses
2016-09-14 15:23:12 +01:00