[PR #29366] test: add unit tests for workspace endpoint and load balancing config controllers #32391

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

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

State: open
Merged: No


Description

This PR adds comprehensive unit tests for two workspace controllers that were previously missing test coverage:

  1. Workspace Endpoint Controller (api/controllers/console/workspace/endpoint.py)
  2. Load Balancing Config Controller (api/controllers/console/workspace/load_balancing_config.py)

Changes

Workspace Endpoint Controller Tests

  • Test endpoint creation with valid/invalid plugin identifiers
  • Test endpoint listing with pagination
  • Test plugin-specific endpoint filtering
  • Test endpoint update and deletion
  • Test endpoint enable/disable operations
  • Test authorization checks (admin/owner only)
  • Test input validation (name, settings, pagination parameters)
  • Test error handling (PluginPermissionDeniedError)

File: api/tests/unit_tests/controllers/console/workspace/test_endpoint.py
Test Cases: 13 tests across 7 test classes

Load Balancing Config Controller Tests

  • Test credentials validation (success and failure cases)
  • Test config-specific credentials validation
  • Test authorization (admin/owner only)
  • Test parameter validation (model, model_type, credentials)
  • Test different model types support (LLM, TEXT_EMBEDDING, etc.)
  • Test unauthorized access handling

File: api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.py
Test Cases: 12 tests across 2 test classes

Testing Approach

  • All tests use proper mocking to avoid external dependencies
  • Tests follow existing patterns in the codebase (similar to test_billing.py)
  • Tests validate authorization decorators work correctly
  • Tests cover both success and error scenarios
  • Tests validate Pydantic model validation and RequestParser validation

Test Coverage

  • Endpoint Controller: 13 test cases covering all 7 API endpoints
  • Load Balancing Controller: 12 test cases covering both validation endpoints
  • Total: 25 test cases

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

Related

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

Close: #29365


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

**Original Pull Request:** https://github.com/langgenius/dify/pull/29366 **State:** open **Merged:** No --- ## Description This PR adds comprehensive unit tests for two workspace controllers that were previously missing test coverage: 1. **Workspace Endpoint Controller** (`api/controllers/console/workspace/endpoint.py`) 2. **Load Balancing Config Controller** (`api/controllers/console/workspace/load_balancing_config.py`) ## Changes ### Workspace Endpoint Controller Tests - ✅ Test endpoint creation with valid/invalid plugin identifiers - ✅ Test endpoint listing with pagination - ✅ Test plugin-specific endpoint filtering - ✅ Test endpoint update and deletion - ✅ Test endpoint enable/disable operations - ✅ Test authorization checks (admin/owner only) - ✅ Test input validation (name, settings, pagination parameters) - ✅ Test error handling (PluginPermissionDeniedError) **File**: `api/tests/unit_tests/controllers/console/workspace/test_endpoint.py` **Test Cases**: 13 tests across 7 test classes ### Load Balancing Config Controller Tests - ✅ Test credentials validation (success and failure cases) - ✅ Test config-specific credentials validation - ✅ Test authorization (admin/owner only) - ✅ Test parameter validation (model, model_type, credentials) - ✅ Test different model types support (LLM, TEXT_EMBEDDING, etc.) - ✅ Test unauthorized access handling **File**: `api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.py` **Test Cases**: 12 tests across 2 test classes ## Testing Approach - All tests use proper mocking to avoid external dependencies - Tests follow existing patterns in the codebase (similar to `test_billing.py`) - Tests validate authorization decorators work correctly - Tests cover both success and error scenarios - Tests validate Pydantic model validation and RequestParser validation ## Test Coverage - **Endpoint Controller**: 13 test cases covering all 7 API endpoints - **Load Balancing Controller**: 12 test cases covering both validation endpoints - **Total**: 25 test cases ## 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 ## Related Part of the effort to improve test coverage across the Dify codebase. Close: #29365 --- 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#32391