From 3ff7cbde55ac01034eda6963c8c8d5e37d5ea445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 12 Nov 2024 09:50:11 +0100 Subject: [PATCH] chore: more convenient unit test running 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. --- Makefile | 8 ++++++++ README.rst | 17 +++++++++++++++-- notesserver/docker-compose.test.yml | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 notesserver/docker-compose.test.yml diff --git a/Makefile b/Makefile index 0c689738..2082bb82 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.rst b/README.rst index fbaaec7e..321452c0 100644 --- a/README.rst +++ b/README.rst @@ -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 *********************** diff --git a/notesserver/docker-compose.test.yml b/notesserver/docker-compose.test.yml new file mode 100644 index 00000000..0dc73b6c --- /dev/null +++ b/notesserver/docker-compose.test.yml @@ -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