Commit Graph

4100 Commits

Author SHA1 Message Date
Leo Hemsted
b1cccdcc6b First batch of flake8 changes.
Many unused variables, and replacing some old fixtures with
admin_request before I realised just how many there where 😩
2017-11-28 17:00:01 +00:00
Leo Hemsted
363105774f Merge pull request #1439 from alphagov/flake8
Flake8
2017-11-28 15:33:07 +00:00
Leo Hemsted
90e9a2f1b3 use flake8 instead of pycodestyle
since there are thousands and thousands of errors in the tests files
at the moment, i propose fixing those errors in separate PR for now.
2017-11-28 14:28:01 +00:00
Leo Hemsted
28088428f1 flake8 - misc flake8 errs.
* unused variables
* variables in loops overshadowing imports
* excepts with no defined exc type (tried to avoid `except Exception` too)
* history mapper is still too complex
* default variables should never be mutable
2017-11-28 14:28:01 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Leo Hemsted
043dee5a54 ensure no tests share the same name (using flake8's checker) 2017-11-28 14:28:01 +00:00
Leo Hemsted
3ee351b802 remove unused db.py and add flake8 config 2017-11-28 14:26:40 +00:00
Leo Hemsted
9a0c01fee5 Merge pull request #1436 from alphagov/click-tweaks
Click tweaks
2017-11-28 14:26:29 +00:00
Rebecca Law
a7232381bf Merge pull request #1433 from alphagov/add-reply-to-notifications
Populate reply-to-text field in notifications
2017-11-28 13:19:36 +00:00
Leo Hemsted
5b7118973e take advantage of click's type validation/coercion
(saves us having to write the stuff ourselves). Also adds a small
click plugin to do datetime parsing.

Sample output:

```
[leohemsted:~/dev/api]$ flask command create_provider_rates --help
Usage: flask command create_provider_rates [OPTIONS]

  Backfill rates for a given provider

Options:
  -p, --provider_name [mmg|firetext|ses]
                                  [required]
  -c, --cost FLOAT                Cost (pence) per message including decimals
                                  [required]
  -d, --valid_from DATE           [required]
  --help                          Show this message and exit.
[leohemsted:~/dev/api]$ flask command create_provider_rates -p ses -c 1.234 -d invalid
Usage: flask command create_provider_rates [OPTIONS]

Error: Invalid value for "-d" / "--valid_from": Could not parse datetime string "invalid" formatted as %Y-%m-%dT%H:%M:%S
```
2017-11-28 12:50:29 +00:00
Rebecca Law
b0d88ec08c Updates as per review comments 2017-11-28 11:05:56 +00:00
Leo Hemsted
300ff0ebf6 Merge pull request #1435 from alphagov/fix-bad-test
fix test that did not depend on the notify-db-session fixture, so left a messy db
2017-11-28 11:02:55 +00:00
Leo Hemsted
2b54c2308b fix test that did not depend on the notify-db-session fixture, so left a messy db 2017-11-28 10:42:54 +00:00
Leo Hemsted
721202b44f use more click functionality to reduce our own codes' complexity 2017-11-28 10:35:46 +00:00
Leo Hemsted
fa3b48b357 Merge pull request #1421 from alphagov/celery-fix
celery.task.retry exc param should be a throwable.
2017-11-28 10:19:14 +00:00
Rebecca Law
ab5b7c20a7 Use sms sender or reply to email address of the Notify service in create_2fa_code depending on message type. 2017-11-27 16:52:52 +00:00
Venus Bailey
9af2b54e48 Merge pull request #1413 from alphagov/pyup-update-boto3-1.4.7-to-1.4.8
Update boto3 to 1.4.8
2017-11-27 16:09:25 +00:00
Leo Hemsted
1e4a480298 only catch s3 and db errors in build-dvla-file-for-job
this reduces the amount of error messages we log (we'll no longer log
at error level when build-dvla-file-for-job retries while waiting for
the task to finish), and make sure we retry in those cases above - db
or s3 having temporary troubl
2017-11-27 15:11:58 +00:00
Leo Hemsted
b6ac7f074d celery.task.retry exc param should be a throwable.
This causes an issue when it hits the max retry limit, and tries to
throw your exception to let you deal with it - at this point it was
moaning because we pass in a string

if it's not defined, and we're inside an exception block celery uses
that instead.
2017-11-27 14:55:29 +00:00
Rebecca Law
4ecf168590 Upate test for persist_notification 2017-11-27 14:45:34 +00:00
venusbb
3945007d24 add reply-to-text to user/rest persist notifications 2017-11-27 14:36:54 +00:00
Leo Hemsted
2ddf05a645 Merge pull request #1432 from alphagov/cf-deploy-sleep
Add sleep after stopping the old app instances on deploy
2017-11-27 14:15:09 +00:00
venusbb
e1175542b7 add reply-to-text to send notification to service users 2017-11-27 14:05:04 +00:00
Rebecca Law
ecde8b6575 Merge pull request #1431 from alphagov/add-reply-to-model
Add reply_to_text to Notification model.
2017-11-27 14:04:54 +00:00
venusbb
a97d946d2d Merge branch 'master' of https://github.com/alphagov/notifications-api into add-reply-to-notifications 2017-11-27 13:53:37 +00:00
Leo Hemsted
bcee95214e Add sleep after stopping the old app instances on deploy
sleep for 10 seconds to try and make sure that all worker threads
(either web api or celery) have finished before we delete when we
delete the DB is unbound from the app, which can cause
"permission denied for relation" psycopg2 errors.
2017-11-27 13:46:39 +00:00
Rebecca Law
86098041fa Add reply_to_text to Notification model.
This was missed out of the previous PR and needs to be there before the next PR is merged.
2017-11-27 13:39:35 +00:00
Richard Chapman
e2dad7c94e Merge pull request #1430 from alphagov/rc-monthly-template-usage-endpoint
Removed the templates/monthly endpoint
2017-11-27 13:05:00 +00:00
Rebecca Law
530f2e7f6a Update invite user endpoint to set the reply_to_text on the notification.
Update v1 post notifications to set the reply_to_text on the notification.
2017-11-27 12:30:50 +00:00
Rebecca Law
12024e9619 Update save_letter task to save the default letter contact block when creating the notification. 2017-11-27 11:33:04 +00:00
Richard Chapman
adfba208c4 Removed the templates/monthly endpoint
Removed the REST endpoint and the DAO that it uses as the endpoint is
no longer used by the Admin UI and the DAO is not reused anywhere
else.

- Removed REST endpoint
- Removed DAO which gets the stats
- Removed associated tests of both methods
2017-11-27 11:06:43 +00:00
Alexey Bezhan
1971d7d4b3 Merge pull request #1425 from alphagov/enable-firetext-inbound-sms-auth
Abort unauthenticated requests for Firetext inbound SMS
2017-11-27 10:45:34 +00:00
Rebecca Law
5450af661e Merge branch 'master' into add-reply-to-notifications 2017-11-27 10:40:02 +00:00
Rebecca Law
049daa0cb8 Save reply_to_text for one off notiications and csv notificaitons. 2017-11-25 11:31:36 +00:00
Rebecca Law
d779751bae Set reply_to_text for letter notifications posted to /notifications/letter 2017-11-24 16:17:25 +00:00
Leo Hemsted
b7d5e80509 Merge pull request #1423 from alphagov/fix-firetext-inbound-500s
fix 500s when inbound msgs sent from alphanumerics rather than normal…
2017-11-24 15:39:39 +00:00
Leo Hemsted
a084d45487 Merge pull request #1426 from alphagov/celery-cf-stop-errors
remove cf stop to try and improve deploy robustness
2017-11-24 15:17:47 +00:00
Leo Hemsted
03dcd46b59 Merge pull request #1427 from alphagov/fix-commands
ensure the app context is included in every single flask command
2017-11-24 12:18:20 +00:00
Leo Hemsted
4c14e3279f ensure the app context is included in every single flask command 2017-11-24 12:01:28 +00:00
Leo Hemsted
4d75f032c6 remove cf stop to try and improve deploy robustness
Rationale:
Sometimes, when deploying, we've seen errors while stopping the old
apps: "(psycopg2.ProgrammingError) permission denied for relation notifications".

When you call cf stop, it may not be entirely synchronous. Under the
hood, cloudfoundry has to do a whole bunch of things when you stop an
app - it has its own internal db of what app states are, and also has
to remove it from any load balancers etc, and also it has to actually
stop the app. We're not sure if the `cf stop` command guarantees that
your process has already terminated by the time that the command
returns.

In our Makefile, we call `cf stop`, followed by `cf delete`. One
posisble theory is that the process is still running when `cf stop`
exits, and then `cf delete` unbinds that service from the database,
removing all of it's users' permissions.

This isn't confirmed, however, this commit removes the `cf stop`
command to see if it solves the issue. PaaS team confirmed that
it's redundant - `cf delete` will carry out the same tasks under
the hood.
2017-11-24 10:53:16 +00:00
Leo Hemsted
fcf3932bb4 Merge pull request #1418 from alphagov/remove-flask-script
Remove flask script
2017-11-24 10:28:56 +00:00
Alexey Bezhan
87f99b6edb Merge pull request #1402 from alphagov/fix-migrations
Add a script to fix migration ordering conflicts
2017-11-24 10:14:15 +00:00
Alexey Bezhan
e813f1ff87 Add a script to fix migration ordering conflicts
When generating a new migration we give it a number that increments
the latest existing migration on master. This means that when there
are multiple PRs open containing a migration and one of them gets
merged the others need to be updated to move their migration files
to apply on top of the recently merged one.

This requires renaming the file and changing migration references
for both the migration revision and down_revision.

If a PR introduced more than 1 migration they all need to be updated
one after another since each one needs to be renamed.

This adds a script to simplify this process. `./scripts/fix_migrations.py`
will check for any branch points If it finds exactly one (which
should be the common case), it asks which migration should be moved
and renames / updates references to move the selected branch on top
of the other one.

It won't resolve any conflicts within migrations themselves (eg if
both branches modified the same column) and it won't try to resolve
cases with more than 1 branch.
2017-11-24 09:58:41 +00:00
Alexey Bezhan
4d48421767 Abort unauthenticated requests for Firetext inbound SMS
Switches on authentication checks for Firetext inbound SMS callbacks.

This should only be released once Firetext callback URLs have been
updated with authentication details.
2017-11-23 17:17:37 +00:00
Leo Hemsted
61b28ca523 update bootstrap to use new command 2017-11-23 17:12:13 +00:00
Leo Hemsted
5466b7cd3c fix test create_app invocation 2017-11-23 17:04:58 +00:00
Leo Hemsted
d30a8b83c1 update readme and ensure makefile up to date 2017-11-23 17:04:58 +00:00
Leo Hemsted
b727f53836 ensure app can run on paas
instead of using wsgi, we now use "application" - this tells gunicorn
to look inside the python module application (application.py) for a
wsgi app - and by default that is also called application so rename
the variable.

Also, when running tasks, we're not using gunicorn so need to set the
flask variable in the manifest so that `flask command ...` finds the
app properly.

Remove server_commands as it's not used any more.
2017-11-23 17:04:58 +00:00
Leo Hemsted
cd6f85281c any apps that use current_app need to be in a context
to achieve this, the decorator flask.cli.with_appcontext is used. Not sure why it
hasn't applied by default /shrug
2017-11-23 17:04:58 +00:00
Leo Hemsted
6d45a887c5 remove wsgi 2017-11-23 17:04:58 +00:00