Skip to content

Commit

Permalink
chore: more convenient unit test running
Browse files Browse the repository at this point in the history
Previously, it was not possible to run unit tests locally without
manually creating mysql & elasticsearch containers. Here, we create a
`make pytest` target that automatically starts the required containers.
  • Loading branch information
regisb committed Nov 12, 2024
1 parent 7a9aa32 commit 3ff7cbd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ PACKAGES = notesserver notesapi

validate: test.requirements test

pytest: test-start-services test test-stop-services

test: clean
python -Wd -m pytest

test-start-services:
docker compose -f notesserver/docker-compose.test.yml --project-name=edxnotesapi_test up -d --remove-orphans

test-stop-services:
docker compose -f notesserver/docker-compose.test.yml --project-name=edxnotesapi_test stop

pii_check: test.requirements pii_clean
DJANGO_SETTINGS_MODULE=notesserver.settings.test code_annotations django_find_annotations --config_file .pii_annotations.yml \
--lint --report --coverage
Expand Down
17 changes: 15 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ Configuration
Running Tests
*************

Run ``make validate`` install the requirements, run the tests, and run
lint.
Install requirements::

make test.requirements

Start mysql/elasticsearch services::

make test-start-services

Run unit tests::

make test

Run quality checks::

make quality

How To Resync The Index
***********************
Expand Down
18 changes: 18 additions & 0 deletions notesserver/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "edx_notes_api"
ports:
- 127.0.0.1:3306:3306

elasticsearch:
image: elasticsearch:7.13.4
environment:
discovery.type: single-node
bootstrap.memory_lock: "true"
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
ports:
- 127.0.0.1:9200:9200

0 comments on commit 3ff7cbd

Please sign in to comment.