Skip to content

Commit

Permalink
Addons: build.current API response fix (#11068)
Browse files Browse the repository at this point in the history
When _not sending `url=` parameter_, we were returning the lastest build by date,
but we need to filter it by `state=finished` and `success=True` in the same way
as we are doing when sending the `url=` parameter.

I found this while working on readthedocs/addons#88
  • Loading branch information
humitos authored Jan 29, 2024
1 parent dcd4655 commit ae09228
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 45 additions & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ae09228

Please sign in to comment.