Skip to content

Adds test case for studio_metadata_mixin class#248

Open
farhan wants to merge 1 commit into
mainfrom
farhan/add-unit-test-video-block
Open

Adds test case for studio_metadata_mixin class#248
farhan wants to merge 1 commit into
mainfrom
farhan/add-unit-test-video-block

Conversation

@farhan
Copy link
Copy Markdown
Contributor

@farhan farhan commented May 13, 2026

Ticket: #197 (comment)

The editable_metadata_fields property on VideoBlock had no dedicated tests, leaving its field-level
transformations (type overrides, transcript language injection, license toggling, English transcript
merging) unverified during the XBlock extraction from edx-platform.

This PR adds:

  • A new test_studio_metadata_mixin.py test file covering VideoBlock.editable_metadata_fields
  • Tests for default field modifications (sub removal, transcripts/edx_video_id/handout type overrides,
    language list injection)
  • Tests for license field removal/retention based on the settings service's licensing_enabled flag
  • Tests for English transcript lookup via the video_config service, including merge-with-existing and
    TranscriptNotFoundError handling
  • Uses DummyRuntime (no XModuleMixin) to ensure the block is exercised in its extracted form

@farhan farhan moved this to 🏗 In progress in Aximprovements Team May 13, 2026
@farhan farhan removed the status in Aximprovements Team May 15, 2026
@farhan farhan moved this to 🏗 In progress in Aximprovements Team May 18, 2026
@farhan farhan marked this pull request as ready for review May 18, 2026 10:36
@farhan farhan moved this from 🏗 In progress to 👀 In review in Aximprovements Team May 18, 2026
@irfanuddinahmad irfanuddinahmad requested a review from Copilot May 21, 2026 09:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds unit tests covering VideoBlock.editable_metadata_fields behavior in StudioMetadataMixin, validating field transformations, licensing behavior, and English transcript enrichment via services.

Changes:

  • Introduces a new Django SimpleTestCase suite for editable_metadata_fields
  • Adds helpers for constructing a VideoBlock and mocking runtime/services
  • Covers default field modifications, licensing on/off, and transcript merge behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py Outdated
Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py Outdated
Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py Outdated
Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py Outdated
@irfanuddinahmad
Copy link
Copy Markdown

Code Review

Overview

This PR adds the first dedicated unit test file for VideoBlock.editable_metadata_fields. The property was previously untested during the XBlock extraction from edx-platform. Coverage targets: field-level transformations (type overrides, sub removal, language injection), license toggling, and English transcript lookup via video_config.

The overall structure is clean and the intent is well-communicated. A few gaps and style points worth addressing before merge.


What Works Well

  • Clear section separators (# ---) and descriptive test names make the file easy to navigate.
  • _service_stub as a @staticmethod is a clean, reusable pattern for wiring a single service mock.
  • @override_settings(ALL_LANGUAGES=...) at the class level is the right place to put it.
  • Good use of _base_fields to keep test setup DRY without hiding intent.

Issues & Suggestions

Medium — Missing edge cases

  1. public_access when public_url=None is never asserted.
    test_default_field_modifications calls _get_fields() (no public_url) but makes no assertion about public_access. Either assert the field is unchanged, or document that the production code doesn't touch public_access when the URL is absent. This is currently an invisible branch.

  2. License field with no settings service.
    There is no test for: _get_fields(include_license=True) where service=None (the default — all services return None). What happens to license in this case? Retained? Removed? This branch is untested.

  3. English transcript when sub is empty.
    Tests for video_config explicitly set self.block.sub = 'some_sub_id' to make possible_sub_ids non-empty. There is no test confirming that when sub is empty the transcript lookup is skipped and transcripts.value is unmodified. That's a meaningful branch in the production code.

Medium — Test does two things

  1. test_field_modifications_with_custom_args tests two unrelated scenarios.
    It tests transcripts.value passthrough and public_access enrichment in one test. Split it into test_transcripts_value_passthrough and test_public_access_enriched_when_url_present. Single-assertion tests are much easier to diagnose on failure.

Minor — Style / coupling

  1. instantiate_block as a module-level function.
    It is only used by this test class. Moving it in as a @staticmethod (or @classmethod) keeps the test class self-contained and makes the relationship to the class explicit.

  2. Hardcoded '/handler/block/handler' couples the assertion to DummyRuntime's internals.
    Consider asserting on a more stable invariant (e.g., assert 'handler' in fields['transcripts']['urlRoot']), or add an inline comment explaining the dependency so a reader doesn't have to go spelunking through DummyRuntime to understand why this URL is expected.

  3. 4-level nested with blocks in _get_fields are hard to scan.
    Python 3 allows parenthesized with on multiple lines:

    with (
        patch.object(self.block, '_get_editable_metadata_fields', return_value=self._base_fields(include_license)),
        patch.object(self.block, 'get_transcripts_info', return_value={'sub': '', 'transcripts': transcripts or {}}),
        patch.object(self.block, 'get_public_video_url', return_value=public_url),
        patch.object(self.block.runtime, 'service', **service_kwargs),
    ):
        return self.block.editable_metadata_fields
  4. self.block.sub = 'some_sub_id' mutates shared state without comment.
    It's safe here because setUp re-creates self.block per test, but a brief comment (# triggers possible_sub_ids to be non-empty) would help future readers who might not realize why this assignment is required.


Summary

Severity Count
Medium (missing coverage) 3
Medium (test design) 1
Minor (style/coupling) 4

Good foundational PR — the happy paths and primary error path are all covered. The main asks before merge are: test public_access when URL is absent, test license behavior when there is no settings service, and test the sub-is-empty branch for transcript lookup. The style points are optional but would improve long-term maintainability.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py
Comment thread xblocks_contrib/video/tests/test_studio_metadata_mixin.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

The editable_metadata_fields property had no dedicated tests, leaving
its field-level transformations (type overrides, sub removal, transcript
language injection, license toggling, English transcript merging via
video_config service) unverified during XBlock extraction from
edx-platform.

Adds TestEditableMetadataFieldsProperty covering:
- Default field modifications (sub removal, type overrides for
  transcripts/edx_video_id/handout, urlRoot, public_access)
- Transcripts value passthrough and public_access URL enrichment
- License removal/retention based on settings service licensing_enabled
- License retention when no settings service is present
- English transcript lookup via video_config (found, merged, not found)

Uses DummyRuntime (no XModuleMixin) to exercise the block in its
extracted form.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@farhan farhan force-pushed the farhan/add-unit-test-video-block branch from 6b992db to 177ed85 Compare May 22, 2026 08:02
@farhan farhan closed this May 22, 2026
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Aximprovements Team May 22, 2026
@farhan farhan reopened this May 22, 2026
@farhan farhan requested a review from Copilot May 22, 2026 08:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants