Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: modify get_full_url to omit adding base_url in inaplicable cases (…
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 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 |
---|---|---|
|
@@ -706,6 +706,7 @@ Contributors | |
* Mansi Gundre | ||
* Hanoon | ||
* Steve Steinwand | ||
* Swojak-A | ||
|
||
Translators | ||
=========== | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.core.files.base import ContentFile | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
from django.urls import reverse | ||
|
||
from wagtail.documents import models | ||
|
||
|
||
class TestCorrectDownloadUrlSerialization(TestCase): | ||
|
||
"""Test asserts that in case of both `redirect` and `direct` | ||
WAGTAILDOCS_SERVE_METHOD settings `download_url` field | ||
is correctly serialized by DocumentDownloadUrlField.""" | ||
|
||
def setUp(self): | ||
self.document = models.Document(title="Test document", file_hash="123456") | ||
self.document.file.save("example.doc", ContentFile("A boring example document")) | ||
|
||
def tearDown(self): | ||
# delete the FieldFile directly because the TestCase does not commit | ||
# transactions to trigger transaction.on_commit() in the signal handler | ||
self.document.file.delete() | ||
|
||
def get_response(self, document_id, **params): | ||
return self.client.get( | ||
reverse("wagtailapi_v2:documents:detail", args=(document_id,)), params | ||
) | ||
|
||
@override_settings( | ||
WAGTAILDOCS_SERVE_METHOD="redirect", | ||
DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage", | ||
WAGTAILAPI_BASE_URL="http://example.com/", | ||
) | ||
def test_serializer_wagtaildocs_serve_redirect(self): | ||
response = self.get_response(self.document.id) | ||
data = response.json() | ||
self.assertIn("meta", data) | ||
meta = data["meta"] | ||
self.assertIn("download_url", meta) | ||
download_url = meta["download_url"] | ||
expected_url = "http://example.com/documents/%d/example.doc" % self.document.pk | ||
self.assertEqual(download_url, expected_url) | ||
|
||
@override_settings( | ||
WAGTAILDOCS_SERVE_METHOD="direct", | ||
DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage", | ||
MEDIA_URL="http://remotestorage.com/media/", | ||
WAGTAILAPI_BASE_URL="http://example.com/", | ||
) | ||
def test_serializer_wagtaildocs_serve_direct(self): | ||
response = self.get_response(self.document.id) | ||
data = response.json() | ||
self.assertIn("meta", data) | ||
meta = data["meta"] | ||
self.assertIn("download_url", meta) | ||
download_url = meta["download_url"] | ||
self.assertEqual( | ||
download_url, "http://remotestorage.com/media/documents/example.doc" | ||
) |