Skip to content

Commit

Permalink
test: Run tests against django main branch (#7650)
Browse files Browse the repository at this point in the history
* ci: Add testing against django main branch

* ci: Add dependabot github action updates

* ci: Test all dbs on django main

* Update postgres

Co-authored-by: Fabian Braun <fsbraun@gmx.de>

* Output django version

Co-authored-by: Fabian Braun <fsbraun@gmx.de>

* Output django version

Co-authored-by: Fabian Braun <fsbraun@gmx.de>

* ci: install requirements before django

* Remove duplicate

Co-authored-by: Fabian Braun <fsbraun@gmx.de>

* Replace get_storage_class with import_string

* Fix ruff

* remove unused code from util. __init__.py

* Fix incomplete property overwrite

* Fix: Lazy choice field implementation was wrong. Added test coverage

* Fix: Add `on-error-continue: true` to django-main-postgres and django-main-mysql github actions

---------

Co-authored-by: Fabian Braun <fsbraun@gmx.de>
  • Loading branch information
marksweb and fsbraun committed Sep 22, 2023
1 parent 534660a commit f572e38
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
141 changes: 138 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:


steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
python-version: 3.9

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
Expand All @@ -167,3 +167,138 @@ jobs:
run: python manage.py test
env:
DATABASE_URL: sqlite://localhost/testdb.sqlite

django-main-sqlite:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
requirements-file: ['requirements_base.txt']
django-version: [
'https://github.com/django/django/archive/main.tar.gz'
]
os: [
ubuntu-20.04,
]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt install gettext gcc -y
python -m pip install --upgrade pip
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
python setup.py install
- name: Test with django test runner
run: python manage.py test
continue-on-error: true
env:
DATABASE_URL: sqlite://localhost/testdb.sqlite

django-main-postgres:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
requirements-file: ['requirements_base.txt']
django-version: [
'https://github.com/django/django/archive/main.tar.gz'
]
os: [
ubuntu-20.04,
]

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
sudo apt install gettext gcc -y
python -m pip install --upgrade pip
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
pip install -r test_requirements/databases.txt
python setup.py install
- name: Test with django test runner
run: |
python -c "from django import __version__ ; print(f'Django version {__version__}')"
python manage.py test
continue-on-error: true
env:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1/postgres

django-main-mysql:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
requirements-file: ['requirements_base.txt']
django-version: [
'https://github.com/django/django/archive/main.tar.gz'
]
os: [
ubuntu-20.04,
]

services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: djangocms_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3


steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}

uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
sudo apt install gettext gcc -y
python -m pip install --upgrade pip
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install pytest ${{ matrix.django-version }}
pip install -r test_requirements/databases.txt
python setup.py install
- name: Test with django test runner
run: |
python manage.py test
continue-on-error: true
env:
DATABASE_URL: mysql://root@127.0.0.1/djangocms_test
6 changes: 3 additions & 3 deletions cms/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class LazyChoiceField(forms.ChoiceField):

@property
def choices(self):
return super().choices()
return self._choices

@choices.setter
def _set_choices(self, value):
# we overwrite this function so no list(value) is called
def choices(self, value):
# we overwrite this function so no normalize(value) is called
self._choices = self.widget.choices = value


Expand Down
12 changes: 11 additions & 1 deletion cms/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ViewRestrictionInlineAdminForm,
)
from cms.api import assign_user_to_page, create_page, create_page_content
from cms.forms.fields import PageSelectFormField, SuperLazyIterator
from cms.forms.fields import LazyChoiceField, PageSelectFormField, SuperLazyIterator
from cms.forms.utils import (
get_page_choices,
get_site_choices,
Expand Down Expand Up @@ -353,3 +353,13 @@ def test_user_forms(self):
form._current_user = user
self.assertTrue(form.is_valid(), form.errors)
form.save()


class FieldsTestCase(CMSTestCase):
def test_lazy_choice_field(self):
"""LazyChoiceField does not resolve lazy choice objects"""
from django.utils.functional import Promise
from django.utils.translation import gettext_lazy as _

field = LazyChoiceField(choices=_("Lazy"))
self.assertIsInstance(field.choices, Promise)
14 changes: 0 additions & 14 deletions cms/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# TODO: this is just stuff from utils.py - should be splitted / moved
from django.conf import settings
from django.core.files.storage import get_storage_class
from django.utils.functional import LazyObject

from cms.utils.i18n import (
get_default_language,
Expand Down Expand Up @@ -50,14 +47,3 @@ def get_language_from_request(request, current_page=None):
language = get_default_language(site_id=site_id)

return language


default_storage = 'django.contrib.staticfiles.storage.StaticFilesStorage'


class ConfiguredStorage(LazyObject):
def _setup(self):
self._wrapped = get_storage_class(getattr(settings, 'STATICFILES_STORAGE', default_storage))()


configured_storage = ConfiguredStorage()

0 comments on commit f572e38

Please sign in to comment.