Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add tox testing for Django 5.1 and Wagtail 6.2 + 6.3
- Drop testing for Python 3.8
- Fix `get_client_root_url` when no Site is set

## [0.8] - 2024-02-23

Expand Down
2 changes: 1 addition & 1 deletion src/wagtail_headless_preview/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_client_root_url_from_site(site) -> str:
root_url = headless_preview_settings.CLIENT_URLS[site.hostname]
except (AttributeError, KeyError):
root_url = headless_preview_settings.CLIENT_URLS["default"].format(
SITE_ROOT_URL=site.root_url
SITE_ROOT_URL=getattr(site, "root_url", "")
)

if headless_preview_settings.ENFORCE_TRAILING_SLASH:
Expand Down
14 changes: 13 additions & 1 deletion tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.test import RequestFactory, TestCase, override_settings
from django.urls import reverse
from django.utils.http import urlencode
from wagtail.models import Page
from wagtail.models import Page, Site

from tests.testapp.models import HeadlessPage, SimplePage
from wagtail_headless_preview.models import PagePreview
Expand Down Expand Up @@ -109,6 +109,18 @@ def test_get_client_root_url_without_trailing_slash_enforcement(self):
"https://headless.site",
)

@override_settings(
WAGTAIL_HEADLESS_PREVIEW={
"CLIENT_URLS": {"default": "https://headless.site"},
}
)
def test_get_client_root_url_with_no_site(self):
Site.objects.all().delete()
self.assertEqual(
self.page.get_client_root_url(self.request),
"https://headless.site/",
)

@override_settings(
WAGTAIL_HEADLESS_PREVIEW={"SERVE_BASE_URL": "https://headless.site"},
TEST_OVERRIDE_CLIENT_ROOT_URL=True,
Expand Down