diff --git a/downloads/models.py b/downloads/models.py index fb651c29a..9101305ff 100644 --- a/downloads/models.py +++ b/downloads/models.py @@ -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(), diff --git a/downloads/tests/test_models.py b/downloads/tests/test_models.py index 1f260e08a..4d9918904 100644 --- a/downloads/tests/test_models.py +++ b/downloads/tests/test_models.py @@ -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, ) @@ -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())