Skip to content

Commit

Permalink
fix tests to independently install djangocms-url-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 7, 2024
1 parent e39fc8f commit ec1bc8d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 48 deletions.
77 changes: 41 additions & 36 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,43 +82,48 @@ def create_page(self, title, **kwargs):
def get_placeholders(self, page):
return page.get_placeholders(self.language)

def create_url(
self,
site=None,
content_object=None,
manual_url="",
relative_path="",
phone="",
mailto="",
anchor="",
):
from djangocms_url_manager.models import Url, UrlGrouper
from djangocms_url_manager.utils import is_versioning_enabled
from djangocms_versioning.constants import DRAFT
from djangocms_versioning.models import Version

if site is None:
site = self.default_site

url = Url.objects.create(
site=site,
content_object=content_object,
manual_url=manual_url,
relative_path=relative_path,
phone=phone,
mailto=mailto,
anchor=anchor,
url_grouper=UrlGrouper.objects.create(),
)
if is_versioning_enabled():
Version.objects.create(
content=url,
created_by=self.superuser,
state=DRAFT,
content_type_id=ContentType.objects.get_for_model(Url).id,
try:
import djangocms_url_manager as __just_testing__

def create_url(
self,
site=None,
content_object=None,
manual_url="",
relative_path="",
phone="",
mailto="",
anchor="",
):
from djangocms_url_manager.models import Url, UrlGrouper
from djangocms_url_manager.utils import is_versioning_enabled
from djangocms_versioning.constants import DRAFT
from djangocms_versioning.models import Version

if site is None:
site = self.default_site

url = Url.objects.create(
site=site,
content_object=content_object,
manual_url=manual_url,
relative_path=relative_path,
phone=phone,
mailto=mailto,
anchor=anchor,
url_grouper=UrlGrouper.objects.create(),
)

return url
if is_versioning_enabled():
Version.objects.create(
content=url,
created_by=self.superuser,
state=DRAFT,
content_type_id=ContentType.objects.get_for_model(Url).id,
)

return url
except ModuleNotFoundError:
pass

def delete_urls(self):
from djangocms_url_manager.models import Url
Expand Down
6 changes: 3 additions & 3 deletions tests/link/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from djangocms_frontend.contrib.link.forms import LinkForm, SmartLinkField
from djangocms_frontend.contrib.link.helpers import get_choices

from ..fixtures import DJANGO_CMS4, TestFixture
from ..fixtures import TestFixture


class LinkPluginTestCase(TestFixture, CMSTestCase):
Expand Down Expand Up @@ -137,14 +137,14 @@ def test_link_form(self):
self.create_url(manual_url="https://www.django-cms.org/").id
)
)
if DJANGO_CMS4
if hasattr(self, "create_url")
else dict(external_link="https://www.django-cms.org/")
),
}
)
form = LinkForm(request.POST)
self.assertTrue(form.is_valid(), f"{form.__class__.__name__}:form errors: {form.errors}")
if DJANGO_CMS4:
if hasattr(self, "create_url"):
self.delete_urls()
else:
request.POST.update({"mailto": "[email protected]"})
Expand Down
17 changes: 8 additions & 9 deletions tests/test_plugin_tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from cms import __version__ as cms_version
from cms.test_utils.testcases import CMSTestCase
from django.contrib.sites.shortcuts import get_current_site
from django.template import engines
Expand Down Expand Up @@ -77,17 +76,17 @@ def test_complex_tags(self):
self.assertInHTML(expected_result, result)

def test_link_plugin(self):
if cms_version < "4":
grouper = None
if hasattr(self, "create_url"):
grouper = self.create_url(manual_url="/test/").url_grouper
template = django_engine.from_string("""{% load frontend %}
{% plugin "textlink" name="Click" external_link="/test/" link_type="btn" link_context="primary" link_outline=False %}
Click me!
{% endplugin %}
""") # noqa: B950
{% plugin "textlink" name="Click" url_grouper=grouper site=test_site link_type="btn" link_context="primary" link_outline=False %}
Click me!
{% endplugin %}
""") # noqa: B950
else:
grouper = self.create_url(manual_url="/test/").url_grouper
grouper = None
template = django_engine.from_string("""{% load frontend %}
{% plugin "textlink" name="Click" url_grouper=grouper site=test_site link_type="btn" link_context="primary" link_outline=False %}
{% plugin "textlink" name="Click" external_link="/test/" link_type="btn" link_context="primary" link_outline=False %}
Click me!
{% endplugin %}
""") # noqa: B950
Expand Down

0 comments on commit ec1bc8d

Please sign in to comment.