Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readthedocs/api/v2/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def concurrent(self, request, **kwargs):
# We make this endpoint public because we don't want to expose the build API key inside the user's container.
# To emulate "auth" we check for the builder hostname to match the `Build.builder` defined in the database.
permission_classes=[],
# We can't use the default `get_queryset()` method because it's filtered by build API key and/or user access.
# Since we don't want to check for permissions here we need to use a custom queryset here.
get_queryset=lambda: Build.objects.all(),
methods=["post"],
)
def healthcheck(self, request, **kwargs):
Expand Down
43 changes: 43 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,49 @@ def setUp(self):
self.project = get(Project, users=[self.user])
self.version = self.project.versions.get(slug=LATEST)

def test_healthcheck(self):
# Build cloning state
build = get(
Build,
project=self.project,
version=self.version,
state=BUILD_STATE_CLONING,
builder="build-a1b2c3",
success=False,
)
self.assertIsNone(build.healthcheck)

client = APIClient()
r = client.post(reverse("build-healthcheck", args=(build.pk,), query={"builder": "build-a1b2c3"}))
build.refresh_from_db()

self.assertEqual(r.status_code, 204)
self.assertIsNotNone(build.healthcheck)

# Build invalid builder
build.healthcheck = None
build.save()

client = APIClient()
r = client.post(reverse("build-healthcheck", args=(build.pk,), query={"builder": "build-invalid"}))
build.refresh_from_db()

self.assertEqual(r.status_code, 404)
self.assertIsNone(build.healthcheck)

# Build finished state
build.state = BUILD_STATE_FINISHED
build.healthcheck = None
build.save()

client = APIClient()
r = client.post(reverse("build-healthcheck", args=(build.pk,), query={"builder": "build-a1b2c3"}))
build.refresh_from_db()

self.assertEqual(r.status_code, 404)
self.assertIsNone(build.healthcheck)


def test_reset_build(self):
build = get(
Build,
Expand Down