From 45b3c00836a5a8ef4b1ee5d41fbbbcd4019f52e3 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:29:26 -0300 Subject: [PATCH 1/8] Create 'pytest.ini' file --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..04cdc40 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +DJANGO_SETTINGS_MODULE = project.settings + +python_files = test.py test_*.py *_tests.py \ No newline at end of file From 9a1ae27150619c1146318329e96e6abee25156ab Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:29:55 -0300 Subject: [PATCH 2/8] Create 'tests/' folder with a 'test_sample' test --- tests/__init__.py | 0 tests/test_sample.py | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_sample.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_sample.py b/tests/test_sample.py new file mode 100644 index 0000000..a6f1c78 --- /dev/null +++ b/tests/test_sample.py @@ -0,0 +1,2 @@ +def test_sample(): + assert True \ No newline at end of file From ae287af502dfcfa9a2a337ed4b8297410f377225 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:41:06 -0300 Subject: [PATCH 3/8] Update 'pytest.ini' to support pytest-cov. Create '.coveragerc' file --- .coveragerc | 6 ++++++ pytest.ini | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..5be15ba --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[report] +show_missing = True +omit = + manage.py + venv/* + *wsgi.py \ No newline at end of file diff --git a/pytest.ini b/pytest.ini index 04cdc40..8a86196 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,6 @@ [pytest] DJANGO_SETTINGS_MODULE = project.settings -python_files = test.py test_*.py *_tests.py \ No newline at end of file +python_files = test.py test_*.py *_tests.py + +addopts = --cov-report html --cov . \ No newline at end of file From dbe81322f72f50e624897e7306077a1dd810cb40 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:41:46 -0300 Subject: [PATCH 4/8] Create script to test and produce coverage reports in 'Makefile' --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 0ca9547..b0bb488 100644 --- a/Makefile +++ b/Makefile @@ -20,3 +20,9 @@ install_dependencies: setup_node_environment: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash export NVM_DIR=$$HOME/.nvm; . ~/.nvm/nvm.sh ; nvm install + +test: + pytest + +cov: + pytest && python -m webbrowser -t htmlcov/index.html \ No newline at end of file From 62300b6400c6413c0163ff342f81e7ee804b5189 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:42:17 -0300 Subject: [PATCH 5/8] Update 'requirements.txt' with pytest, pytest-django and pytest-cov libs --- requirements.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/requirements.txt b/requirements.txt index 077bc50..33d33f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ asgiref==3.2.5 attrs==19.3.0 black==19.10b0 click==7.1.1 +coverage==5.5 dj-database-url==0.5.0 Django==3.0.4 django-heroku==0.3.1 @@ -12,11 +13,19 @@ djangorestframework==3.11.0 entrypoints==0.3 flake8==3.7.9 gunicorn==20.0.4 +iniconfig==1.1.1 mccabe==0.6.1 +packaging==20.9 pathspec==0.7.0 +pluggy==0.13.1 psycopg2==2.8.4 +py==1.10.0 pycodestyle==2.5.0 pyflakes==2.1.1 +pyparsing==2.4.7 +pytest==6.2.4 +pytest-cov==2.12.1 +pytest-django==4.4.0 python-decouple==3.3 pytz==2019.3 regex==2020.2.20 From 0cbbe14e245c6322e597b5daf03dba6658c568f6 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:44:13 -0300 Subject: [PATCH 6/8] Install pytest-sugar lib --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 33d33f5..cc493ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,10 +26,12 @@ pyparsing==2.4.7 pytest==6.2.4 pytest-cov==2.12.1 pytest-django==4.4.0 +pytest-sugar==0.9.4 python-decouple==3.3 pytz==2019.3 regex==2020.2.20 sqlparse==0.3.1 +termcolor==1.1.0 toml==0.10.0 typed-ast==1.4.1 whitenoise==5.0.1 From 4c357478af8d300fd591e65130ff0d0401b27259 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:50:54 -0300 Subject: [PATCH 7/8] Update 'README.md' with testing instructions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 25336c8..e6687f7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,12 @@ make run Since nvm can be a little fiddly, if you have any issues with it, [try reading their documentation](https://github.com/nvm-sh/nvm#installing-and-updating) on how to use it. +## Testing it + +Run the command `pytest` in the main directory, or run the script `make test`. + +For coverage report, run the script `make cov`. Your default browser will open with the report for the tests, if all tests pass. + ## Adding new dependencies If you wish to add new dependencies, just note that: From 27b3738613999d5c646225556e3f64e7ec4a5b67 Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante Date: Fri, 11 Jun 2021 16:51:42 -0300 Subject: [PATCH 8/8] Provide documentation to 'Makefile' --- Makefile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index b0bb488..327c2e1 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,34 @@ +.DEFAULT_GOAL := help + +help: ## show help message + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + + .PHONY: build_frontend run_frontend run_django run install_dependencies setup_node_environment -build_frontend: +build_frontend: ## build frontend application npm run build -run_frontend: +run_frontend: ## run frontend application npm start -run_django: +run_django: ## run backend application python manage.py runserver -run: +run: ## run both backend and frontend applications make -j2 run_django run_frontend -install_dependencies: +install_dependencies: ## install both backend and frontend dependencies make setup_node_environment pip install -r requirements.txt npm i -setup_node_environment: +setup_node_environment: ## setup node environment curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash export NVM_DIR=$$HOME/.nvm; . ~/.nvm/nvm.sh ; nvm install -test: +test: ## run the tests pytest -cov: +cov: ## run the tests, and open coverage report in your favorite browser pytest && python -m webbrowser -t htmlcov/index.html \ No newline at end of file