[PR #29373] test: add comprehensive unit tests for RAG pipeline controller #32394

Open
opened 2026-02-21 20:51:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/29373

State: open
Merged: No


Description

This PR adds comprehensive unit tests for the RAG pipeline controller that was previously missing test coverage. The RAG pipeline controller handles pipeline template management, creation, configuration, execution, and status management.

Changes

RAG Pipeline Controller Tests

  • Test pipeline template listing (built-in and customized)
  • Test template detail retrieval
  • Test customized template CRUD operations (create, update, delete)
  • Test template publishing
  • Test payload validation
  • Test error handling for various failure scenarios
  • Test different language support
  • Test template YAML content retrieval

File: api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline.py
Test Cases: 18 tests covering all major functionality

Test Coverage Details

  1. Pipeline Template Listing

    • Built-in templates with default parameters
    • Customized templates retrieval
    • Different language support (en-US, zh-CN, etc.)
    • Empty result handling
  2. Template Detail Retrieval

    • Built-in template detail retrieval
    • Customized template detail retrieval
    • Template not found handling
  3. Customized Template CRUD

    • Template update (PATCH) with valid payload
    • Template update with invalid payload validation
    • Template deletion (DELETE)
    • Template deletion when not found
    • Template YAML content retrieval (POST)
    • Template YAML retrieval when not found
  4. Template Publishing

    • Successful template publishing
    • Publishing with invalid payload
    • Publishing with empty name validation
    • Publishing with icon information

Testing Approach

  • All tests use proper mocking to avoid external dependencies
  • Tests follow existing patterns in the codebase
  • Tests validate Pydantic model validation
  • Tests cover both success and error scenarios
  • Tests validate payload constraints (min_length, max_length)
  • Extensive comments throughout explaining test purpose, setup, and assertions

Test Coverage

  • RAG Pipeline Controller: 18 test cases covering all API endpoints and error scenarios
  • Total: 844+ lines of well-documented test code

Comments and Documentation

As requested, all tests include extensive comments explaining:

  • Test purpose and what is being verified
  • Test setup and arrangement (Arrange-Act-Assert pattern)
  • Expected behavior and assertions
  • Edge cases and error conditions
  • Parameter descriptions in docstrings

Checklist

  • Tests follow the project's testing guidelines
  • All tests pass locally
  • Code follows existing patterns and conventions
  • No linter errors
  • Tests use proper mocking to avoid external dependencies
  • Extensive comments added throughout test file

Related

Part of the effort to improve test coverage across the Dify codebase.

Close: #29372

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=157775043

**Original Pull Request:** https://github.com/langgenius/dify/pull/29373 **State:** open **Merged:** No --- ## Description This PR adds comprehensive unit tests for the RAG pipeline controller that was previously missing test coverage. The RAG pipeline controller handles pipeline template management, creation, configuration, execution, and status management. ## Changes ### RAG Pipeline Controller Tests - ✅ Test pipeline template listing (built-in and customized) - ✅ Test template detail retrieval - ✅ Test customized template CRUD operations (create, update, delete) - ✅ Test template publishing - ✅ Test payload validation - ✅ Test error handling for various failure scenarios - ✅ Test different language support - ✅ Test template YAML content retrieval **File**: `api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline.py` **Test Cases**: 18 tests covering all major functionality ### Test Coverage Details 1. **Pipeline Template Listing** - Built-in templates with default parameters - Customized templates retrieval - Different language support (en-US, zh-CN, etc.) - Empty result handling 2. **Template Detail Retrieval** - Built-in template detail retrieval - Customized template detail retrieval - Template not found handling 3. **Customized Template CRUD** - Template update (PATCH) with valid payload - Template update with invalid payload validation - Template deletion (DELETE) - Template deletion when not found - Template YAML content retrieval (POST) - Template YAML retrieval when not found 4. **Template Publishing** - Successful template publishing - Publishing with invalid payload - Publishing with empty name validation - Publishing with icon information ## Testing Approach - All tests use proper mocking to avoid external dependencies - Tests follow existing patterns in the codebase - Tests validate Pydantic model validation - Tests cover both success and error scenarios - Tests validate payload constraints (min_length, max_length) - **Extensive comments throughout** explaining test purpose, setup, and assertions ## Test Coverage - **RAG Pipeline Controller**: 18 test cases covering all API endpoints and error scenarios - **Total**: 844+ lines of well-documented test code ## Comments and Documentation As requested, all tests include extensive comments explaining: - Test purpose and what is being verified - Test setup and arrangement (Arrange-Act-Assert pattern) - Expected behavior and assertions - Edge cases and error conditions - Parameter descriptions in docstrings ## Checklist - [x] Tests follow the project's testing guidelines - [x] All tests pass locally - [x] Code follows existing patterns and conventions - [x] No linter errors - [x] Tests use proper mocking to avoid external dependencies - [x] Extensive comments added throughout test file ## Related Part of the effort to improve test coverage across the Dify codebase. Close: #29372 Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=157775043
yindo added the pull-request label 2026-02-21 20:51:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32394