Contains:
- the public-facing REST API for Notification built on the GOV.UK Notify platform, which teams can integrate with using their clients
- an internal-only REST API built using Flask to manage services, users, templates, etc (this is what the admin app talks to)
- asynchronous workers built using Celery to put things on queues and read them off to be processed, sent to providers, updated, etc
- We currently do not support sending of letters
- We currently do not receive a response if text messages were delivered or not
For any issues during the following instructions, make sure to review the Frequent problems section toward the end of the document.
On OS X:
- Install PyEnv with Homebrew. This will preserve your sanity.
brew install pyenv
- Install Python 3.9.1 or whatever is the latest
pyenv install 3.9.1
- If you expect no conflicts, set
3.9.1
as you default
pyenv global 3.9.1
- Ensure it installed by running
python --version
if it did not, take a look here: pyenv/pyenv#660
- Install
virtualenv
:
pip install virtualenvwrapper
- Add the following to your shell rc file. ex:
.bashrc
or.zshrc
source ~/.pyenv/versions/3.9.1/bin/virtualenvwrapper.sh
- Restart your terminal and make your virtual environtment:
mkvirtualenv -p ~/.pyenv/versions/3.9.1/bin/python notifications-api
- You can now return to your environment any time by entering
workon notifications-api
-
Install Postgres.app.
-
Create the database for the application
createdb --user=postgres notification_api
- Install the required environment variables via our LastPast Vault
Within the team's LastPass Vault, you should find corresponding folders for this
project containing the .env
content that you should copy in your root folder. This
will grant the application necessary access to our internal infrastructure.
If you don't have access to our LastPass Vault (as you evaluate our notification
platform for example), you will find a sane set of defaults exists in the .env.example
file. Copy that file to .env
and customize it to your needs.
- Install all dependencies
pip3 install -r requirements.txt
- Generate the version file ?!?
make generate-version-file
- Run all DB migrations
flask db upgrade
- Run the service
flask run -p 6011 --host=0.0.0.0
15a. To test
pip3 install -r requirements_for_test.txt
make test
scripts/run_celery.sh
scripts/run_celery_sms.sh
scripts/run_celery_beat.sh
This codebase is Python 3 only. At the moment we run 3.9.1 in production. You will run into problems if you try to use Python 3.4 or older.
requirements.txt
file is generated from the requirements-app.txt
in order to pin
versions of all nested dependencies. If requirements-app.txt
has been changed (or
we want to update the unpinned nested dependencies) requirements.txt
should be
regenerated with
make freeze-requirements
requirements.txt
should be committed alongside requirements-app.txt
changes.
Jinja templates used in this repo: email_template.jinja2
Jinja templates are pulled in from the notification-utils repo. To test jinja changes locally (without needing to update the upstream), follow this procedure:
-
Create a
jinja_templates
folder in the project root directory. This folder name is already gitignored and won't be tracked. -
Copy the jinja template files from notification-utils into the
jinja_templates
folder created in step 1 -
Set a new .ENV variable:
USE_LOCAL_JINJA_TEMPLATES=True
-
Make markup changes, and see them locally!
-
When finished, copy any changed jinja files back to notification-utils, and push up the PR for your changes in that repo.
-
Remove
USE_LOCAL_JINJA_TEMPLATES=True
from your .env file, and delete any jinja injinja_templates
. Deleting the folder and jinja files is not required, but recommended. Make sure you're pulling up-to-date jinja from notification-utils the next time you need to make changes.
Problem: No postgres role exists.
Solution: If the command complains you don't have a postgres role existing, execute the following command and retry the above afterward:
createuser -l -s postgres
Problem : E999 SyntaxError: invalid syntax
when running flake8
Solution : Check that you are in your correct virtualenv, with python 3.9
Problem:
/bin/sh: 1: Syntax error: "(" unexpected
make: *** [Makefile:31: freeze-requirements] Error 2
when running make freeze-requirements
Solution: Change /bin/sh
to /bin/bash
in the Makefile
Problem: ImportError: failed to find libmagic. Check your installation
Solution:Install libmagic
, ex: brew install libmagic
Problem: assert 'test_notification_api' in db.engine.url.database, 'dont run tests against main db
Solution: Do not specify a database in your .env
Problem: Messages are in the queue but not sending
Solution: Check that celery
is running.