Commit Graph

6987 Commits

Author SHA1 Message Date
Rebecca Law
d8c4733a5a Merge pull request #2654 from alphagov/validate-content-header-for-post-requests
Add validation for missing content-type header
2019-11-22 11:31:56 +00:00
Rebecca Law
6b09075779 Fix poorly written sentence 2019-11-22 11:02:22 +00:00
Rebecca Law
e0b4b258aa Shortened the length of time to check for messages with the wrong state.
There is a chance that the there is an outstanding retry task that has yet to run but the task that are replayed here protect against the task running twice. So this just means it might get sent sooner than later.
2019-11-21 15:51:27 +00:00
Rebecca Law
5d6886242b Check that the request payload data is valid json.
By adding `force=True` to request.get_json() the mime type is ignore. If the data is not valid json the method will return a `BadRequestError` we catch that and throw our own error with a clear error message "Invalid JSON supplied in POST data".
If the json is valid return the json data or an empty dict if None is passed in.

This PR improves the error messages if the json is invalid, previously, the error message was "None object type" message which is not very helpful.
2019-11-21 15:23:11 +00:00
Leo Hemsted
c78a5d8536 Merge pull request #2662 from alphagov/utils-bump
Utils bump
2019-11-21 15:23:11 +00:00
Rebecca Law
ac4f0e8027 After a comment from @idavidmcdonald, I asked myself why are not creating the task to upload the pdf and update the notification.
The assumption was that S3 would throw an exception if the object was uploaded twice. That's not the case the default behaviour is that if a file already exists it will be overwritten. So it is completely safe to run the task from the alert.

It can also mean that we don't need to wait 4hours 15 minutes. Shall I decease the amount of time before restarting the task?
2019-11-19 16:04:21 +00:00
Leo Hemsted
6e21c56327 Merge pull request #2662 from alphagov/utils-bump
Utils bump
2019-11-19 10:55:07 +00:00
Leo Hemsted
8f7f99234b use Template.is_message_too_long rather than content_count directly
this function returns false for emails and letters so we can clean up
the code and reduce duplication a little bit
2019-11-18 17:00:32 +00:00
Leo Hemsted
5e9a21f5d0 bump requirements 2019-11-18 15:48:38 +00:00
Rebecca Law
cd03f905c0 Merge pull request #2659 from alphagov/get-sender-id-from-metadata
Get sender id from metadata
2019-11-18 10:57:59 +00:00
Rebecca Law
918975b0a6 Use sender_id from CSV metadata.
When we upload a CSV for a job, we add the sender_id as metadata to the file that is uploaded on S3.
There is more than one place where we process rows from that CSV.
 - process_job
 - scheduled_job
 - check_for_missing_rows_in_completed_jobs
 - check_job_status

All of these places need to use the sender_id, now the sender_id is always read from the file metadata.
In a subsequent PR we can remove the optional sender_id parameter from process_job task.
2019-11-15 15:42:29 +00:00
Rebecca Law
6155f7666e Testing with latest 2019-11-15 15:42:24 +00:00
Rebecca Law
516190262a [WIP] 2019-11-15 15:41:27 +00:00
Rebecca Law
d25fcc8748 Merge pull request #2661 from alphagov/fix-billing-query
Fix query to populate ft_billing table.
2019-11-15 10:58:48 +00:00
Rebecca Law
db0d45966f Fix query to populate ft_billing table.
The group by for the query was wrong which would result in 2 rows with different totals but the same unique key, so the second row would update the first row. Meaning we had incorrect numbers for the billing data.
Because some of the data had null for the sent_by column, the select would turn the Null --> dvla, but that same function was not used in the group by. So any time we had missing sent_by data we would end up with 2 rows where one would overwrite the other.
2019-11-15 10:23:48 +00:00
Rebecca Law
c42420c329 Add an alert when a letter is created but doesn't have a file in S3 for sending. We can tell this is the case because there is no updated_at and billable units are still 0.
At this point we are just creating a zendesk ticket - perhaps we can just call the create_letter_pdf task.
2019-11-13 16:39:59 +00:00
Rebecca Law
0979b41562 Merge pull request #2656 from alphagov/exclude-old-jobs-from-check
Added a filter to restrict jobs older than a day from coming back.
2019-11-08 11:56:26 +00:00
Rebecca Law
8d042c36f4 Added a filter to restrict jobs older than a day from coming back.
This is only necessary because there is currently a job that is old, but had 1 row created a couple days later. So now there is 1 notifications for the job where the rest have been purged.
2019-11-08 10:37:37 +00:00
Rebecca Law
8276ecaa24 Merge pull request #2655 from alphagov/fix-error-message
Add the missing format for the log message
2019-11-07 15:27:37 +00:00
Rebecca Law
5aaf5cd588 Add the missing format for the log message when a missing row is processed. 2019-11-07 15:01:23 +00:00
Rebecca Law
5a11e10cbf Merge pull request #2653 from alphagov/check-for-missing-rows
Check for missing rows
2019-11-07 13:52:15 +00:00
Rebecca Law
559faf3034 Fix the query.
Missing the where clause to join the two tables.... OOPS
2019-11-07 10:57:31 +00:00
Rebecca Law
43c0122dd0 Fix db downgrade script 2019-11-06 13:54:16 +00:00
Rebecca Law
4da06f1d5d remove old db upgrade file 2019-11-06 11:17:01 +00:00
Rebecca Law
9def176e7a Fix typo in config 2019-11-06 10:56:37 +00:00
Rebecca Law
fd0c12912a Fix merge conflict with db upgrade 2019-11-06 10:54:38 +00:00
Rebecca Law
74546a265e Added cron for check_for_missing_rows_in_completed_jobs
Run the task every 10 minutes. Does that seem reasonable? Maybe that is too often.
2019-11-06 10:49:46 +00:00
Rebecca Law
db5a50c5a7 Adding a scheduled task to processing missing rows from job
Sometimes a job finishes but has missed a row in the middle. It is a mystery why this is happening, it could be that the task to save the notifications has been dropped.
So until we solve the missing let's find missing rows and process them.

A new scheduled task has been added to find any "finished" jobs that do not have enough notifications created. If there are missing notifications the job processes those rows for the job.
Adding the new task to beat schedule will be done in the next commit.

A unique key constraint has been added to Notifications to ensure that the row is not added twice. Any index or constraint can affect performance, but this unique constraint should not affect it enough for us to notice.
2019-11-06 10:49:46 +00:00
Leo Hemsted
975af113e4 Merge pull request #2639 from alphagov/remove-loadtesting-db-migration
remove loadtesting from the database
2019-11-06 10:49:46 +00:00
Leo Hemsted
7601ef0b8d Merge pull request #2639 from alphagov/remove-loadtesting-db-migration
remove loadtesting from the database
2019-11-05 15:14:23 +00:00
Leo Hemsted
59f1ce940d update tests to reflect no loadtesting provider 2019-11-05 15:01:55 +00:00
Leo Hemsted
4ed6ca1601 remove loadtesting from the database 2019-11-05 15:01:55 +00:00
Katie Smith
95ffc8bda6 Merge pull request #2651 from alphagov/tidy-fixtures
Tidy fixtures after Pytest 5 upgrade
2019-11-01 15:13:36 +00:00
Katie Smith
544a7a2311 Remove parameters from fixtures
Since Pytest 4, we can't call fixtures as if they were functions. This
change removes the parameters from the fixtures (since we can't use
them), except for when the parameter is another fixture.
2019-11-01 14:34:15 +00:00
Katie Smith
6411e10d7b Remove unused fixtures 2019-11-01 13:18:07 +00:00
Pea (Malgorzata Tyczynska)
2b1a84dd0d Merge pull request #2647 from alphagov/tell-users-why-letter-failed-validation
Grab metadata when getting pdf letter preview from S3
2019-11-01 10:19:53 +00:00
Katie Smith
51c509c0ac Merge pull request #2649 from alphagov/pytest-5-changes
Upgrade to Pytest 5 😅
2019-11-01 09:30:53 +00:00
Rebecca Law
6f9edf0c07 Merge pull request #2650 from alphagov/delay-10-before-killing
Change how the bash script is started.
2019-10-31 16:56:33 +00:00
Rebecca Law
fe18512dd2 Change how the bash script is started.
By adding `exec` to the entrypoint bash script for the application, we can trap an EXIT from the script and execute our custom `on_exit` method with checks if the application process is busy before terminating, waiting up to 10 seconds. We don't need to trap `TERM` so that's been removed again.

Written by:
@servingupaces
@tlwr
2019-10-31 16:41:16 +00:00
Katie Smith
e504410ced 🎉 Pytest 5 🎉 2019-10-31 15:50:37 +00:00
Katie Smith
8abe427cb7 Fix tests which call str() on exception messages
Since Pytest 5, `ExceptionInfo` objects (returned by `pytest.raises`) now
have the same `str` representation as `repr`. This means that `str(e)`
now needs to be changed to `str(e.value)`.

https://github.com/pytest-dev/pytest/issues/5412
2019-10-31 15:38:44 +00:00
Katie Smith
04c1c35efb Stop calling fixures as functions in the tests 2019-10-31 15:04:23 +00:00
Katie Smith
97b807a99d Add test function to create service whitelist
This will be used to stop us needing to call the `sample_service_whitelist` fixture as
a function.
2019-10-31 15:04:23 +00:00
Katie Smith
87d7ed21a2 Fix fixtures
Stopped 2 fixtures from calling other fixtures as functions and causing
errors.
2019-10-31 15:04:23 +00:00
Rebecca Law
c35aca25e0 Merge pull request #2645 from alphagov/trap-term
Catch the TERM signal in the run_app_*paas scripts
2019-10-31 10:46:41 +00:00
Katie Smith
ac1642d8db Merge pull request #2646 from alphagov/pytest-5-changes
Start making tests Pytest 4 compliant
2019-10-30 13:56:47 +00:00
Katie Smith
38243cf860 Stop calling fixtures as functions in the tests 2019-10-30 13:05:53 +00:00
Katie Smith
fb875c50c1 Stop fixtures in conftest from calling other fixtures
Stopped some the fixtures in conftest.py from calling other
fixtures as functions to make them Pytest 4 compliant.
2019-10-30 11:22:36 +00:00
Katie Smith
99c3837dc1 Fix the fixtures for templates lacking certain permissions
These fixtures were both calling other fixtures as functions and being
called as functions in the tests. Rewriting the tests to make them
Pytest 4 compatible means we are no longer using
`sample_template_without_letter_permission`, so this has been deleted.
2019-10-30 11:22:36 +00:00
David McDonald
6252dcf916 Merge pull request #2643 from alphagov/set-postage
Set postage
2019-10-30 10:22:33 +00:00