Commit Graph

43 Commits

Author SHA1 Message Date
Rebecca Law
1f9aade749 - Adding test where post_notification can't send to a member outside of the team or whitelist.
- Updating some tests to be pytest4 compliant.
2019-06-11 16:45:35 +01:00
Pea Tyczynska
9a76d6706e Update tests to match the new csv data 2018-12-07 11:24:15 +00:00
Leo Hemsted
d9aa220aa6 move folders and templates to other folders
new endpoints:
/services/<service_id>/move-to-folder
/services/<service_id>/move-to-folder/<target_template_folder_id>

* takes in a dict containing lists of `templates` and `folders` uuids.
* sets parent of templates and folders to the folder specified in the
  URL. Or None, if there was no id specified.
* if any template or folder has a differen service id, then the whole
  update fails
* if any folder is an ancestor of the target folder, then the whole
  update fails (as that would cause a cyclical folder structure).
* the whole function is wrapped in a single `transactional` decorator,
  so in case of error nothing will be saved.
2018-11-08 17:13:00 +00:00
Leo Hemsted
69e08fa23b fix tests to create notifications properly
migrated away from calling fixtures as functions
2018-09-25 16:10:26 +01:00
Katie Smith
af5c4d2872 Include the notification sender name when serializing notifications
The `serialize` method of the Notification model now includes the
`created_by_name`. If a notification was sent as a one-off message this
value will now be the name of the person who sent the notification. If
a notification was sent through the API or by a CSV upload we don't
record the id of the sender, so `created_by_name` will be `None`.

This change affects the data that gets returned from these endpoints:
* /v2/notifications/<notification_id>
* /v2/notifications
2018-07-20 09:37:50 +01:00
Ken Tsang
7011b90bd4 Refactor is_precompiled_letter to model 2018-03-07 23:03:03 +00:00
Ken Tsang
c14663d84a Fix serialization on precompiled letter
Postcodes are required for created letters, but not for precompiled, this fix allows postcodes to be None in the model.
As postcodes are still required for created letter they should be caught by validation schemas in the POST handler
2018-02-26 13:53:06 +00:00
Ken Tsang
3355a29d01 Ensure letter personalisation is serialized correctly
The personalisation for letters can take different formats depending on
how the letter was generated, for example it can contain either
address_line_1 or addressline1. This change ensures that it is always
serialized in the same way.
2018-01-24 16:44:14 +00:00
Rebecca Law
fd217e67f5 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-15 12:33:38 +00:00
Alexey Bezhan
0825177f2d Add tests for notification.template returning the right version
Adds test for:
* checking the template version foreign key constraint
* checking that template changes don't affect existing notifications
* notification statistics aren't affected by different template versions
* notification stats always return the current template name
2017-11-10 15:13:55 +00:00
Alexey Bezhan
94dae42902 Avoid assigning notification.template when creating test objects
`Notification.template` changed from being a Template relationship
to TemplateHistory. When a relationship attribute is being assigned,
SQLAlchemy checks that the assigned value type matches the relationship
type. Since most tests at the moment create a notification using a
Template instance this check fails.

Rewriting the tests to use TemplateHistory objects would require
changes to the majority of tests. Instead, when creating a notification
objects we assign the foreign key attributes directly. This skips the
SQLAlchemy type check, but we still get the constraint check on the
foreign keys, so a matching TemplateHistory object needs to exist in
the database.
2017-11-10 15:12:07 +00:00
Rebecca Law
0054361044 Refactor the sms sender code to remove any unused methods.
Refactor tests/db/create_service() to behave more like the real world.
Created new create_service_with_inbound_number and create_service_with_defined_sms_sender() test/db methods.
2017-11-07 14:26:18 +00:00
Rebecca Law
4eec11b633 Added an optional parameter in the form for POST /v2/notifications/sms and /service/<service_id>/send-notification to pass in the SMS sender id.
The send_sms_to_provider still needs to use the SMS sender being passed in to the POST.

As part of https://www.pivotaltracker.com/story/show/152106587
2017-10-30 13:36:49 +00:00
kentsanggds
d39bf96324 Merge pull request #1333 from alphagov/ken-handle-dvla-response-file
Handle DVLA response file
2017-10-26 11:09:09 +01:00
Ken Tsang
a2b42194cd Add letter status received to data model
- in order to reduce the number of statuses in the database the letter status `received` will be mapped to `delivered` internally
2017-10-25 10:48:35 +01:00
Rebecca Law
8d6c38e1fe Now that we allow multiple SMS senders for a service, update the sender for SMS to be the default SMS sender, regardless if it is inbound number or not 2017-10-24 13:37:17 +01:00
Rebecca Law
cefb74c732 Removed a test that should have been removed during the last merge 2017-10-04 13:49:01 +01:00
Rebecca Law
ba7cd79581 Created a get_default_sms_sender method, which returns the default sms_sender from the service_sms_sender table rather than service.sms_sender.
One step closer to removing services.sms_sender.

fix the unit tests
2017-10-02 10:29:00 +01:00
Ken Tsang
366d07dbbe Add ServiceLetterContact data model and script 2017-09-21 16:08:49 +01:00
Rebecca Law
08fdcbfc67 Merge pull request #1266 from alphagov/use-reply-to-from-new-table
Use reply to email address from new table
2017-09-21 09:54:52 +01:00
Leo Hemsted
4174c72f21 allow 'accepted' as a proxy for created + sending as well as 'failed' for the three failure types when querying the api 2017-09-20 15:30:14 +01:00
Leo Hemsted
cb3379d0b6 rename received_by_notify to accepted
accepted is nice since it both implies that things look good, while
not being commital about next steps.
2017-09-20 11:20:51 +01:00
Leo Hemsted
4936fa384c return fake "received_by_notify" status for letter notifications
created and sending aren't quite as helpful for letters, since their
journey through notify and our providers is so different to emails/sms.
So instead, we should return estimated_dispatch_date (in a future PR)
and the status should just read received_by_notify
2017-09-20 11:20:13 +01:00
Rebecca Law
a53a0da414 [WIP] need to fix the tests 2017-09-20 10:45:35 +01:00
Ken Tsang
667ee57a35 Refactor code to use inbound_numbers if set 2017-08-16 12:50:44 +01:00
Ken Tsang
cfabab0785 Refactor code to add updated_at 2017-08-11 12:56:59 +01:00
Leo Hemsted
da02ffa32f ensure template history serializes using template serialize fn 2017-08-09 12:24:35 +01:00
Leo Hemsted
c9762f75a1 make sure template serialises letter subjects 2017-08-09 11:56:52 +01:00
Leo Hemsted
5d61b3644c add tests for new test-key handling 2017-08-02 11:14:05 +01:00
Leo Hemsted
38bb4ad6c2 notification.personalisation now always returns an empty dict
There are a variety of ways a notification can be created - via the
API, via CSV, via one-off messages, via the same but sent as a test -
the point is, there are lots of entry points, and lots of inconsistency
about how personalisation may be sent in. If there are no
personalisation options in the template, we may get either `None` or
`{}` - if the value is None, to avoid an error in our encryption lib,
we just store None in the database.

THIS ENDS NOW!

We've had some problems on the front-end that is caused by
notifications having the `None` value. This commit changes the
personalisation property getter and setter to store/return `{}`
rather than None.
2017-07-06 12:30:07 +01:00
Leo Hemsted
fd4e27bfd3 add type conversion to report downloads
"sent" is fine as an internal marker but not very obvious to the end
user that it specifically refers to international messages. We now
say "Sent internationally" in the CSV
2017-04-28 11:00:55 +01:00
Imdad Ahad
49fb4823e3 Refactor tests 2017-04-21 11:07:45 +01:00
Imdad Ahad
9fbd43c072 Serialise notifications for csv separately:
* Introduces separate method on Notification to serialise the notification
* ready for csv output
* Fixes issue where job_row_number = 0 not being accounted for correctly
2017-04-20 11:52:00 +01:00
Paul Craig
57a0d7295d Rewrite failed statuses
There are no more notifications whose statuses are "failed", as
the "failed" status has now been replaced with statuses that are
more specific about the nature of the failure.

However, we still want to be able to filter by failing
notifications. (ie "/v2/notifications?status=failed").

Created a `.substitute_status()` method which takes a status
string or list of status strings and, if it finds 'failure',
replaces it with the other failing status types.

This way, calling for nottifications with "?status=failed" is
internally treated as
"status = ['technical-failure', 'temporary-failure', 'permanent-failure']"
2016-11-25 15:23:46 +00:00
Paul Craig
1fce30aaa7 Cost savings
The "cost" value was flawed for a couple of reasons.

1. Lots of messages are free, so in those instances the "cost"
   doesn't tell you anything
2. The query to get the rate was expensive and we don't have
   an obvious way to get it back very efficiently for large numbers
   of notifications.

So we scrapped it.
2016-11-25 15:23:03 +00:00
Paul Craig
a17adb4707 New test for notification.cost() method
Added a test that asking for a nonexistent provider_rate blows
everything up.

Also updated existing test to use a weirder number.
2016-11-22 18:01:16 +00:00
Paul Craig
fddb1653ac Add .cost() to notification model
In the V2 API, the GET response for an individual notification
returns a 'cost' value, which we can get by multiplying the
billable units by the per-message rate of the supplier who
sent the message.
Any notifications with billable units > 0 but without a
corresponding `ProviderRates` entry will blow up the application,
so make sure you've got one.
2016-11-18 17:50:39 +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
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
Imdad Ahad
8184eff15a Update ServiceWhitelist to conform to new data model 2016-09-27 13:44:29 +01:00
Leo Hemsted
2e16be18bc Merge branch 'master' of github.com:alphagov/notifications-api into service-whitelist 2016-09-23 10:14:42 +01:00
Leo Hemsted
5c5ca26630 Add ServiceWhiteList model with corresponding tests 2016-09-22 11:58:51 +01:00
Martyn Inglis
99250b2248 Adds a builder method to the notification object.
This is used to construct a notification from the sorts of data an API call provides. This is used in both the db-email / db-sms tasks and the notifications rest endpoint to construct the notification DB object.
2016-09-07 13:44:56 +01:00