diff --git a/Makefile b/Makefile index abede5eb..2e0d08d5 100644 --- a/Makefile +++ b/Makefile @@ -20,12 +20,12 @@ all: build test lint .PHONY: dev dev: export APPUID = $(APP_UID) dev: setup_mounts - @docker-compose build && docker-compose up -d web celery + @docker-compose up --build -d web celery ## make build : Build and start docker containers - (web and db) .PHONY: build build: - @docker-compose up --build web -d + @docker-compose up --build -d web .PHONY: down down: export APPUID = $(APP_UID) @@ -37,20 +37,26 @@ down: logs: @docker-compose logs -ft -## Run tests with coverage -.PHONY: test -test: export APPUID = $(APP_UID) -test: setup_mounts +ensure_web_container_for_test: @if [ $$(docker ps -a -f name=dev | wc -l) -eq 2 ]; then \ docker exec dev python -m pytest --version; \ else \ echo "No containers running.. Starting Django runserver:"; \ make build; \ - echo "Running Tests"; \ fi - @docker exec dev python -m pytest -v --cov --disable-warnings;\ - echo "Tests finished." +## Run tests with coverage +.PHONY: test +test: export APPUID = $(APP_UID) +test: setup_mounts ensure_web_container_for_test + @if [ "$(TESTS)" = "" ]; then \ + echo "No arguments passed to make test. Running all tests.."; \ + docker exec dev python -m pytest -v --cov --disable-warnings; \ + echo "Tests finished."; \ + else \ + echo "Running tests with filter $(TESTS)"; \ + docker exec dev python -m pytest -v --cov --disable-warnings -k '$(TESTS)'; \ + fi ## Create lint issues file .PHONY: lint_issues diff --git a/config.json.sample b/config.json.sample index 87ffae83..87d10d9c 100644 --- a/config.json.sample +++ b/config.json.sample @@ -6,7 +6,7 @@ "localhost" ], "CSRF_TRUSTED_ORIGINS": [ - "" + "http://localhost" ] }, "sso": { @@ -21,7 +21,7 @@ "username": "", "password": "", "host": "", - "port": + "port": 3306 }, "access_modules": { "git_urls": [ diff --git "a/docs/\342\200\234How-to\342\200\235 guides/Running Tests.md" "b/docs/\342\200\234How-to\342\200\235 guides/Running Tests.md" new file mode 100644 index 00000000..4d168c80 --- /dev/null +++ "b/docs/\342\200\234How-to\342\200\235 guides/Running Tests.md" @@ -0,0 +1,34 @@ +# Running Unit Tests + +To run all tests in the code-base, run the following on the root directory for `enigma-public-central` + +```bash +make test +``` + +This will also clone the access modules repo added in config.json and run tests within them. + +## How it works + +It first ensures that the `web` container running the enigma webserver is up and running. +Then the `make` script will run the `pytest` command as a subshell in the running container. + +In case the `web` container is not up, it will first start it. + +## Running specific tests + +To run specific subset of `pytest` tests, you can add a pass a test filter to the make command, which forwards the filter to `pytest` cli. + +Example, + +```bash +make test TESTS="test_aws_access" +``` + +OR + +```bash +make test TESTS="test_aws_access or test_grant_gcp_access" +``` + +Please check this [link](https://docs.pytest.org/en/7.3.x/example/markers.html#using-k-expr-to-select-tests-based-on-their-name) to understand what expressions are supported