kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Add integration tests for the full process_content_requests flow including file transfer outcomes

Open AlexVelezLl opened this issue 7 months ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Follow up to https://github.com/learningequality/kolibri/pull/14619#discussion_r3118333501.

Overview

Complexity: Medium Target branch: develop

process_content_requests() currently has integration tests in TestImportMetadataChannelUpgrade that cover the metadata-import phase end-to-end, but _process_content_requests (the file-transfer phase) is always mocked — so no test exercises the full flow from metadata import through to file transfer completion or failure. This task adds a test class covering that gap, including the post-upgrade edge case flagged in this PR review comment.

Context

TestImportMetadataChannelUpgrade (in kolibri/core/content/test/utils/test_content_request.py, lines 2160–2403) tests process_content_requests() end-to-end using a module-scoped import_metadata_responses pytest fixture (lines 2085–2157) that pre-builds real channel metadata responses (v1 and v2) by hitting the live importmetadata endpoint, then removes the channel from the DB so each test starts clean.

Within that class, _get_import_metadata is mocked to return the pre-built responses, import_channel_from_data runs for real (so ContentNode/ChannelMetadata rows are actually written), and PreferredDevicesWithClient is mocked to return a known peer — but _process_content_requests is always mocked to just mark all downloads as Completed. This means no existing test exercises the file-transfer phase at all.

Additionally, a PR review comment on #14619 flags a specific untested path in _import_metadata: when a node survives a channel upgrade in the DB with available=False (the has_metadata=True, available=False case), the current tests don't verify it gets re-queued correctly. This issue covers both that focused gap and the broader missing file-transfer integration tests.

The Change

A new pytest test class (separate from TestImportMetadataChannelUpgrade, reusing what makes sense from the import_metadata_responses fixture and setup patterns) that exercises the full process_content_requests() flow — metadata import through file transfer — without mocking _process_content_requests. ContentDownloadRequestResourceImportManager is mocked to simulate file transfer outcomes without real I/O.

The class should cover at minimum:

  • Successful file transfer — ContentDownloadRequestResourceImportManager returns a non-zero count, no exception; the download request ends up Completed
  • Failed file transfer — ContentDownloadRequestResourceImportManager raises LocationError or sets an exception; the download request ends up Failed
  • Content already available — the ContentNode is already available=True before the download is attempted; the AlreadyAvailable path is taken and the request still ends up Completed
  • Post-upgrade has_metadata=True, available=False node — a node that survives a channel upgrade in the DB with available=False is re-queued for download (not skipped), and the download request transitions correctly based on the simulated file transfer outcome

Acceptance Criteria

General

  • [ ] A new test class covers process_content_requests() end-to-end without mocking _process_content_requests
  • [ ] ContentDownloadRequestResourceImportManager is mocked to simulate file transfer outcomes; no real file I/O occurs

Testing

  • [ ] A test verifies that a successful file transfer results in the download request marked Completed
  • [ ] A test verifies that a failed file transfer (e.g. LocationError) results in the download request marked Failed
  • [ ] A test verifies that when a ContentNode is already available=True, the AlreadyAvailable path is taken and the request is still marked Completed
  • [ ] A test verifies that after a channel upgrade, a node that remains in the DB with available=False (has_metadata=True, available=False) is re-queued for download and transitions to the correct status based on the simulated file transfer outcome

AI usage

This issue was drafted with Claude Code assistance from session context and code review of test_content_request.py and content_request.py. The problem description and acceptance criteria were verified against the actual source. The content was reviewed and edited for accuracy before filing.

AlexVelezLl avatar Apr 29 '26 19:04 AlexVelezLl

Plan: Integration tests that run process_content_requests() from metadata import through file transfer, with only the import manager faked (#14660).

  • [ ] Extract the shared channel-metadata setup into a base class
  • [ ] Add the file-transfer integration test class
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • Shared setup is lifted into a base class; if reviewers want TestImportMetadataChannelUpgrade untouched, the new class copies ~50 setup lines.
  • Success fake sets the node available=True; if a plain return-value mock is preferred, the already-available test needs a manual update between two passes.
  • Already-available case uses two requesters for one node in one pass; if one requester is wanted, it becomes two passes with a manual availability update.
  • Post-upgrade test also asserts one metadata fetch in pass 2, for the review's "not added to downloads_to_process"; if that counts as implementation detail, drop it and keep the status assertions.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Oct 25 '26 18:10 rtibblesbot