Commit Graph

128 Commits

Author SHA1 Message Date
Ken Tsang
5f945ab30e Refactored code, changed now to utcnow in test 2017-03-29 11:47:41 +01:00
Ken Tsang
af78efd137 Fix get_detailed_services BST 2017-03-29 11:03:28 +01:00
Leo Hemsted
d639aa22df skip failing timezone test
TODO fixme
2017-03-28 14:02:47 +01:00
Rebecca Law
f880604c85 First attempt at securing the endpoints.
Started with adding a before_request event to the service_blueprint, which executes the requires_admin_auth method rather than the require_auth method.

Obviously this is not done but want to get this in front of people to get an opinion.
2017-03-16 10:42:45 +00:00
Imdad Ahad
36d52c6e42 Add template type to response and refactor 2017-03-08 12:01:38 +00:00
Imdad Ahad
520c588d56 Add endpoint to retreive stats for service by template per month 2017-03-08 12:01:38 +00:00
Chris Hill-Scott
cffd0c2c54 Remove weekly stats endpoints
The weekly stats endpoint wont be used once
https://github.com/alphagov/notifications-admin/pull/1109 has been
merged.

It has been replaced with a new monthly endpoint in
https://github.com/alphagov/notifications-api/pull/807
2017-02-08 13:16:41 +00:00
Rebecca Law
30ca9e7e78 Merge pull request #811 from alphagov/check-service-is-active
Check service is active
2017-02-02 11:59:28 +00:00
Leo Hemsted
855a412c90 Merge pull request #812 from alphagov/plat-adm-dates
make sure we convert strings to dates before we use them
2017-01-31 16:24:30 +00:00
Leo Hemsted
cd47dbd36b make sure we convert strings to dates before we use them
fixes 500 on platform admin page
2017-01-31 16:12:46 +00:00
Rebecca Law
dab89969cc If the service is inactive at the time of sending the notification to the provider, the notification is marked as technical-failure.
Removed the /service/<id>/deactivate endpoint, now using /service/<id>/archive
2017-01-31 14:28:25 +00:00
Chris Hill-Scott
56ba653f48 Add endpoint for breakdown of activity by month
This endpoint will eventualy replace the weekly breakdown one. By month
for a given financial year is better, because it gives us consistency
with the breakdown of financial usage (and eventually consistency with
the template usage).

The code to do this is a bit convoluted, in order to fill out the counts
for months and statuses where we don’t have notifications.

This will make the admin side of this easier, because we can rely on
there always being numbers available. The admin side will deal with
summing the statuses (eg `temporary-failure` > `failed`) because this
is presentational.

This commit also modifies the usage count to use `.between()` for
consistency.
2017-01-31 14:16:34 +00:00
Leo Hemsted
3113f49271 Merge pull request #810 from alphagov/letter-fix
fix api statistics to account for letters
2017-01-31 12:29:35 +00:00
Leo Hemsted
0d089a383e fix tests in service/test_rest.py 2017-01-31 12:06:25 +00:00
Rebecca Law
539ebdce70 This is what I meant to test 2017-01-31 11:45:35 +00:00
Rebecca Law
907a1e91ac Removed the need for 2 return statements.
Update tests to fix copy/paste errors, use freezetime to ensure there is never a random failing test.
2017-01-31 11:33:36 +00:00
Leo Hemsted
3cd8605e11 fix api statistics to account for letters 2017-01-31 11:32:53 +00:00
Rebecca Law
87556687ab This is the first PR in the story to create a suspend service feature.
- Renaming /service/<id>/deactivate to /service/<id>/archive to match language on the UI.
  - Will need to update admin before deleting the deactive service method
- Created dao and endpoint methods to suspend and resume a service.
- I confirm the use of suspend and resume with a couple people on the team, seems to be the right choice.

The idea is that if you archive a service there is no coming back from that.
To suspend a service is marking it as inactive and revoking the api keys. To resume a service is to mark the service as active, the service will need to create new API keys.
It makes sense that if a service is under threat that the API keys should be renewed.

The next PR will update the code to check that the service is active before sending the request or allowing any actions by the service.
2017-01-30 16:32:44 +00:00
Chris Hill-Scott
4e60265c58 Add tests for billable unit rest endpoint
Doesn’t do extensive tests through the DAO layer, we have separate tests
elsewhere for that. This just tests the query parameter validation.
2017-01-27 11:47:40 +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
Rebecca Law
0ec84ff5e8 Refactor the get_detailed_services so that the start and end date are not defaulted to None.
Set the start and end date to today's date if they are not set in the request.args
2016-12-29 13:50:41 +00:00
Rebecca Law
8ad078b663 Added a date range filter for the get all services end point.
When the start_date and end_date query argruments exists in the request,
the query will return the results from the NotificationHistory table for the given date range.
We will need to check the performance of this query, but this will only be used by the platform admin page.
2016-12-28 15:39:55 +00:00
Jenny Duckett
d2649aebc8 Add include_from_test_key parameter to /service
We want to be able to toggle the numbers on the platform admin page between
including and excluding notifications sent using test keys, so that we can see
both real use of the platform and all load on it.

This parameter defaults to True, which is the existing behaviour.
2016-12-05 17:50:52 +00:00
Leo Hemsted
d706d86c9c don't re-delete already archived/revoked templates/api-keys 2016-11-14 14:10:40 +00:00
Leo Hemsted
195f3615e6 add test that if we have an exception, nothing is committed 2016-11-11 14:40:25 +00:00
Leo Hemsted
9ae6e14140 move deactivate functionality into one database transactions
this means that any errors will cause the entire thing to roll back

unfortunately, to do this we have to circumvent our regular code, which calls commit a lot, and lazily loads a lot of things, which will flush, and cause the version decorators to fail. so we have to write a lot of stuff by hand and re-select the service (even though it's already been queried) just to populate the api_keys and templates relationship on it
2016-11-11 11:20:41 +00:00
Leo Hemsted
e8c3a5cdde add check for inactive services to auth handler
cleaned up some auth code to marginally improve efficiency of error checking
and hopefully make it easier to read

fixed some incorrect auth headers in the deactivate tests
2016-11-10 11:07:12 +00:00
Leo Hemsted
b0e240267a add only_active flag to get services functionality 2016-11-09 15:07:23 +00:00
Leo Hemsted
d4a300ec7a add only_active flag to GET /services/
does what it says on the tin
2016-11-09 11:45:39 +00:00
Leo Hemsted
3cbacecf19 fix non-functional/overengineered existing tests 2016-11-09 11:32:07 +00:00
Leo Hemsted
089ac099f3 POST /service/{id}/deactivate deactivates a service:
* set active=False on the service
* renames service to "_archived_{old_name}"
* archives all templates for the service
* revokes all api keys for the service
2016-11-08 17:10:28 +00:00
Leo Hemsted
da2fa5b4bc move sqlalchemy defaults from booleans to SQL constructs
booleans aren't actually allowed, and quietly do nothing

also default Services.active to true
2016-11-08 17:10:28 +00:00
Leo Hemsted
a45c62d41d add can_send_letters flag to services
defaults to false
2016-10-26 13:01:40 +01:00
Chris Hill-Scott
def1d253aa Add endpoint to get billable units/financial year
`/services/ef7a665d-11a4-425a-a180-a67ca00b69d7/billable-units?year=2016`

Pretty much just passes through to the DAO layer. Validates that year
is:

- present (there’s no need for unbounded queries on this endpoint)
- an integer
2016-10-03 15:50:55 +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
d258e29edc Fix conflict 2016-09-27 14:05:29 +01:00
Imdad Ahad
99cfa7bae2 Fix url to get from whitelist endpoint 2016-09-27 13:51:43 +01:00
Leo Hemsted
eedc1f2093 tests for service whitelist rest 2016-09-23 12:24:53 +01:00
Chris Hill-Scott
21f3448fbc Use client fixture 2016-09-23 10:41:37 +01:00
Chris Hill-Scott
ba71079f22 Reduce indentation 2016-09-23 10:41:37 +01:00
Chris Hill-Scott
d7bb83fadf Optionally get notifications created w/ test key
This is only for the method that the admin app uses; it doesn’t affect
the public get notifications endpoint.
2016-09-23 10:40:33 +01:00
Chris Hill-Scott
4217bd2108 Optionally get only notifications created by API
This commit adds the `include_jobs` filter to the
`GET /services/…/notifications` endpoint. It defaults to `True` (ie show
all notifications) but makes it possible to only return notifications
created by _any_ API key.

This is so that we can show a log of all notifications sent through the
API in the admin app.

It does not expose this list to the public `GET /notifications` endpoint
because this would violate our rules about keys only being able to get
notifications created with keys of the same type.
2016-09-22 11:17:46 +01:00
Martyn Inglis
fe5d53bd70 Ensure GET /notifications/ by service ID returns CSV and API data - used by ADMIN console.
- this is existing functionality mimicked.
2016-09-15 16:00:46 +01:00
Leo Hemsted
556b69a487 still return service if they have never sent any notifications 2016-08-24 15:00:51 +01:00
Leo Hemsted
29df7edaf9 tests for detailed services 2016-08-24 15:00:51 +01:00
Leo Hemsted
5491668579 let users set organisation on POST /service/{id} 2016-08-15 10:54:26 +01:00
Leo Hemsted
cc7ea8043c add organisation and branding to GET /service response dict 2016-08-12 11:40:57 +01:00
Leo Hemsted
143cfb526c change update_provider_stats to use billable_units
updated tests etc, and removed some old tests that are no longer relevant
2016-08-03 17:22:20 +01:00
Leo Hemsted
05ef4911b1 use freeze_time whenever we mess with dates
also fixed a gotcha where an object was created in a fixture, so the freezetime decorator didn't apply
2016-08-02 11:02:59 +01:00