-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: refactor tests for djangoCMS 4 support
- Loading branch information
1 parent
1a21f40
commit f5d89f0
Showing
5 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from django.apps import apps | ||
|
||
from cms import __version__ | ||
|
||
DJANGO_CMS4 = not (__version__ < "4") | ||
DJANGOCMS_VERSIONING = apps.is_installed("djangocms_versioning") | ||
|
||
|
||
class TestFixture: | ||
"""Sets up generic setUp and tearDown methods for tests.""" | ||
|
||
def setUp(self): | ||
self.language = "en" | ||
self.superuser = self.get_superuser() | ||
return super().setUp() | ||
|
||
def tearDown(self): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.models import Version | ||
|
||
Version.objects.all().delete() | ||
return super().tearDown() | ||
|
||
if DJANGO_CMS4: # CMS V4 | ||
|
||
def _get_version(self, grouper, version_state, language=None): | ||
language = language or self.language | ||
|
||
from djangocms_versioning.models import Version | ||
|
||
versions = Version.objects.filter_by_grouper(grouper).filter( | ||
state=version_state | ||
) | ||
for version in versions: | ||
if ( | ||
hasattr(version.content, "language") | ||
and version.content.language == language | ||
): | ||
return version | ||
return None | ||
|
||
def publish(self, grouper, language=None): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.constants import DRAFT | ||
|
||
version = self._get_version(grouper, DRAFT, language) | ||
if version is not None: | ||
version.publish(self.superuser) | ||
|
||
def unpublish(self, grouper, language=None): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.constants import PUBLISHED | ||
|
||
version = self._get_version(grouper, PUBLISHED, language) | ||
if version is not None: | ||
version.unpublish(self.superuser) | ||
|
||
def get_placeholders(self, page, language=None): | ||
return page.get_placeholders(language or self.language) | ||
|
||
else: # CMS V3 | ||
|
||
def publish(self, page, language=None): | ||
page.publish(language) | ||
|
||
def unpublish(self, page, language=None): | ||
page.unpublish(language) | ||
|
||
def get_placeholders(self, page, language=None): | ||
return page.get_placeholders() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters