Skip to content

Commit

Permalink
Fix migration test and add tests for Django 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 27, 2024
1 parent 3da1aef commit a534cb5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 28 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.10", "3.11", "3.12"] # latest release minus two
python-version: [ "3.9", "3.10", "3.11", "3.12"] # latest release minus two
requirements-file: [
dj42_cms311.txt,
dj42_cms41.txt,
dj50_cms311.txt,
dj50_cms41.txt,
dj51_cms311.txt,
dj51_cms41.txt,
]
os: [
ubuntu-20.04,
]

exclude:
- requirements-file: dj50_cms311.txt
python-version: 3.9
- requirements-file: dj50_cms41.txt
python-version: 3.9
- requirements-file: dj51_cms311.txt
python-version: 3.9
- requirements-file: dj51_cms41.txt
python-version: 3.9
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions tests/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
isort
flake8
pyflakes>=2.1
django-test-migrations
4 changes: 4 additions & 0 deletions tests/requirements/dj51_cms311.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r base.txt

Django>=5.1,<5.2
django-cms>=3.11,<4.0
4 changes: 4 additions & 0 deletions tests/requirements/dj51_cms41.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r base.txt

Django>=5.1,<5.2
django-cms>=4.1,<4.2
69 changes: 43 additions & 26 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from django.forms import model_to_dict
from django.test import TestCase, override_settings

from cms import __version__ as cms_version
from cms.api import create_page
from cms.models import PageUrl

from django_test_migrations.contrib.unittest_case import MigratorTestCase

Expand Down Expand Up @@ -38,44 +40,59 @@ def test_for_missing_migrations(self):
if status_code == '1' and "djangocms_link" in output:
self.fail(f'There are missing migrations:\n {output.getvalue()}')

# @skipIf(__version__ >= '5', "Migration has already been tested before releasing version 5")
@skipIf(__version__ >= '5' or cms_version < "4", "Migration has already been tested before releasing version 5")
class MigrationToVersion5(MigratorTestCase):
migrate_from = ('djangocms_link', '0016_alter_link_cmsplugin_ptr')
migrate_to = ('djangocms_link', '0018_remove_link_anchor_remove_link_external_link_and_more')

def setUp(self):
self.page = model_to_dict(create_page(
title='test',
template='page.html',
language='en',
))
if hasattr(self.page, "node"):
self.node = model_to_dict(self.page.node)
self.file = model_to_dict(get_filer_file())
super().setUp()

def prepare(self):
Link = self.old_state.apps.get_model('djangocms_link', 'Link')
Page = self.old_state.apps.get_model('cms', 'Page')
File = self.old_state.apps.get_model('filer', 'File')
PageContent = self.old_state.apps.get_model('cms', 'PageContent')
PageUrl = self.old_state.apps.get_model('cms', 'PageUrl')
TreeNode = self.old_state.apps.get_model('cms', 'TreeNode')
Site = self.old_state.apps.get_model('sites', 'Site')

# First create a Site at this stage in migration
site = Site.objects.create(
domain='example.com',
name='example.com',
)
# ... then a node
node = TreeNode.objects.create(
path='0001',
depth=1,
numchild=0,
parent=None,
site=site,
)
# ... a page
self.page = Page.objects.create(
node=node,
)
# ... and finally a page content object
PageContent.objects.create(
title='My Page',
page=self.page,
language='en',
)
PageUrl.objects.create(
page=self.page,
language='en',
path='my-page',
)
self.links = [
# Link.objects.create(
# template="default",
# name="My Link",
# internal_link=self.page,
# anchor="some_id",
# ),
Link.objects.create(
template="default",
name="My Link",
internal_link=self.page,
anchor="some_id",
),
Link.objects.create(
template="default",
name="My Link",
external_link="http://www.django-cms.com",
),
# Link.objects.create(
# template="default",
# name="My Link",
# file_link=self.file,
# ),
Link.objects.create(
template="default",
name="My Link",
Expand All @@ -87,13 +104,13 @@ def prepare(self):
phone="+01 234 567 89",
),
]
self.urls = ["http://www.django-cms.com", "mailto:[email protected]", "tel:+0123456789"]
self.urls = ["/en/my-page/#some_id", "http://www.django-cms.com", "mailto:[email protected]", "tel:+0123456789"]

def test_tags_migrated(self):
Link = self.new_state.apps.get_model('djangocms_link', 'Link')
links = Link.objects.all()

for link, url in zip(links, self.urls):
with self.subTest(link=link, url=url):
self.assertEqual(get_link(link.link), url)
self.assertEqual(get_link(link.link, site_id=1), url)

0 comments on commit a534cb5

Please sign in to comment.