@@ -123,6 +123,27 @@ def test_visual_context__for_page__with_no_revision(mock_capture_message, client
123123 mock_capture_message .assert_called_once_with (f"Unable to get a latest_revision for { page } so unable to send visual context." )
124124
125125
126+ @override_settings (WAGTAILADMIN_BASE_URL = "https://cms.example.com" )
127+ @mock .patch ("springfield.cms.wagtail_localize_smartling.callbacks.SharingLinkView.as_view" )
128+ @mock .patch ("springfield.cms.wagtail_localize_smartling.callbacks.RequestFactory" )
129+ def test__get_html_for_sharing_link__uses_cms_hostname_and_path_only (mock_factory_cls , mock_as_view ):
130+ # sharing_link.url is a full URL — we should extract just the path and use
131+ # the CMS hostname as SERVER_NAME so make_preview_request doesn't fall back
132+ # to 'localhost' / 'testserver' and return a 400 error page.
133+ mock_response = mock .Mock ()
134+ mock_response .text = "<html><body>page content</body></html>"
135+ mock_as_view .return_value = mock .Mock (return_value = mock_response )
136+
137+ sharing_link = mock .Mock ()
138+ sharing_link .url = "http://localhost/_internal_draft_preview/abc123/"
139+
140+ result = _get_html_for_sharing_link (sharing_link )
141+
142+ mock_factory_cls .assert_called_once_with (SERVER_NAME = "cms.example.com" )
143+ mock_factory_cls .return_value .get .assert_called_once_with ("/_internal_draft_preview/abc123/" )
144+ assert result == "<html><body>page content</body></html>"
145+
146+
126147# The happy path is implicitly tested in test_visual_context__*, above
127148@mock .patch ("springfield.cms.wagtail_localize_smartling.callbacks.capture_exception" )
128149@mock .patch ("springfield.cms.wagtail_localize_smartling.callbacks.SharingLinkView.as_view" )
0 commit comments