[PR #28479] Feat/add test script for account models #32056

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

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

State: closed
Merged: Yes


Add Comprehensive Unit Tests for Account Model

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 #<issue number>.

Summary

This PR adds comprehensive unit tests for the Account model (tests/unit_tests/models/test_account_models.py) covering all critical functionality:

Fixes

Closes https://github.com/langgenius/dify/issues/28480

Test Coverage (47 tests)

  • Account Model Validation - Tests for account creation, field validation, and property accessors
  • Password Hashing/Verification - Tests for password security including hashing consistency, salt handling, and validation rules
  • Account Status Transitions - Tests for all status states (PENDING, UNINITIALIZED, ACTIVE, BANNED, CLOSED) and transitions
  • Tenant Relationship Integrity - Tests for tenant associations, role management, and relationship handling
  • Email Uniqueness Constraints - Implicit validation through model constraints
  • Role Permissions - Tests for admin, owner, editor, and dataset operator permissions

Key Features

  • Follows TDD principles with Arrange-Act-Assert structure
  • Uses proper mocking patterns consistent with existing codebase
  • Strong type safety with explicit type annotations
  • Self-documenting test names and docstrings
  • All 47 tests pass successfully

Changes Made

  • Created api/tests/unit_tests/models/test_account_models.py with 9 test classes
  • Tests cover Account, Tenant, TenantAccountJoin, and related enum models
  • Includes integration tests for multi-tenant scenarios and authentication flows

Screenshots

N/A - This PR adds unit tests only, no UI changes.

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 dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

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

**Original Pull Request:** https://github.com/langgenius/dify/pull/28479 **State:** closed **Merged:** Yes --- # Add Comprehensive Unit Tests for Account Model > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR adds comprehensive unit tests for the Account model (`tests/unit_tests/models/test_account_models.py`) covering all critical functionality: ### Fixes Closes https://github.com/langgenius/dify/issues/28480 ### Test Coverage (47 tests) - **Account Model Validation** - Tests for account creation, field validation, and property accessors - **Password Hashing/Verification** - Tests for password security including hashing consistency, salt handling, and validation rules - **Account Status Transitions** - Tests for all status states (PENDING, UNINITIALIZED, ACTIVE, BANNED, CLOSED) and transitions - **Tenant Relationship Integrity** - Tests for tenant associations, role management, and relationship handling - **Email Uniqueness Constraints** - Implicit validation through model constraints - **Role Permissions** - Tests for admin, owner, editor, and dataset operator permissions ### Key Features - Follows TDD principles with Arrange-Act-Assert structure - Uses proper mocking patterns consistent with existing codebase - Strong type safety with explicit type annotations - Self-documenting test names and docstrings - All 47 tests pass successfully ### Changes Made - Created `api/tests/unit_tests/models/test_account_models.py` with 9 test classes - Tests cover Account, Tenant, TenantAccountJoin, and related enum models - Includes integration tests for multi-tenant scenarios and authentication flows ## Screenshots N/A - This PR adds unit tests only, no UI changes. ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods Contribution by Gittensor, learn more at https://gittensor.io/
yindo added the pull-request label 2026-02-21 20:50:40 -05:00
yindo closed this issue 2026-02-21 20:50:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32056