Commit Graph

4649 Commits

Author SHA1 Message Date
Katie Smith
a6dae2c81b Remove unnecessary code to do with testing service name uniqueness
notifications-admin has now been changed to always pass the service_id
to the 'service/unique' endpoint. This means we don't need to cover the
case of there being no service_id and the tests can also be updated.
2018-02-15 16:32:09 +00:00
Rebecca Law
c94cbb02b1 Merge pull request #1671 from alphagov/fix-uuid-validation
Fix UUID validate in the JSON schema
2018-02-15 14:23:02 +00:00
Rebecca Law
52bf6dabcd The regex to validate uuids was not rejecting uuids with a space at the end.
Switched to using a isinstance check on the string.
Added an order by clause to dao_get_template_usage_stats_by_service, it was causing an itermitten failure in the tests.
2018-02-15 13:34:06 +00:00
Chris Hill-Scott
bacfe79501 Merge pull request #1667 from alphagov/wra
Add letter logo for Welsh Revenue Authority and East Riding of Yorkshire Council
2018-02-15 12:00:02 +00:00
Alexey Bezhan
8a67b714e2 Merge pull request #1651 from alphagov/eventlet-celery-workers-service-callbacks
Switch service callback workers to use eventlet pool implementation
2018-02-15 11:08:54 +00:00
Chris Hill-Scott
f4be8fd80b Add East Riding of Yorkshire Council to migration 2018-02-15 11:08:17 +00:00
Chris Hill-Scott
f55f555e4d Add letter logo for Welsh Revenue Authority
Depends on:
- [ ] https://github.com/alphagov/notifications-template-preview/pull/94
2018-02-15 11:08:16 +00:00
Rebecca Law
019a6ef1e4 Merge pull request #1657 from alphagov/fix-template-versions
Fix template version for admin app
2018-02-15 10:14:58 +00:00
Rebecca Law
4820365b13 Rename migration file so that the force db migration part of the deploy does not trigger 2018-02-15 09:47:28 +00:00
Rebecca Law
a56f3b206f Merge branch 'master' into fix-template-versions 2018-02-15 09:45:56 +00:00
Chris Hill-Scott
de11751919 Merge pull request #1661 from alphagov/pytest-env
Automatically set environment vars before tests
2018-02-15 09:34:49 +00:00
Chris Hill-Scott
781bae2523 Merge pull request #1663 from alphagov/fail-fast
Stop pytest on 10th failing test
2018-02-15 09:34:42 +00:00
Rebecca Law
d8b062a960 Merge pull request #1664 from alphagov/switch-to-pdf-flow
Switch to using the pdf letter flow.
2018-02-14 15:36:12 +00:00
Rebecca Law
12352a4153 Merge pull request #1635 from alphagov/remove-failed-as-a-status
Remove failed as a possible status
2018-02-14 14:35:01 +00:00
Chris Hill-Scott
faa76755c3 Allow up to 10 tests to fail before stopping
This is a sensible compromise between 1 test and ALL THE TESTS.

Uses the `maxfail` option as documented here:
https://docs.pytest.org/en/latest/usage.html#stopping-after-the-first-or-n-failures
2018-02-14 13:27:06 +00:00
Chris Hill-Scott
845aad1183 Remove environment_test.sh
These config variables are now set in `pytest.ini` instead.
2018-02-14 12:19:13 +00:00
Chris Hill-Scott
d36b742e14 Automatically set environment vars before tests
Sometimes you just wanna run some tests directly using the `pytest`
command. But you’re in a new shell, and have forgotten to do
`source environment_test.sh`. The screen fills with red, and your day
just got a little bit worse.

This commit will stop this from ever happening again, by making the
setting environment variables part of running Pytest. It does this with
a plugin called pytest-env[1].

pytest.ini is the standard way of configuring pytest. Creating this file
where it didn’t exist before changes the behaviour of pytest, in that
it will now look for tests in the same directory as the file, rather
than defaulting to the `tests/` directory. So we also have to explicitly
configure pytest[2] to tell it that it should only look in this
directory. Otherwise it gets lost in the weeds of `node_modules`.

This also changes the way that `SQLALCHEMY_DATABASE_URI` is overriden to
the convention used by this plugin.

1. https://github.com/MobileDynasty/pytest-env
2. https://docs.pytest.org/en/latest/customize.html#confval-testpaths

fixup! Remove environment_test.sh
2018-02-14 12:19:12 +00:00
Chris Hill-Scott
e87ed0f68a Stop pytest on first failing test
If a PR is going to fail because tests aren’t passing then you:
- should know about it as quick as possible
- shouldn’t waste precious Jenkins CPU running subsequent tests

This commit adds the `-x` flag to pytest, which stops the test run as
soon as one failing test is discovered.
2018-02-14 11:54:40 +00:00
Leo Hemsted
15c2a9461e Merge pull request #1658 from alphagov/pyup-update-boto3-1.5.27-to-1.5.28
Update boto3 to 1.5.28
2018-02-14 11:48:35 +00:00
Leo Hemsted
10ebf4ae02 Merge pull request #1659 from alphagov/pyup-update-awscli-1.14.37-to-1.14.38
Update awscli to 1.14.38
2018-02-14 11:48:21 +00:00
Leo Hemsted
4d7a0acaf2 Merge pull request #1662 from alphagov/leohemsted-patch-1
Update requirements.txt
2018-02-14 11:48:10 +00:00
Leo Hemsted
f070b4eab1 Update requirements.txt
email validation
2018-02-14 11:31:17 +00:00
Rebecca Law
94162bc1bf Updated the schema to return reply_to - which is the id and reply_to_text which is the contact_block 2018-02-14 11:20:09 +00:00
Katie Smith
2049e75210 Merge pull request #1656 from alphagov/let-service-change-punctuation-in-name
Allow services to add punctuation to or change the case of their name
2018-02-14 10:22:41 +00:00
Katie Smith
e1cc8175d7 Allow services to add puntuation to or change the case of their name
Changed the '/service/unique' endpoint to optionally accept the
service_id parameter. It now doesn't matter if a user tries to change
the capitalization or add punctuation to their own service name. But
there should still be an error if a user tries to change the punctuation
or capitalization of another service.

service_id needs to be allowed to be None until notifications-admin is
updated to always pass in the service_id.
2018-02-14 10:11:46 +00:00
pyup-bot
a6cf634ab6 Update awscli from 1.14.37 to 1.14.38 2018-02-13 23:25:22 +00:00
pyup-bot
ea13919190 Update boto3 from 1.5.27 to 1.5.28 2018-02-13 23:25:18 +00:00
Rebecca Law
e736c90d00 Switch to using the pdf letter flow.
When sending letters always use the pdf letter flow regardless of service permissions.
2018-02-13 18:38:32 +00:00
Rebecca Law
c833a76070 The admin app is looking for reply_to_text not reply_to. This will fix the admin app and not affect the public api calls for template versions, they don't use the marshmallow schema 2018-02-13 17:12:00 +00:00
kentsanggds
16c78a8924 Merge pull request #1649 from alphagov/ken-link-service-org
Link service to organisation
2018-02-13 16:46:49 +00:00
Alexey Bezhan
2dfbd93c7e Switch service callback workers to use eventlet pool implementation
Service callbacks are I/O bound and can take a long time if the
callback URL takes a long time to respond. This is a perfect use
case for an eventlet worker pool since it allows spawning multiple
green threads (1000 in the proposed configuration) to execute HTTP
requests concurrently without a significant increase in CPU load
or memory usage needed for adding additional worker processes.
2018-02-13 16:44:30 +00:00
Alexey Bezhan
9eada23392 Release DB connection before executing service API callback
Flask-SQLAlchemy sets up a connection pool with 5 connections and will
create up to 10 additional connections if all the pool ones are in use.

If all connections in the pool and all overflow connections are in
use, SQLAlchemy will block new DB sessions until a connection becomes
available. If a session can't acquire a connections for a specified
time (we set it to 30s) then a TimeoutError is raised.

By default db.session is deleted with the related context object
(so when the request is finished or app context is discarded).

This effectively limits the number of concurrent requests/tasks with
multithreaded gunicorn/celery workers to the maximum DB connection pool
size. Most of the time these limits are fine since the API requests are
relatively quick and are mainly interacting with the database anyway.

Service callbacks however have to make an HTTP request to a third party.
If these requests start taking a long time and the number of threads is
larger than the number of DB connections then remaining threads will
start blocking and potentially failing if it takes more than 30s to
acquire a connection. For example if a 100 threads start running tasks
that take 20s each with a max DB connection pool size of 10 then first 10
threads will acquire a connection right away, next 10 tasks will block for
20 seconds before the initial connections are released and all other tasks
will raise a TimeoutError after 30 seconds.

To avoid this, we perform all database operations at the beginning of
the task and then explicitly close the DB session before sending the
HTTP request to the service callback URL. Closing the session ends
the transaction and frees up the connection, making it available for
other tasks. Making calls to the DB after calling `close` will acquire
a new connection. This means that tasks are still limited to running
at most 15 queries at the same time, but can have a lot more concurrent
HTTP requests in progress.
2018-02-13 16:44:30 +00:00
Alexey Bezhan
599e611278 Create an app context for each celery task run
Celery tasks require an active app context in order to use app logger,
database or app configuration values. Since there's no builtin support
we create this context by using a custom celery task class NotifyTask.

However, NotifyTask was using `current_app`, which itself is only
available within an app context so the code was pushing an initial
context in run_celery.py.

This works with the default prefork pool implementation, but raises
a "working outside of application context" error with an eventlet
pool since that initial  application context is local to a thread
and eventlet celery worker pool will create multiple green threads.

To avoid this, we bind NotifyTask to the app variable with a closure
and use that variable instead of `current_app` to create the context
for executing the task. This avoids any issues caused by shared
initial app context being lost when spawning additional worker threads.

We still need to keep the context push in run_celery.py for prefork
workers since it's required for logging events outside of tasks
(eg logging during `worker_process_shutdown` signal processing).
2018-02-13 16:44:30 +00:00
Ken Tsang
f09bcf5ed9 Refactored organisation dao test 2018-02-13 16:38:35 +00:00
Ken Tsang
4576bdd64f Reraise integrity errors on org name unique contraints as 400
- currently being raised as 500s, but should really be 400s as the request data has the duplicate name
2018-02-13 14:47:03 +00:00
Ken Tsang
d80c7d4f65 Return services serialized for dashboard for orgs
- rather than returning the entire service, return only whats needed when listing the service on the org dashboard
2018-02-13 14:06:43 +00:00
Ken Tsang
085110417f Refactor organisation_dao 2018-02-13 14:06:43 +00:00
Ken Tsang
44f9143d08 Organisation services API endpoints 2018-02-13 14:06:43 +00:00
Ken Tsang
60f96ab598 Organisation service DAO 2018-02-13 14:06:43 +00:00
Ken Tsang
6e0e3e9f08 Migration script to add organisation_to_service association table 2018-02-13 14:06:43 +00:00
Ken Tsang
a035dcf7b0 Add organisation_to_service association table
- moved Organisation so that Service model has access to it
2018-02-13 14:06:43 +00:00
Richard Chapman
362dcb9636 Merge pull request #1654 from alphagov/pyup-update-awscli-1.14.32-to-1.14.37
Update awscli to 1.14.37
2018-02-13 12:19:27 +00:00
Richard Chapman
0aa2a36f6b Merge pull request #1653 from alphagov/pyup-update-boto3-1.5.22-to-1.5.27
Update boto3 to 1.5.27
2018-02-13 12:19:11 +00:00
Richard Chapman
ca38c47ac0 Merge pull request #1652 from alphagov/rc_fixed_failing_test
Added a freezetime to the test test_create_letters_pdf_calls_s3upload
2018-02-13 12:18:59 +00:00
Richard Chapman
ad8928370c Merge pull request #1638 from alphagov/pyup-update-psycopg2-2.7.3.2-to-2.7.4
Update psycopg2 to 2.7.4
2018-02-13 12:18:39 +00:00
pyup-bot
a56849aee5 Update awscli from 1.14.32 to 1.14.37 2018-02-13 01:10:33 +00:00
pyup-bot
da12acab36 Update boto3 from 1.5.22 to 1.5.27 2018-02-13 01:10:24 +00:00
Richard Chapman
da669e46f0 Import of time was not needed - removed 2018-02-12 17:08:10 +00:00
Richard Chapman
d2f4f544c1 Added a freezetime to the test test_create_letters_pdf_calls_s3upload
as it failed on prodction and I managed to get it to fail locally

{'file_location': '2018-02-12/NOTIFY.FOO.D.2.C.N.20180212164427.PDF'}
!= {'file_location': '2018-02-12/NOTIFY.FOO.D.2.C.N.20180212164428.PDF'}

A freeze time till ensure that the finame which is based on the time
will not fail.
2018-02-12 16:55:15 +00:00
Leo Hemsted
376ebc5025 Merge pull request #1650 from alphagov/fix
fix bug where we s3upload crashed if you didn't supply tags
2018-02-12 16:12:05 +00:00