Skip to content

Commit a47658e

Browse files
committed
Fix updating the supernav downloads
1 parent 27aef89 commit a47658e

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

downloads/models.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,13 @@ def update_supernav():
175175
if latest_pymanager:
176176
data['pymanager'] = latest_pymanager.download_file_for_os(o.slug)
177177

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

180182
if not python_files:
181183
return
182184

183-
if not all(f['python3'] or f['pymanager'] for f in python_files):
184-
# We have a latest Python release, different OSes, but don't have release
185-
# files for the release, so return early.
186-
return
187-
188185
content = render_to_string('downloads/supernav.html', {
189186
'python_files': python_files,
190187
'last_updated': timezone.now(),

downloads/tests/test_models.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_update_supernav(self):
157157
release=self.python_3,
158158
slug=slug,
159159
name='Python 3.10',
160-
url='/ftp/python/{}.zip'.format(slug),
160+
url=f'/ftp/python/{slug}.zip',
161161
download_button=True,
162162
)
163163

@@ -186,3 +186,47 @@ def test_update_supernav(self):
186186
self.assertIn('class="download-os-windows"', content)
187187
self.assertIn('pymanager-25.0.msix', content)
188188
self.assertIn('python3.10-windows.zip', content)
189+
190+
def test_update_supernav_skips_os_without_files(self):
191+
"""Test that update_supernav works when an OS has no download files.
192+
193+
Regression test for a bug where adding an OS (like Android) without
194+
any release files would cause update_supernav to silently abort,
195+
leaving the supernav showing outdated version information.
196+
"""
197+
# Arrange
198+
from ..models import OS, update_supernav
199+
from boxes.models import Box
200+
201+
# Create an OS without any release files
202+
OS.objects.create(name="Android", slug="android")
203+
204+
# Create download files for other operating systems
205+
for os, slug in [
206+
(self.osx, "python3.10-macos"),
207+
(self.linux, "python3.10-linux"),
208+
(self.windows, "python3.10-windows"),
209+
]:
210+
ReleaseFile.objects.create(
211+
os=os,
212+
release=self.python_3,
213+
slug=slug,
214+
name="Python 3.10",
215+
url=f"/ftp/python/{slug}.zip",
216+
download_button=True,
217+
)
218+
219+
# Act
220+
update_supernav()
221+
222+
# Assert: verify supernav was updated
223+
box = Box.objects.get(label="supernav-python-downloads")
224+
content = box.content.rendered
225+
226+
# OSes with files should be present
227+
self.assertIn('class="download-os-windows"', content)
228+
self.assertIn('class="download-os-macos"', content)
229+
self.assertIn('class="download-os-linux"', content)
230+
231+
# Android (no files) should not be present
232+
self.assertNotIn("android", content.lower())

0 commit comments

Comments
 (0)