Skip to content

test: Run tests against django main branch #7650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()