Skip to content

test: unit test case for controllers.console.app module#32247

Open
rajatagarwal-oss wants to merge 8 commits intolanggenius:mainfrom
infocusp-fullstack:chore/controllers.console.app_unit-tests
Open

test: unit test case for controllers.console.app module#32247
rajatagarwal-oss wants to merge 8 commits intolanggenius:mainfrom
infocusp-fullstack:chore/controllers.console.app_unit-tests

Conversation

@rajatagarwal-oss
Copy link

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #32072 .

Summary

Added unit test cases controllers.console.app module.
fixes #32072

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Feb 11, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rajatagarwal-oss, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on substantially improving the unit test coverage across a wide array of console API endpoints and related functionalities. The changes introduce new test files for numerous modules, ensuring that critical components like app management, data handling, and administrative tasks are thoroughly validated. This effort aims to bolster the overall robustness and maintainability of the application's backend by catching potential issues early and providing a more stable development environment.

Highlights

  • Expanded Unit Test Coverage: Significantly increased unit test coverage for various modules within controllers.console.app, including annotation, completion, ops_trace, site, workflow, workflow app log, workflow draft variable, workflow statistic, workflow trigger, wraps, MCP server, app import, audio, conversation, generator, message, model config, and statistic APIs. This enhances the reliability and stability of these API endpoints.
  • Refactored Existing Tests: Updated existing unit tests in test_annotation_security.py and workflow_draft_variables_test.py by moving internal imports to the top of the file for better code organization and consistency. The test_annotation_security.py also saw a change in a test case from timeout configuration to queue registration.
  • New Unit Tests for Console Controllers: Introduced new unit tests for several console controllers, specifically for admin functionalities (banner and app management), API key management, feature flags, file handling (upload, preview, supported types), API specification definitions, and version checking logic.
  • Removed Obsolete Test Files: Two test files, test_fastopenapi_init_validate.py and test_fastopenapi_remote_files.py, were removed, indicating a cleanup or refactoring of FastOpenAPI related tests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • api/tests/unit_tests/controllers/console/app/test_annotation_api.py
    • Added new unit tests for AnnotationReplyPayload, AnnotationSettingUpdatePayload, AnnotationListQuery, CreateAnnotationPayload, UpdateAnnotationPayload, AnnotationReplyStatusQuery, and AnnotationFilePayload.
  • api/tests/unit_tests/controllers/console/app/test_annotation_security.py
    • Updated imports to move annotation_import_rate_limit and annotation_import_concurrency_limit to top-level imports.
    • Changed test_task_has_timeout_configured to test_task_is_registered_with_queue to verify task queue registration.
  • api/tests/unit_tests/controllers/console/app/test_app_apis.py
    • Added new unit tests for Completion, OpsTrace, Site, Workflow, Workflow App Log, Workflow Draft Variable, Workflow Statistic, Workflow Trigger, Wraps, and MCP Server endpoints.
    • Included tests for error handling and payload validation across various modules.
  • api/tests/unit_tests/controllers/console/app/test_app_import_api.py
    • Added new unit tests for AppImportApi and AppImportConfirmApi covering import status, webapp auth updates, and dependency checks.
  • api/tests/unit_tests/controllers/console/app/test_audio_api.py
    • Added new unit tests for audio-to-text and text-to-audio functionalities, including error handling for large audio files and voice listing.
  • api/tests/unit_tests/controllers/console/app/test_conversation_api.py
    • Added new unit tests for conversation listing, retrieval, and deletion, including handling of invalid time ranges and missing conversations.
  • api/tests/unit_tests/controllers/console/app/test_generator_api.py
    • Added new unit tests for rule generation, instruction generation (code nodes, legacy modify), and instruction template generation, covering various success and error paths.
  • api/tests/unit_tests/controllers/console/app/test_message_api.py
    • Added new unit tests for chat message queries, message feedback payloads, and feedback export queries, including validation and default values.
  • api/tests/unit_tests/controllers/console/app/test_model_config_api.py
    • Added new unit tests for ModelConfigResource, verifying app model configuration updates for chat and agent modes, including encryption of agent tool parameters.
  • api/tests/unit_tests/controllers/console/app/test_statistic_api.py
    • Added new unit tests for daily message, conversation, token cost, and terminal statistics, including error handling for invalid time ranges.
  • api/tests/unit_tests/controllers/console/app/test_wraps.py
    • Added new unit tests for the get_app_model decorator, validating app model injection and error handling for incorrect modes or missing IDs.
  • api/tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py
    • Moved FileTransferMethod, FileType, and File imports from within test functions to the top of the file.
  • api/tests/unit_tests/controllers/console/test_admin.py
    • Added extensive unit tests for DeleteExploreBannerApi, InsertExploreBannerApi, InsertExploreAppApi, and InsertExploreAppListApi.
    • Introduced fixtures for admin authentication, console payload, banner payload, and session factory.
    • Covered scenarios for banner management, recommended app creation/update/deletion, and trial app handling.
  • api/tests/unit_tests/controllers/console/test_apikey.py
    • Added new unit tests for BaseApiKeyListResource and BaseApiKeyResource, covering API key listing, deletion, and permission checks.
  • api/tests/unit_tests/controllers/console/test_fastopenapi_init_validate.py
    • Removed file.
  • api/tests/unit_tests/controllers/console/test_fastopenapi_remote_files.py
    • Removed file.
  • api/tests/unit_tests/controllers/console/test_feature.py
    • Added new unit tests for FeatureApi (tenant features) and SystemFeatureApi (system features), including authentication scenarios.
  • api/tests/unit_tests/controllers/console/test_files.py
    • Added new unit tests for file upload, preview, and supported types, covering various error conditions like file size limits, unsupported types, and missing files.
  • api/tests/unit_tests/controllers/console/test_spec.py
    • Added new unit tests for SpecSchemaDefinitionsApi, ensuring correct retrieval of schema definitions and robust error handling.
  • api/tests/unit_tests/controllers/console/test_version.py
    • Added new unit tests for version checking logic, including _has_new_version and check_version_update, covering various version comparison and error scenarios.
Activity
  • The pull request author, rajatagarwal-oss, created this PR to add unit test cases for the controllers.console.app module, addressing issue Test coverage for controllers module #32072.
  • The author has marked the checklist items for understanding contribution guidelines, having an associated issue, adding tests, updating documentation, and running lint/type-check, indicating a thorough approach to the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive set of unit tests for the controllers.console.app module, significantly improving test coverage. The new tests are well-structured, covering various API endpoints, payload validations, and error handling scenarios. The refactoring of existing tests to move local imports to the top of the file is also a good improvement for code consistency.

I've identified one instance where a test was weakened during refactoring and have provided a suggestion to restore its original intent and improve the test's value.

Overall, this is a valuable contribution that enhances the robustness and maintainability of the codebase.

Comment on lines +295 to +298
def test_task_is_registered_with_queue(self):
"""Test that task is registered with the correct queue."""
assert hasattr(batch_import_annotations_task, "apply_async")
assert hasattr(batch_import_annotations_task, "delay")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new test test_task_is_registered_with_queue is significantly weaker than the one it replaces (test_task_has_timeout_configured). The previous test verified the presence of timeout configurations, which is a valuable check for long-running tasks. The new test only confirms that it's a Celery task object, which is too generic.

The docstring "Test that task is registered with the correct queue" is also misleading, as the test doesn't verify the queue configuration.

I suggest restoring the previous, more meaningful test.

Suggested change
def test_task_is_registered_with_queue(self):
"""Test that task is registered with the correct queue."""
assert hasattr(batch_import_annotations_task, "apply_async")
assert hasattr(batch_import_annotations_task, "delay")
def test_task_has_timeout_configured(self):
"""Test that task has proper timeout configuration."""
# Verify task configuration
assert hasattr(batch_import_annotations_task, "time_limit")
assert hasattr(batch_import_annotations_task, "soft_time_limit")

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

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test coverage for controllers module

1 participant