To run backend tests locally:
-
Start the application cluster with
docker compose up
-
Start the test database with
docker compose --profile test up
. Yes, you should start the test database separately. It'll be more likely to boot properly this way. -
Add a test marker to the test DB. This will allow the DB to clear itself after each test run. See instructionsbelow.
-
Connect to the API container with
docker exec -it "police-data-trust-api-1" /bin/bash
. You can find the container name by runningdocker ps
. -
Run the tests with
python -m pytest
. -
If you want to run a specific test file, you can do so with
python -m pytest <path_to_test_file>
. You can also run a specific test withpython -m pytest <path_to_test_file>::<test_function_name>
.
-
With the test database running, navigate to
localhost:7474
in your browser. -
On the Neo4J web interface, select
neo4j://127.0.0.1:7688
as the connection URL. Otherwise, you will connect to the main database. You can connect to a new DB by typing the following into the command bar at the very top of your browser window::server connect neo4j://127.0.0.1:7688
and pressing Enter or clicking the run button. The command bar often starts withneo4j$
at the beginning. -
Run the following query to add a test marker to the database:
MERGE (n:TestMarker {name: 'TEST_DATABASE'});
This command can also be run from the command bar at the top of your screen.
- You can now run the tests. The database will clear itself after each test run.
-
Start the application cluster with
docker compose up
-
Connect to the API container with
docker exec -it "police-data-trust-api-1" /bin/bash
. You can find the container name by runningdocker ps
. -
Run the linter with
flake8 backend/
.