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
9 changes: 3 additions & 6 deletions downloads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,13 @@ def update_supernav():
if latest_pymanager:
data['pymanager'] = latest_pymanager.download_file_for_os(o.slug)

python_files.append(data)
# Only include OSes that have at least one download file
if data['python3'] or data['pymanager']:
python_files.append(data)

if not python_files:
return

if not all(f['python3'] or f['pymanager'] for f in python_files):
# We have a latest Python release, different OSes, but don't have release
# files for the release, so return early.
return

content = render_to_string('downloads/supernav.html', {
'python_files': python_files,
'last_updated': timezone.now(),
Expand Down
46 changes: 45 additions & 1 deletion downloads/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_update_supernav(self):
release=self.python_3,
slug=slug,
name='Python 3.10',
url='/ftp/python/{}.zip'.format(slug),
url=f'/ftp/python/{slug}.zip',
download_button=True,
)

Expand Down Expand Up @@ -186,3 +186,47 @@ def test_update_supernav(self):
self.assertIn('class="download-os-windows"', content)
self.assertIn('pymanager-25.0.msix', content)
self.assertIn('python3.10-windows.zip', content)

def test_update_supernav_skips_os_without_files(self):
"""Test that update_supernav works when an OS has no download files.

Regression test for a bug where adding an OS (like Android) without
any release files would cause update_supernav to silently abort,
leaving the supernav showing outdated version information.
"""
# Arrange
from ..models import OS, update_supernav
from boxes.models import Box

# Create an OS without any release files
OS.objects.create(name="Android", slug="android")

# Create download files for other operating systems
for os, slug in [
(self.osx, "python3.10-macos"),
(self.linux, "python3.10-linux"),
(self.windows, "python3.10-windows"),
]:
ReleaseFile.objects.create(
os=os,
release=self.python_3,
slug=slug,
name="Python 3.10",
url=f"/ftp/python/{slug}.zip",
download_button=True,
)

# Act
update_supernav()

# Assert: verify supernav was updated
box = Box.objects.get(label="supernav-python-downloads")
content = box.content.rendered

# OSes with files should be present
self.assertIn('class="download-os-windows"', content)
self.assertIn('class="download-os-macos"', content)
self.assertIn('class="download-os-linux"', content)

# Android (no files) should not be present
self.assertNotIn("android", content.lower())