From 948b76451250fa83d6490acf02d3cd27bd8f26bb Mon Sep 17 00:00:00 2001 From: Darrell Malone Jr Date: Mon, 14 Oct 2024 18:44:55 -0500 Subject: [PATCH] Update Readme to explain tests --- README.md | 2 ++ backend/tests/README.md | 44 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b78ba60bb..d1416fc41 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ flake8 backend/ python -m pytest ``` +For more information on running the tests, see the [backend tests README](./backend/tests/README.md) + ### Front End Tests The current frontend tests can be found in the GitHub Actions workflow file [frontend-checks.yml](https://github.com/codeforboston/police-data-trust/blob/0488d03c2ecc01ba774cf512b1ed2f476441948b/.github/workflows/frontend-checks.yml) diff --git a/backend/tests/README.md b/backend/tests/README.md index 928fa76f5..a4e8fe4ef 100644 --- a/backend/tests/README.md +++ b/backend/tests/README.md @@ -1,5 +1,43 @@ -To run tests locally: +To run backend tests locally: -```shell -python -m pytest +## Pytest (Unit Tests) + +1. Start the application cluster with `docker-compose up` + +2. 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. + +3. Add a test marker to the test DB. This will allow the DB to clear itself after each test run. See instructions below. + +4. Connect to the API container with `docker exec -it "police-data-trust-api-1" /bin/bash`. You can find the container name by running `docker ps`. + +5. Run the tests with `python -m pytest`. + +6. If you want to run a specific test file, you can do so with `python -m pytest `. You can also run a specific test with `python -m pytest ::`. + + +## Adding a test marker to the test database + +1. With the test database running, navigate to `localhost:7474` in your browser. + +2. On the Neo4J web interface, select `neo4j://127.0.0.1:7688` as the connection URL. Otherwise, you will connect to the main database. + +3. Log in with the username `neo4j` and the password `test_pwd`. + +4. Run the following query to add a test marker to the database: + +``` +MERGE (n:TestMarker {name: 'TEST_DATABASE'}); +``` + +5. You can now run the tests. The database will clear itself after each test run. + + +## Flake8 (Linting) + +1. Start the application cluster with `docker-compose up` + +2. Connect to the API container with `docker exec -it "police-data-trust-api-1" /bin/bash`. You can find the container name by running `docker ps`. + +3. Run the linter with `flake8 backend/`. ```