Skip to content

Commit f572e38

Browse files
markswebfsbraun
andauthored
test: Run tests against django main branch (#7650)
* 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>
1 parent 534660a commit f572e38

File tree

5 files changed

+163
-21
lines changed

5 files changed

+163
-21
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/workflows/test.yml

Lines changed: 138 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
4444

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

4949
uses: actions/setup-python@v2
@@ -101,7 +101,7 @@ jobs:
101101

102102

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

107107
uses: actions/setup-python@v2
@@ -148,7 +148,7 @@ jobs:
148148
python-version: 3.9
149149

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

154154
uses: actions/setup-python@v2
@@ -167,3 +167,138 @@ jobs:
167167
run: python manage.py test
168168
env:
169169
DATABASE_URL: sqlite://localhost/testdb.sqlite
170+
171+
django-main-sqlite:
172+
runs-on: ${{ matrix.os }}
173+
strategy:
174+
fail-fast: false
175+
matrix:
176+
python-version: ['3.11']
177+
requirements-file: ['requirements_base.txt']
178+
django-version: [
179+
'https://github.com/django/django/archive/main.tar.gz'
180+
]
181+
os: [
182+
ubuntu-20.04,
183+
]
184+
185+
steps:
186+
- uses: actions/checkout@v4
187+
- name: Set up Python ${{ matrix.python-version }}
188+
189+
uses: actions/setup-python@v4
190+
with:
191+
python-version: ${{ matrix.python-version }}
192+
- name: Install dependencies
193+
run: |
194+
sudo apt install gettext gcc -y
195+
python -m pip install --upgrade pip
196+
pip install -r test_requirements/${{ matrix.requirements-file }}
197+
pip install pytest ${{ matrix.django-version }}
198+
python setup.py install
199+
200+
- name: Test with django test runner
201+
run: python manage.py test
202+
continue-on-error: true
203+
env:
204+
DATABASE_URL: sqlite://localhost/testdb.sqlite
205+
206+
django-main-postgres:
207+
runs-on: ${{ matrix.os }}
208+
strategy:
209+
fail-fast: false
210+
matrix:
211+
python-version: ['3.11']
212+
requirements-file: ['requirements_base.txt']
213+
django-version: [
214+
'https://github.com/django/django/archive/main.tar.gz'
215+
]
216+
os: [
217+
ubuntu-20.04,
218+
]
219+
220+
services:
221+
postgres:
222+
image: postgres:13
223+
env:
224+
POSTGRES_USER: postgres
225+
POSTGRES_PASSWORD: postgres
226+
POSTGRES_DB: postgres
227+
ports:
228+
- 5432:5432
229+
# needed because the postgres container does not provide a healthcheck
230+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
231+
232+
steps:
233+
- uses: actions/checkout@v4
234+
- name: Set up Python ${{ matrix.python-version }}
235+
236+
uses: actions/setup-python@v2
237+
with:
238+
python-version: ${{ matrix.python-version }}
239+
cache: 'pip'
240+
- name: Install dependencies
241+
run: |
242+
sudo apt install gettext gcc -y
243+
python -m pip install --upgrade pip
244+
pip install -r test_requirements/${{ matrix.requirements-file }}
245+
pip install pytest ${{ matrix.django-version }}
246+
pip install -r test_requirements/databases.txt
247+
python setup.py install
248+
249+
- name: Test with django test runner
250+
run: |
251+
python -c "from django import __version__ ; print(f'Django version {__version__}')"
252+
python manage.py test
253+
continue-on-error: true
254+
env:
255+
DATABASE_URL: postgres://postgres:postgres@127.0.0.1/postgres
256+
257+
django-main-mysql:
258+
runs-on: ${{ matrix.os }}
259+
strategy:
260+
fail-fast: false
261+
matrix:
262+
python-version: ['3.11']
263+
requirements-file: ['requirements_base.txt']
264+
django-version: [
265+
'https://github.com/django/django/archive/main.tar.gz'
266+
]
267+
os: [
268+
ubuntu-20.04,
269+
]
270+
271+
services:
272+
mysql:
273+
image: mysql:8.0
274+
env:
275+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
276+
MYSQL_DATABASE: djangocms_test
277+
ports:
278+
- 3306:3306
279+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
280+
281+
282+
steps:
283+
- uses: actions/checkout@v4
284+
- name: Set up Python ${{ matrix.python-version }}
285+
286+
uses: actions/setup-python@v2
287+
with:
288+
python-version: ${{ matrix.python-version }}
289+
cache: 'pip'
290+
- name: Install dependencies
291+
run: |
292+
sudo apt install gettext gcc -y
293+
python -m pip install --upgrade pip
294+
pip install -r test_requirements/${{ matrix.requirements-file }}
295+
pip install pytest ${{ matrix.django-version }}
296+
pip install -r test_requirements/databases.txt
297+
python setup.py install
298+
299+
- name: Test with django test runner
300+
run: |
301+
python manage.py test
302+
continue-on-error: true
303+
env:
304+
DATABASE_URL: mysql://root@127.0.0.1/djangocms_test

cms/forms/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class LazyChoiceField(forms.ChoiceField):
2121

2222
@property
2323
def choices(self):
24-
return super().choices()
24+
return self._choices
2525

2626
@choices.setter
27-
def _set_choices(self, value):
28-
# we overwrite this function so no list(value) is called
27+
def choices(self, value):
28+
# we overwrite this function so no normalize(value) is called
2929
self._choices = self.widget.choices = value
3030

3131

cms/tests/test_forms.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ViewRestrictionInlineAdminForm,
1414
)
1515
from cms.api import assign_user_to_page, create_page, create_page_content
16-
from cms.forms.fields import PageSelectFormField, SuperLazyIterator
16+
from cms.forms.fields import LazyChoiceField, PageSelectFormField, SuperLazyIterator
1717
from cms.forms.utils import (
1818
get_page_choices,
1919
get_site_choices,
@@ -353,3 +353,13 @@ def test_user_forms(self):
353353
form._current_user = user
354354
self.assertTrue(form.is_valid(), form.errors)
355355
form.save()
356+
357+
358+
class FieldsTestCase(CMSTestCase):
359+
def test_lazy_choice_field(self):
360+
"""LazyChoiceField does not resolve lazy choice objects"""
361+
from django.utils.functional import Promise
362+
from django.utils.translation import gettext_lazy as _
363+
364+
field = LazyChoiceField(choices=_("Lazy"))
365+
self.assertIsInstance(field.choices, Promise)

cms/utils/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# TODO: this is just stuff from utils.py - should be splitted / moved
2-
from django.conf import settings
3-
from django.core.files.storage import get_storage_class
4-
from django.utils.functional import LazyObject
52

63
from cms.utils.i18n import (
74
get_default_language,
@@ -50,14 +47,3 @@ def get_language_from_request(request, current_page=None):
5047
language = get_default_language(site_id=site_id)
5148

5249
return language
53-
54-
55-
default_storage = 'django.contrib.staticfiles.storage.StaticFilesStorage'
56-
57-
58-
class ConfiguredStorage(LazyObject):
59-
def _setup(self):
60-
self._wrapped = get_storage_class(getattr(settings, 'STATICFILES_STORAGE', default_storage))()
61-
62-
63-
configured_storage = ConfiguredStorage()

0 commit comments

Comments
 (0)