Skip to content

Commit b0d4220

Browse files
committed
test: add tests for corrected_release_notes_url property
Covers hg URL conversion, https variant, modern URLs left unchanged, and empty URL passthrough.
1 parent 4830b9c commit b0d4220

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

apps/downloads/tests/test_models.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,53 @@ def test_release_file_urls_not_python_dot_org(self):
311311
name="Windows installer draft",
312312
**kwargs,
313313
)
314+
315+
class ReleaseNotesURLTests(BaseDownloadTests):
316+
"""Tests for Release.corrected_release_notes_url property."""
317+
318+
def test_hg_url_converted_to_github(self):
319+
"""An hg.python.org URL is remapped to its GitHub equivalent."""
320+
release = Release.objects.create(
321+
version=Release.PYTHON3,
322+
name="Python 3.3.6",
323+
is_published=True,
324+
release_notes_url="http://hg.python.org/cpython/file/v3.3.6/Misc/NEWS",
325+
)
326+
self.assertEqual(
327+
release.corrected_release_notes_url,
328+
"https://github.com/python/cpython/blob/v3.3.6/Misc/NEWS",
329+
)
330+
331+
def test_https_hg_url_also_converted(self):
332+
"""An https hg.python.org URL is also remapped to GitHub."""
333+
release = Release.objects.create(
334+
version=Release.PYTHON3,
335+
name="Python 3.2.6",
336+
is_published=True,
337+
release_notes_url="https://hg.python.org/cpython/file/v3.2.6/Misc/NEWS",
338+
)
339+
self.assertEqual(
340+
release.corrected_release_notes_url,
341+
"https://github.com/python/cpython/blob/v3.2.6/Misc/NEWS",
342+
)
343+
344+
def test_modern_url_returned_unchanged(self):
345+
"""A non-hg URL (e.g. already on GitHub) is returned unchanged."""
346+
url = "https://github.com/python/cpython/blob/v3.12.0/Misc/NEWS.d"
347+
release = Release.objects.create(
348+
version=Release.PYTHON3,
349+
name="Python 3.12.0",
350+
is_published=True,
351+
release_notes_url=url,
352+
)
353+
self.assertEqual(release.corrected_release_notes_url, url)
354+
355+
def test_empty_url_returns_empty(self):
356+
"""An empty release_notes_url returns an empty string."""
357+
release = Release.objects.create(
358+
version=Release.PYTHON3,
359+
name="Python 3.11.0",
360+
is_published=True,
361+
release_notes_url="",
362+
)
363+
self.assertEqual(release.corrected_release_notes_url, "")

0 commit comments

Comments
 (0)