diff --git a/readthedocs/projects/views/public.py b/readthedocs/projects/views/public.py index b3afdd485d7..49437c16379 100644 --- a/readthedocs/projects/views/public.py +++ b/readthedocs/projects/views/public.py @@ -26,7 +26,7 @@ from readthedocs.analytics.tasks import analytics_event from readthedocs.analytics.utils import get_client_ip -from readthedocs.builds.constants import LATEST +from readthedocs.builds.constants import LATEST, BUILD_STATUS_DUPLICATED from readthedocs.builds.models import Version from readthedocs.builds.views import BuildTriggerMixin from readthedocs.core.permissions import AdminPermission @@ -177,10 +177,16 @@ def get(self, request, project_slug, *args, **kwargs): ).first() if version: - last_build = version.builds.filter( - type='html', - state='finished', - ).order_by('-date').first() + last_build = ( + version.builds + .filter( + type='html', + state='finished', + ) + .exclude(status=BUILD_STATUS_DUPLICATED) + .order_by('-date') + .first() + ) if last_build: if last_build.success: status = self.STATUS_PASSING diff --git a/readthedocs/rtd_tests/tests/test_project_views.py b/readthedocs/rtd_tests/tests/test_project_views.py index eed95783ea6..524831859b7 100644 --- a/readthedocs/rtd_tests/tests/test_project_views.py +++ b/readthedocs/rtd_tests/tests/test_project_views.py @@ -11,7 +11,7 @@ from django.views.generic.base import ContextMixin from django_dynamic_fixture import get, new -from readthedocs.builds.constants import EXTERNAL +from readthedocs.builds.constants import BUILD_STATUS_DUPLICATED, EXTERNAL from readthedocs.builds.models import Build, Version from readthedocs.integrations.models import GenericAPIWebhook, GitHubWebhook from readthedocs.oauth.models import RemoteRepository @@ -611,6 +611,25 @@ def test_passing_badge(self): self.assertContains(res, 'passing') self.assertEqual(res['Content-Type'], 'image/svg+xml') + def test_ignore_duplicated_build(self): + """Ignore builds marked as duplicate from the badge status.""" + get( + Build, + project=self.project, + version=self.version, + success=True, + ) + get( + Build, + project=self.project, + version=self.version, + success=False, + status=BUILD_STATUS_DUPLICATED, + ) + res = self.client.get(self.badge_url, {'version': self.version.slug}) + self.assertContains(res, 'passing') + self.assertEqual(res['Content-Type'], 'image/svg+xml') + def test_failing_badge(self): get(Build, project=self.project, version=self.version, success=False) res = self.client.get(self.badge_url, {'version': self.version.slug})