From 33f02445ef8270af2a70acf9b0aad6bd53d0c8f4 Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Fri, 7 Jul 2023 15:00:12 +0200 Subject: [PATCH] Initial testing fixes (#485) * Test py 37,38,39 (#1) dj 22 wt 211,212,213 * Fixes the template include issue with the lock/unlock menu item * Pin the upper bound of the supported Wagtail version to 2.13 and Django to 2.2 * Add some initial documentation for development setup --- .github/workflows/test.yml | 56 +++++++++++++++++++ .gitignore | 5 +- .python-version | 1 + Makefile | 4 +- README.md | 41 ++++++++++---- longclaw/checkout/utils.py | 2 +- .../productrequests/requests_admin.html | 4 +- .../project_name/settings/base.py | 2 +- longclaw/tests/settings.py | 2 +- requirements.txt | 2 - requirements_dev.txt | 13 ----- setup.py | 29 ++++++++-- tox.ini | 39 ++++++++++--- 13 files changed, 155 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .python-version delete mode 100644 requirements.txt delete mode 100644 requirements_dev.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5fd1d1b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,56 @@ +name: Tests + +on: + push: + branches: + - main + + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +jobs: + + test-python: + runs-on: ubuntu-latest + strategy: + matrix: + python: ["3.7", "3.8", "3.9"] + + steps: + - uses: actions/checkout@v2 + - name: Install NPM and dependencies + uses: actions/setup-node@v2 + with: + node-version: '12.x' + - name: Build client + run: | + npm install --prefix ./longclaw/client + npm run build --prefix ./longclaw/client + - name: Upload client + uses: actions/upload-artifact@v2 + with: + name: client + path: ./longclaw/core/static/core/js + + - uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Download client + uses: actions/download-artifact@v2 + with: + name: client + path: ./longclaw/core/static/core/js + - name: Test with tox + run: tox diff --git a/.gitignore b/.gitignore index 558440e..fa20966 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,7 @@ docs/_build webpack-stats.json *bundle.js* -.eggs/ \ No newline at end of file +.eggs/ + +# local virtual environment +/venv diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..475ba51 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.7 diff --git a/Makefile b/Makefile index 18933ea..a4bd367 100644 --- a/Makefile +++ b/Makefile @@ -31,13 +31,13 @@ lint: ## check style with flake8 flake8 longclaw tests test: ## run tests quickly with the default Python - python runtests.py tests + python runtests.py test-all: ## run tests on every Python version with tox tox coverage: ## check code coverage quickly with the default Python - coverage run --source longclaw runtests.py tests + coverage run --source longclaw runtests.py coverage report -m coverage html open htmlcov/index.html diff --git a/README.md b/README.md index 958cead..9f2437c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Longclaw - ## Call For Maintainers + If you are interested in developing this project, please get in touch https://github.com/JamesRamm/longclaw/issues/375 @@ -12,8 +12,6 @@ https://github.com/JamesRamm/longclaw/issues/375 An e-commerce extension for [Wagtail CMS](https://github.com/wagtail/wagtail) - - Checkout the [documentation](https://longclawshop.github.io/longclaw/) ![Image of the dashboard](docs/assets/dashboard.png) @@ -23,28 +21,28 @@ Checkout the [documentation](https://longclawshop.github.io/longclaw/) Install Longclaw: ```bash - $ pip install longclaw +pip install longclaw ``` Setup a Longclaw project ```bash - $ longclaw start my_project +longclaw start my_project ``` Go to project directory and create missing migrations ```bash - $ python manage.py makemigrations home catalog +python manage.py makemigrations home catalog ``` Do migrations for whole project and run ```bash - $ python manage.py migrate - $ python manage.py loadcountries - $ python manage.py createsuperuser - $ python manage.py runserver +python manage.py migrate +python manage.py loadcountries +python manage.py createsuperuser +python manage.py runserver ``` ## Features @@ -61,5 +59,28 @@ Do migrations for whole project and run ![Order Detail](docs/assets/order_detail.png) +## Development setup +Work in progress! +This is a brief guide to setting up a development environment for Longclaw. + +Create a virtualenv and install the requirements + +```bash +python3 -m venv venv +source venv/bin/activate +pip install -e ".[testing]" +``` + +Run the tests + +```bash +make test +``` + +Run the tests with TOX + +```bash +make test-all +``` diff --git a/longclaw/checkout/utils.py b/longclaw/checkout/utils.py index b5949fd..061b249 100644 --- a/longclaw/checkout/utils.py +++ b/longclaw/checkout/utils.py @@ -1,7 +1,7 @@ from decimal import Decimal from django.utils.module_loading import import_string from django.utils import timezone -from ipware.ip import get_client_ip +from ipware import get_client_ip from longclaw.basket.utils import get_basket_items, destroy_basket from longclaw.shipping.utils import get_shipping_cost diff --git a/longclaw/contrib/productrequests/templates/productrequests/requests_admin.html b/longclaw/contrib/productrequests/templates/productrequests/requests_admin.html index 5aed8a3..de12fce 100644 --- a/longclaw/contrib/productrequests/templates/productrequests/requests_admin.html +++ b/longclaw/contrib/productrequests/templates/productrequests/requests_admin.html @@ -21,7 +21,7 @@ {% include "wagtailadmin/shared/page_status_tag.html" with page=page %} {% include "wagtailadmin/pages/_privacy_switch.html" with page=page page_perms=page_perms only %} - {% include "wagtailadmin/pages/_lock_switch.html" %} + {% include "wagtailadmin/pages/action_menu/lock_unlock_menu_item.html" %} @@ -47,4 +47,4 @@ {% block extra_css %} {{ block.super }} {% include "wagtailadmin/pages/_editor_css.html" %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/longclaw/project_template/project_name/settings/base.py b/longclaw/project_template/project_name/settings/base.py index b7c8502..0002f03 100644 --- a/longclaw/project_template/project_name/settings/base.py +++ b/longclaw/project_template/project_name/settings/base.py @@ -64,7 +64,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', - 'wagtail.core.middleware.SiteMiddleware', + 'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware', 'wagtail.contrib.redirects.middleware.RedirectMiddleware', ] diff --git a/longclaw/tests/settings.py b/longclaw/tests/settings.py index 35ec3d0..490e742 100644 --- a/longclaw/tests/settings.py +++ b/longclaw/tests/settings.py @@ -66,7 +66,7 @@ MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - 'wagtail.core.middleware.SiteMiddleware', + 'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware', 'wagtail.contrib.redirects.middleware.RedirectMiddleware', ] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index be206ed..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ ---index-url https://pypi.python.org/simple/ --e . \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index efa22fa..0000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,13 +0,0 @@ --r requirements.txt -bumpversion==0.6.0 -wheel==0.38.1 -setuptools==65.5.1 -coverage>=4.5.2 -mock>=2.0.0 -flake8>=3.6.0 -tox>=3.5.3 -codecov>=2.0.15 - -# Additional test requirements go here -factory_boy>=2.11.1 -wagtail-factories>=1.1.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 48b4f38..576d6a2 100644 --- a/setup.py +++ b/setup.py @@ -87,14 +87,30 @@ setup( ], include_package_data=True, install_requires=[ - 'django==2.2.28', - 'wagtail==2.11.8', + 'django>=2.2,<3.0', + 'wagtail>=2.11,<2.14', 'django-countries==5.5', 'django-extensions==2.2.1', 'djangorestframework==3.11.2', 'django-ipware==2.1.0', 'django-polymorphic==2.0.3', ], + extras_require={ + "testing": [ + "bumpversion==0.6.0", + "wheel==0.38.1", + "setuptools==65.5.1", + "coverage>=4.5.2", + "mock==2.0.0", + "flake8>=3.6.0", + "tox>=3.5.3", + "codecov>=2.0.15", + + "# Additional test requirements go here", + "factory_boy>=2.11.1", + "wagtail-factories>=1.1.0", + ], + }, license="MIT", zip_safe=False, keywords='longclaw', @@ -102,13 +118,16 @@ setup( 'Development Status :: 3 - Alpha', 'Framework :: Django', 'Framework :: Django :: 2.0', + 'Framework :: Wagtail', + 'Framework :: Wagtail :: 2', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.7' + 'Programming Language :: Python :: 3.8' + 'Programming Language :: Python :: 3.9' + 'Programming Language :: Python :: 3.10' ], entry_points=""" [console_scripts] diff --git a/tox.ini b/tox.ini index 623a973..4928509 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,40 @@ [tox] +skipsdist = True +usedevelop = True +skip_missing_interpreters = True + envlist = - {py35,py36,py37}-django-225 + py{37,38,39}-dj{22}-wt{211,212,213} + +[gh-actions] +python = + 3.7: py37 + 3.8: py38 + 3.9: py39 + [testenv] setenv = PYTHONPATH = {toxinidir}:{toxinidir}/longclaw -commands = coverage run --source longclaw runtests.py - coverage xml --omit=*/apps.py,*/migrations/*,*/__init__.py,*/gateways/braintree.py,*/gateways/stripe.py,*/bin/longclaw.py + deps = - django-225: Django==2.2.5 - -r{toxinidir}/requirements_dev.txt + coverage + django-extensions + django-polymorphic + django-ipware + mock + wagtail-factories + + dj22: Django>=2.2,<3.0 + dj30: Django>=3.0,<3.1 + wt211: wagtail>=2.11,<2.12 + wt212: wagtail>=2.12,<2.13 + wt213: wagtail>=2.13,<2.14 + +install_command = pip install -U {opts} {packages} + +commands = + coverage run --source longclaw runtests.py + coverage xml --omit=*/apps.py,*/migrations/*,*/__init__.py,*/gateways/braintree.py,*/gateways/stripe.py,*/bin/longclaw.py + basepython = py37: python3.7 - py36: python3.6 - py35: python3.5