Commit Graph

64 Commits

Author SHA1 Message Date
Leo Hemsted
19bb0d157d reset notification to created if fake callback throws exception
else we ignore it when retrying
2017-10-16 15:49:13 +01:00
Richard Chapman
ce89a05038 Changes after review. Style changes to ensure consistency with the rest of the code base and changed the check of an asset message to be the full message to avoid any confusion in future. 2017-10-05 16:50:18 +01:00
Richard Chapman
7974e59eb7 Changes after review. Updates to style and import order to be more consistent with other code.
Added clarification to an error message to give better debugging information.
Removed using dao_get_reply_to_by_service_id in tests to be more consistent with other code and use the test db functions or remove the need for a call altogether making the code less complex.
2017-10-05 16:50:18 +01:00
Richard Chapman
d2168b7985 Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality. 2017-10-05 16:50:17 +01:00
Richard Chapman
2fbe492d5c [2/10] Allow API calls to specify the reply address option (#1291)
* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Minor update after manual merge to fix check style rule break in test_validators.py where a single space was introduced.

* Updates after code review. Moved the template from the exception message as it was not required and updated the error message to match the field name in the sschema for better debugging and error identification.

* Fixed test after update of exception message
2017-10-04 14:34:45 +01:00
Rebecca Law
0a21f1f3e8 Small refactor to how notification_schemas are tested.
My local build was not always getting the optional requirement for the jsonschema uri format checker (rfc3987).
The requirement has been added to the requirements_for_test file.
I changed the tests to validate the response schema from the post_notifications tests, this way we can tell if we are breaking the contract.
This showed that the email_from was not returning the entire email address but just the username, that has been corrected here.
Removed the response schema validation tests since they are not being testing in the post notification tests.
2017-09-11 11:10:45 +01:00
Ken Tsang
667ee57a35 Refactor code to use inbound_numbers if set 2017-08-16 12:50:44 +01:00
Leo Hemsted
2ab105aaf4 add tests for letter api notifications 2017-07-27 16:43:55 +01:00
Leo Hemsted
0ce9b94c36 Merge pull request #1075 from alphagov/letter-api-refactor
Letter api step 1 - refactor
2017-07-25 14:53:39 +01:00
Rebecca Law
d4bbca2592 Fix for simulated notifications.
When a post is made for a simulated number the id is empty in the notificaiton object that we return.
This fixes that.
2017-07-20 17:56:51 +01:00
Leo Hemsted
79e33073c9 raise 404 when unknown url
consistent with other endpoints.

also refactor of notification_schema to separate some fns to a different file
2017-07-20 15:23:51 +01:00
Leo Hemsted
9caf45451e make persist_notification require kwargs
when functions get as big as that, it's confusing to try and work out what
things are what. By including a * as the first arg, we require that anyone
calling the function has to use kwargs to reference the parameters
2017-07-19 17:02:19 +01:00
Leo Hemsted
7f4eec79e4 add POST letter schema
similar to sms/email, however, for consistency with response values
and internal storage, rather than supplying an "email_address" field
or a "phone_number" field, supply an "address_line_1" and "postcode"
field within the personalisation object.
2017-07-19 17:02:19 +01:00
Ken Tsang
e0fbcb0dc6 Add permission check in for v2 post notification 2017-07-06 12:27:57 +01:00
Ken Tsang
46a55c1cdb Refactor code 2017-07-06 12:27:57 +01:00
Ken Tsang
98cd838510 ken-use-only-new-service-permissions 2017-07-06 12:27:55 +01:00
Rebecca Law
40aadf2748 Merge pull request #991 from alphagov/invite-service-to-schedule
Invite the service to schedule notifications from the API
2017-06-01 12:37:32 +01:00
Rebecca Law
e3baf71016 Update error message 2017-05-31 16:22:56 +01:00
Martyn Inglis
75c5e5e5d5 Merge branch 'master' into redo-queue-visibitlity-timeout
Conflicts:
	app/notifications/process_notifications.py
	app/v2/notifications/post_notifications.py
2017-05-30 10:18:18 +01:00
Rebecca Law
3dc70b8c39 Check service.permissions for the existence of schedule_notifications if the notications is being created with a scheduled_for param. 2017-05-26 15:41:14 +01:00
Rebecca Law
f555c7a73b Refactor tests to use the create_notication in tests.app.db 2017-05-25 11:41:07 +01:00
Martyn Inglis
2591d3a1df This massive set of changes uses the new queue names object throughout the app and tests.
Lots of changes, all changing the line of code that puts things into queues, and the code that tests that.
2017-05-25 10:51:49 +01:00
Rebecca Law
9f6c037530 Use iso8601 to validate scheduled_for datetime.
Added a validation method that always fails for scheduled notifications.
Comment out config for scheduled task.
The schedule notifications will be turned on once we can invite services to use it.
Waiting for the service permission story, must commit this in order to keep things from going stale.
2017-05-24 16:27:15 +01:00
Rebecca Law
53efb4e033 Merge branch 'master' into schedule-api-notification
Conflicts:
	tests/app/v2/notifications/test_post_notifications.py
2017-05-23 13:58:50 +01:00
Leo Hemsted
86c9600b04 use config to get default sender rather than hardcoding
this means that on non-prod envs, it reflects that environment.

it needs to be a lamdba, because the column object is created at import
time, when current_app.config won't have been loaded - this means that
when you create a Service object, that lambda executes and grabs the
correct default value
2017-05-23 11:12:37 +01:00
Leo Hemsted
2535a7fe98 set sms_sender to be 'GOVUK' if not otherwise specified
this is a precursor to making the column non-nullable
2017-05-22 17:13:35 +01:00
Rebecca Law
a57dc18895 Add validation for scheduled_for where the date can not be in the past or more than 24 hours in the future. 2017-05-22 14:39:30 +01:00
Rebecca Law
751abb4b99 Update dateformat for scheduled_for to include minutes. 2017-05-22 14:15:35 +01:00
Rebecca Law
973cc2c4c9 Changed the scheduled_for datetime to only send and hour of a day to send.
Also expect the date being passed in is BST. The date is converted to UTC before saving. And converted to BST when returning a notification.
2017-05-17 15:06:15 +01:00
Rebecca Law
a6529d2723 Return the scheduled_for datetime in the DATETIME_FORMAT from the post_notification 2017-05-16 09:57:58 +01:00
Rebecca Law
f0e2713bef Add scheduled_for in the post notification request form.
Return scheduled for in get_notification requests.
2017-05-15 17:27:38 +01:00
Martyn Inglis
a9539d892c Merge branch 'master' into rate-limit-api-calls
Conflicts:
	requirements.txt
	tests/app/notifications/rest/test_send_notification.py
	tests/app/notifications/test_validators.py
	tests/app/v2/notifications/test_post_notifications.py
2017-05-02 10:56:56 +01:00
Martyn Inglis
99081488f1 Mock out some SQS calls 2017-04-27 12:47:08 +01:00
Martyn Inglis
84860b2a1d Adds a debug line to try and debug jenkins 2017-04-27 10:41:31 +01:00
Martyn Inglis
2a0f8c8808 Validate International phone numbers
- uses new utils methods to validate phone numbers
- defaults to International=True on validation. This ensures the validator works on all numbers
- Then check if the user can send this message to the number internationally if needed.
2017-04-26 15:56:45 +01:00
Martyn Inglis
926b8a60f9 Adds in call to new rate limit method in the redis client
- both V1 and V2 APIs
- Rate limiting wrapped into a new method - check_rate_limiting
	- delegates to the previous daily limit and the new though put limit
- Rate limiting done on key type. Each key has it's own limit (number of requests) and interval (time period of requests)
- Configured in the config. Not done on a per-env basis though could be in the future.
2017-04-24 14:15:08 +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
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
f66670c558 - Added logging to indicate that we created the notification and that we sent the notification to a delivery queue.
- Small updates as recommended by review comments.
2017-01-18 09:56:26 +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
Rebecca Law
bbdbb9079e Fixed the template uri for the post notification responses.
It was optimistic to think the v2 templates would be complete.
2017-01-04 11:22:50 +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
Rebecca Law
9973d74d09 Fix the from number in the post_sms_response. If the service.sms_sender is not set the FROM_NUMBER from the config is returned, which is the default for the notification. 2016-12-12 15:07:03 +00:00
Rebecca Law
57a8f8d7fa The body of the content in the response to a POST v2/notifications was not replacing the placeholders.
This PR fixes that and adds a test for it.

I am confused as to why I had to change the test_validators test that is checking if the mock is called.
Why did this code pass on preview?
2016-11-28 15:49:29 +00:00
Rebecca Law
fa422a85ef Fix unit test failure 2016-11-22 13:25:10 +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