2016-01-28 11:51:52 +00:00
[](https://requires.io/github/alphagov/notifications-api/requirements/?branch=master)
2017-02-24 16:56:01 +00:00
[](https://coveralls.io/github/alphagov/notifications-api?branch=master)
2015-11-18 17:03:35 +00:00
2015-11-20 10:51:08 +00:00
# notifications-api
2015-11-18 13:58:21 +00:00
Notifications api
2015-11-20 10:51:08 +00:00
Application for the notification api.
Read and write notifications/status queue.
Get and update notification status.
2016-10-04 15:09:58 +01:00
## Setting Up
### AWS credentials
2016-10-04 11:12:55 +01:00
2016-10-04 12:05:46 +01:00
To run the API you will need appropriate AWS credentials. You should receive these from whoever administrates your AWS account. Make sure you've got both an access key id and a secret access key.
2016-10-04 11:12:55 +01:00
2016-10-04 15:09:58 +01:00
Your aws credentials should be stored in a folder located at `~/.aws` . Follow [Amazon's instructions ](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files ) for storing them correctly.
### Virtualenv
2016-02-17 09:49:36 +00:00
```
2016-01-25 13:20:20 +00:00
mkvirtualenv -p /usr/local/bin/python3 notifications-api
2016-02-17 09:49:36 +00:00
```
2016-02-16 15:25:46 +00:00
2016-10-04 15:09:58 +01:00
### `environment.sh`
2016-08-24 15:00:09 +01:00
Creating the environment.sh file. Replace [unique-to-environment] with your something unique to the environment. Your AWS credentials should be set up for notify-tools (the development/CI AWS account).
2016-02-16 15:25:46 +00:00
2016-10-04 15:09:58 +01:00
Create a local environment.sh file containing the following:
2016-02-17 10:20:40 +00:00
2016-02-16 15:25:46 +00:00
```
2016-02-17 09:49:36 +00:00
echo "
2016-09-07 09:35:31 +01:00
export SQLALCHEMY_DATABASE_URI='postgresql://localhost/notification_api'
2016-10-04 15:09:58 +01:00
export SECRET_KEY='dev-notify-secret-key'
export DANGEROUS_SALT='dev-notify-salt'
export NOTIFY_ENVIRONMENT='development'
export ADMIN_CLIENT_SECRET='dev-notify-secret-key'
2016-02-29 13:21:12 +00:00
export ADMIN_BASE_URL='http://localhost:6012'
2016-09-07 09:35:31 +01:00
export FROM_NUMBER='development'
2016-10-04 15:09:58 +01:00
export MMG_URL='https://api.mmg.co.uk/json/api.php'
2016-09-07 09:35:31 +01:00
export MMG_API_KEY='MMG_API_KEY'
2016-10-04 15:09:58 +01:00
export LOADTESTING_API_KEY='FIRETEXT_SIMULATION_KEY'
export FIRETEXT_API_KEY='FIRETEXT_ACTUAL_KEY'
export STATSD_PREFIX='YOU_OWN_PREFIX'
export NOTIFICATION_QUEUE_PREFIX='YOUR_OWN_PREFIX'
2016-11-28 09:39:56 +00:00
export REDIS_URL="redis://localhost:6379/0"
2017-11-06 12:34:29 +00:00
export FLASK_APP=application.py
export FLASK_DEBUG=1
export WERKZEUG_DEBUG_PIN=off
2016-02-17 09:49:36 +00:00
"> environment.sh
```
2016-10-04 15:09:58 +01:00
NOTES:
2016-02-17 10:20:40 +00:00
2016-10-04 15:09:58 +01:00
* Replace the placeholder key and prefix values as appropriate
* The SECRET_KEY and DANGEROUS_SALT should match those in the [notifications-admin ](https://github.com/alphagov/notifications-admin ) app.
* The unique prefix for the queue names prevents clashing with others' queues in shared amazon environment and enables filtering by queue name in the SQS interface.
2016-02-23 12:28:10 +00:00
2016-10-04 15:09:58 +01:00
### Postgres
2016-10-04 11:12:55 +01:00
2016-10-04 15:09:58 +01:00
Install [Postgres.app ](http://postgresapp.com/ ). You will need admin on your machine to do this.
2016-02-23 12:28:10 +00:00
2016-12-02 10:09:36 +00:00
### Redis
2016-12-02 10:11:31 +00:00
To switch redis on you'll need to install it locally. On a OSX we've used brew for this. To use redis caching you need to switch it on by changing the config for development:
REDIS_ENABLED = True
2016-12-02 10:09:36 +00:00
2016-02-23 12:28:10 +00:00
## To run the application
2016-11-29 16:39:59 +00:00
First, run `scripts/bootstrap.sh` to install dependencies and create the databases.
2016-02-23 12:28:10 +00:00
You need to run the api application and a local celery instance.
There are two run scripts for running all the necessary parts.
```
scripts/run_app.sh
```
```
scripts/run_celery.sh
```
2016-11-29 16:39:59 +00:00
Optionally you can also run this script to run the scheduled tasks:
2016-03-18 12:58:17 +00:00
```
scripts/run_celery_beat.sh
```
2016-05-11 15:52:49 +01:00
2016-08-24 14:30:46 +01:00
## To test the application
2016-11-16 16:11:23 +00:00
First, ensure that `scripts/bootstrap.sh` has been run, as it creates the test database.
2016-08-24 14:30:46 +01:00
Then simply run
```
make test
```
2017-02-01 09:19:32 +00:00
That will run pycodestyle for code analysis and our unit test suite. If you wish to run our functional tests, instructions can be found in the
2016-10-04 11:18:43 +01:00
[notifications-functional-tests ](https://github.com/alphagov/notifications-functional-tests ) repository.
2016-08-24 14:30:46 +01:00
2017-11-22 16:36:09 +00:00
## To run one off tasks
2016-05-11 15:52:49 +01:00
2017-11-22 16:36:09 +00:00
Tasks are run through the `flask` command - run `flask --help` for more information. There are two sections we need to
care about: `flask db` contains alembic migration commands, and `flask command` contains all of our custom commands. For
example, to purge all dynamically generated functional test data, do the following:
2016-05-11 15:52:49 +01:00
Locally
```
2017-11-22 16:36:09 +00:00
flask command purge_functional_test_data -u <functional tests user name prefix>
2016-05-11 15:52:49 +01:00
```
On the server
```
2017-11-22 16:36:09 +00:00
cf run-task notify-api "flask command purge_functional_test_data -u <functional tests user name prefix>"
2016-05-11 15:52:49 +01:00
```
2017-11-22 16:36:09 +00:00
All commands and command options have a --help command if you need more information.