mirror of
https://github.com/langgenius/dify.git
synced 2026-09-19 10:11:30 +08:00
test: migrate load balancing account ORM model to real entity (#40644)
This commit is contained in:
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
import builtins
|
||||
import importlib
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import ANY, MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -19,7 +18,7 @@ from graphon.model_runtime.errors.validate import CredentialsValidateFailedError
|
||||
if not hasattr(builtins, "MethodView"):
|
||||
builtins.MethodView = MethodView # type: ignore[attr-defined]
|
||||
|
||||
from models.account import TenantAccountRole
|
||||
from models.account import Account, TenantAccountRole
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -57,12 +56,15 @@ def load_balancing_module(monkeypatch: pytest.MonkeyPatch):
|
||||
return module
|
||||
|
||||
|
||||
def _mock_user(role: TenantAccountRole) -> SimpleNamespace:
|
||||
return SimpleNamespace(current_role=role)
|
||||
def _account(role: TenantAccountRole) -> Account:
|
||||
account = Account(name="Owner", email="owner@example.com")
|
||||
account.id = "account-1"
|
||||
account.role = role
|
||||
return account
|
||||
|
||||
|
||||
def _prepare_context(module, monkeypatch: pytest.MonkeyPatch, role=TenantAccountRole.OWNER):
|
||||
user = _mock_user(role)
|
||||
user = _account(role)
|
||||
from controllers.console import wraps
|
||||
|
||||
monkeypatch.setattr(wraps, "current_account_with_tenant", lambda: (user, "tenant-123"))
|
||||
|
||||
Reference in New Issue
Block a user