From 4f50c63f7b98aa8e7de9ce8e751d7a9f2a95d63d Mon Sep 17 00:00:00 2001 From: Thu Trang Pham Date: Wed, 3 Mar 2021 07:42:24 -0800 Subject: [PATCH] WIP: 2021 02 24 dockerize (#18) * Use cache for most fields and admin form for m2m files * MR comments/clean up * Cache should obey exclude and fields * Some more tests and docs * Only use cache for image files * Even more tests and handle save as new * fix test * More tests * minor refactor * Improve test coverage * Adding tests for fieldsets * Added cache timeout * Added another test for an edge case * Fix issue with ManagementForm tampered with * Update cache to only set when form is_multipart * Even more testing changes * Dockerize * Setting up tests in docker * Update github actions * Got first integration test to work * Refactor a bit * Fix github action yml * Use docker-compose up -d in github actions * combine coveralls * Updated readme * Clean up code * Remove dup code from rebase Co-authored-by: Thu Trang Pham --- .dockerignore | 36 ++++++++++ .github/workflows/test.yml | 18 ++++- .python-version | 2 +- Dockerfile | 7 ++ Makefile | 7 ++ README.md | 68 +++++++++++++++---- .../templates/admin/change_confirmation.html | 2 +- admin_confirm/tests/helpers.py | 31 ++++++++- admin_confirm/tests/integration/test_smoke.py | 7 ++ .../tests/unit/test_admin_options.py | 2 +- docker-compose.yml | 18 +++++ tests/market/admin/item_admin.py | 9 --- tests/test_project/settings/base.py | 7 +- 13 files changed, 183 insertions(+), 31 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 admin_confirm/tests/integration/test_smoke.py create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eae9e96 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,36 @@ +__pycache__/ +*.py[cod] + +build/ +dist/ +sdist/ +.eggs/ +*.egg-info/ +.DS_Store + +# Editor settings +.vscode/ + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +*.db + +# Sphinx documentation +docs/_build/ + +# pycharm +.idea/ + +tmp/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a86186..3b1ee26 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,8 +49,24 @@ jobs: parallel: true flag-name: Unit Test + integration-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build Docker + run: docker-compose build + - name: Start Docker + run: docker-compose up -d + - name: Integration Test + run: docker-compose run web make test-all + - name: Coveralls + uses: AndreMiras/coveralls-python-action@develop + with: + parallel: true + flag-name: Integration Test + coveralls: - needs: test + needs: [test, integration-test] runs-on: ubuntu-latest steps: - name: Coveralls Finished diff --git a/.python-version b/.python-version index f29ad5b..61d93e0 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -django-admin-confirm-3.8 +django-admin-confirm-3.8.0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d388347 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3 +ENV PYTHONUNBUFFERED=1 +ENV USE_DOCKER=true +WORKDIR /code +COPY requirements.txt /code/ +RUN pip install -r requirements.txt +COPY . /code/ diff --git a/Makefile b/Makefile index b358d1a..a831224 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,16 @@ run: ./tests/manage.py runserver test: + coverage run --source admin_confirm --branch -m pytest --ignore=admin_confirm/tests/integration + coverage report -m + +test-all: coverage run --source admin_confirm --branch -m pytest coverage report -m +t: + python -m pytest --last-failed -x + check-readme: python -m readme_renderer README.md -o /tmp/README.html diff --git a/README.md b/README.md index d378c5f..7aa1232 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions. -![Screenshot of Change Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/main/screenshot.png) +![Screenshot of Change Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/302e02b1e483fd41e9a6f0b6803b45cd34c866cf/screenshot.png) -![Screenshot of Add Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/main/screenshot_confirm_add.png) +![Screenshot of Add Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/302e02b1e483fd41e9a6f0b6803b45cd34c866cf/screenshot_confirm_add.png) -![Screenshot of Action Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/main/screenshot_confirm_action.png) +![Screenshot of Action Confirmation Page](https://raw.githubusercontent.com/TrangPham/django-admin-confirm/302e02b1e483fd41e9a6f0b6803b45cd34c866cf/screenshot_confirm_action.png) It can be configured to add a confirmation page on ModelAdmin upon: @@ -139,18 +139,21 @@ Your appreciation is also very welcome :) Feel free to: ### Local Development Setup +**Local:** +_You can skip this and just use docker if you want_ + Install pyenv -Install python 3.8 +pyenv install 3.8.0 -Create virtualenv via pyenv +Create **virtualenv** via pyenv ``` -pyenv vituralenv 3.8 django-admin-confirm-3.8 +pyenv vituralenv 3.8.0 django-admin-confirm-3.8.0 ``` -Now your terminal should have `(django-admin-confirm-3.8)` prefix, because `.python-version` should have auto switch your virtual env +Now your terminal should have `(django-admin-confirm-3.8.0)` prefix, because `.python-version` should have auto switch your virtual env -Run migrations and create a superuser and run the server +Run **migrations** and create a superuser and run the server ``` ./tests/manage.py migrate @@ -160,19 +163,54 @@ Run migrations and create a superuser and run the server You should be able to see the test app at `localhost:8000/admin` -Running tests: +**Running tests:** -``` -make test +```sh +make test # Runs unit tests with coverage locally without integration tests +make test-all # Runs unit tests + integration tests, requires extra setup to run locally ``` -Testing new changes on test project: +Use `python -m pytest` if you want to pass in arguments + +`make t` is a short cut to run without coverage, last-failed, and fail fast + +Testing local changes on test project: ``` pip install -e . make run ``` +**Docker:** + +Instead of local set-up, you can also use docker. + +Install docker-compose (or Docker Desktop which installs this for you) + +``` +docker-compose build +docker-compose up -d +``` + +You should now be able to see the app running on `localhost:8000` + +If you haven't already done migrations and created a superuser, you'll want to do it here + +``` +docker-compose exec web tests/manage.py migrate +docker-compose exec web tests/manage.py createsuperuser +``` + +Running tests in docker: + +``` +docker-compose exec -T web make test-all +``` + +The integration tests are set up within docker. I recommend running the integration tests only in docker. + +Docker is also set to mirror local folder so that you can edit code/tests and don't have to rebuild to run new code/tests. + ### Release process Honestly this part is just for my reference. But who knows :) maybe we'll have another maintainer in the future. @@ -180,7 +218,7 @@ Honestly this part is just for my reference. But who knows :) maybe we'll have a Run tests, check coverage, check readme ``` -make test +docker-compose exec -T web make test-all make check-readme ``` @@ -188,7 +226,7 @@ Update version in `setup.py` ``` make package -make upload-testpypi +make upload-testpypi VERSION= ``` Install new version locally @@ -196,7 +234,7 @@ First you have to uninstall if you used `pip install -e` earlier ``` pip uninstall django_admin_confirm -make install-testpypi +make install-testpypi VERSION= ``` Update version in `requirements.txt` diff --git a/admin_confirm/templates/admin/change_confirmation.html b/admin_confirm/templates/admin/change_confirmation.html index da06731..433c75d 100644 --- a/admin_confirm/templates/admin/change_confirmation.html +++ b/admin_confirm/templates/admin/change_confirmation.html @@ -48,7 +48,7 @@ {% if is_popup %}{% endif %} {% if to_field %}{% endif %} - {% if form.is_multipart %}{% endif %} + {% if form.is_multipart %}{% endif %}