diff --git a/readthedocs/proxito/tests/test_hosting.py b/readthedocs/proxito/tests/test_hosting.py index 8294829b935..1ebc43b2371 100644 --- a/readthedocs/proxito/tests/test_hosting.py +++ b/readthedocs/proxito/tests/test_hosting.py @@ -430,6 +430,51 @@ def test_builds_current_is_latest_one(self): # ``a1b2c3-9``is the latest successful build object created assert r.json()["builds"]["current"]["commit"] == "a1b2c3-9" + def test_builds_current_is_latest_one_without_url_parameter(self): + # Create 10 successful build objects + # The latest one (ordered by date) will be ``a1b2c3-9`` + for i in range(10): + fixture.get( + Build, + date=timezone.now(), + project=self.project, + version=self.version, + commit=f"a1b2c3-{i}", + length=60, + state="finished", + success=True, + ) + + # Latest failed build + fixture.get( + Build, + date=timezone.now(), + project=self.project, + version=self.version, + commit=f"a1b2c3-failed", + length=60, + state="finished", + success=False, + ) + + r = self.client.get( + reverse("proxito_readthedocs_docs_addons"), + { + "project-slug": "project", + "version-slug": "latest", + "client-version": "0.6.0", + "api-version": "0.1.0", + }, + secure=True, + headers={ + "host": "project.dev.readthedocs.io", + }, + ) + assert r.status_code == 200 + + # ``a1b2c3-9``is the latest successful build object created + assert r.json()["builds"]["current"]["commit"] == "a1b2c3-9" + def test_project_subproject(self): subproject = fixture.get( Project, diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index f3366f83f47..8500715f505 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -114,7 +114,10 @@ def _resolve_resources(self): project = Project.objects.filter(slug=project_slug).first() version = Version.objects.filter(slug=version_slug, project=project).first() if version: - build = version.builds.first() + build = version.builds.filter( + success=True, + state=BUILD_STATE_FINISHED, + ).first() return project, version, build, filename