[PR #28522] feat: add comprehensive unit tests for dataset service creation methods #32071

Closed
opened 2026-02-21 20:50:41 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: Yes


Description

This PR adds comprehensive unit tests for the DatasetService creation methods, specifically covering create_empty_dataset and create_empty_rag_pipeline_dataset. These tests fill a gap in test coverage and follow the same patterns as existing dataset service tests.

Test Coverage

create_empty_dataset Method Tests (12 test cases)

Internal Dataset Creation:

  • Basic internal dataset creation with required fields
  • Economy indexing technique
  • High quality indexing with default embedding model
  • High quality indexing with custom embedding model
  • Retrieval model configuration
  • Retrieval model with reranking support
  • Custom permission settings

External Dataset Creation:

  • Successful external dataset creation with API and knowledge ID
  • Error handling for missing external API
  • Error handling for missing external knowledge ID

Error Conditions:

  • Duplicate dataset name validation

create_empty_rag_pipeline_dataset Method Tests (6 test cases)

RAG Pipeline Dataset Creation:

  • Creation with provided name
  • Auto-generated name when name is empty
  • Custom permission settings
  • Icon info configuration

Error Conditions:

  • Duplicate name validation
  • Missing current user validation

Testing Approach

  • Follows TDD principles with Arrange-Act-Assert structure
  • Uses factory pattern for test data creation (consistent with existing tests)
  • Comprehensive mocking of dependencies (database, model manager, external services)
  • Tests cover both success paths and error conditions
  • Follows project conventions from test_dataset_service_update_dataset.py and test_dataset_service_delete_dataset.py

Related Work

This complements the existing test coverage:

  • test_dataset_models.py - Dataset model tests (PR #28512)
  • test_dataset_service_update_dataset.py - Update operations
  • test_dataset_service_delete_dataset.py - Delete operations
  • test_dataset_permission.py - Permission checks

Checklist

  • Tests follow TDD principles
  • All tests pass locally
  • Code follows project style guidelines
  • No linting errors
  • Test coverage is comprehensive
  • Tests use proper mocking and fixtures

Contribution by Gittensor, learn more at https://gittensor.io/

**Original Pull Request:** https://github.com/langgenius/dify/pull/28522 **State:** closed **Merged:** Yes --- ## Description This PR adds comprehensive unit tests for the `DatasetService` creation methods, specifically covering `create_empty_dataset` and `create_empty_rag_pipeline_dataset`. These tests fill a gap in test coverage and follow the same patterns as existing dataset service tests. ## Test Coverage ### `create_empty_dataset` Method Tests (12 test cases) **Internal Dataset Creation:** - ✅ Basic internal dataset creation with required fields - ✅ Economy indexing technique - ✅ High quality indexing with default embedding model - ✅ High quality indexing with custom embedding model - ✅ Retrieval model configuration - ✅ Retrieval model with reranking support - ✅ Custom permission settings **External Dataset Creation:** - ✅ Successful external dataset creation with API and knowledge ID - ✅ Error handling for missing external API - ✅ Error handling for missing external knowledge ID **Error Conditions:** - ✅ Duplicate dataset name validation ### `create_empty_rag_pipeline_dataset` Method Tests (6 test cases) **RAG Pipeline Dataset Creation:** - ✅ Creation with provided name - ✅ Auto-generated name when name is empty - ✅ Custom permission settings - ✅ Icon info configuration **Error Conditions:** - ✅ Duplicate name validation - ✅ Missing current user validation ## Testing Approach - Follows **TDD principles** with Arrange-Act-Assert structure - Uses **factory pattern** for test data creation (consistent with existing tests) - Comprehensive **mocking** of dependencies (database, model manager, external services) - Tests cover both **success paths** and **error conditions** - Follows project conventions from `test_dataset_service_update_dataset.py` and `test_dataset_service_delete_dataset.py` ## Related Work This complements the existing test coverage: - ✅ `test_dataset_models.py` - Dataset model tests (PR #28512) - ✅ `test_dataset_service_update_dataset.py` - Update operations - ✅ `test_dataset_service_delete_dataset.py` - Delete operations - ✅ `test_dataset_permission.py` - Permission checks ## Checklist - [x] Tests follow TDD principles - [x] All tests pass locally - [x] Code follows project style guidelines - [x] No linting errors - [x] Test coverage is comprehensive - [x] Tests use proper mocking and fixtures Contribution by Gittensor, learn more at https://gittensor.io/
yindo added the pull-request label 2026-02-21 20:50:41 -05:00
yindo closed this issue 2026-02-21 20:50:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32071