Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.1 KB
Raw Blame
from unittest.mock import patch

import pytest

from services.enterprise.app_permitted_service import list_permitted_apps
from services.entities.app_entities import PermittedAppsPage
from services.errors.app import PermittedAppsUnavailableError
from services.errors.enterprise import EnterpriseAPIError

WRAPPER = "services.enterprise.app_permitted_service.EnterpriseService.WebAppAuth.list_externally_accessible_apps"


def test_list_permitted_apps_decodes_camelcase_response() -> None:
    fake_body = {
        "data": [{"appId": "a"}, {"appId": "b"}],
        "total": 2,
        "hasMore": False,
    }
    with patch(WRAPPER, return_value=fake_body) as m:
        page = list_permitted_apps(page=1, limit=10)

    assert isinstance(page, PermittedAppsPage)
    assert page.total == 2
    assert page.has_more is False
    assert page.app_ids == ["a", "b"]
    m.assert_called_once_with(page=1, limit=10, mode=None, name=None)


def test_list_permitted_apps_passes_filters_to_wrapper() -> None:
    fake_body: dict[str, object] = {"data": [], "total": 0, "hasMore": False}
    with patch(WRAPPER, return_value=fake_body) as m:
        list_permitted_apps(page=2, limit=5, mode="workflow", name="alpha")

    m.assert_called_once_with(page=2, limit=5, mode="workflow", name="alpha")


def test_list_permitted_apps_503_on_ee_error() -> None:
    with patch(WRAPPER, side_effect=EnterpriseAPIError("boom", status_code=500)):
        with pytest.raises(PermittedAppsUnavailableError):
            list_permitted_apps(page=1, limit=10)


def test_list_permitted_apps_503_on_status_error() -> None:
    with patch(WRAPPER, side_effect=EnterpriseAPIError("bad key", status_code=401)):
        with pytest.raises(PermittedAppsUnavailableError):
            list_permitted_apps(page=1, limit=10)


def test_list_permitted_apps_handles_empty_response() -> None:
    fake_body: dict[str, object] = {"data": [], "total": 0, "hasMore": False}
    with patch(WRAPPER, return_value=fake_body):
        page = list_permitted_apps(page=1, limit=10)
    assert page.app_ids == []
    assert page.total == 0
    assert page.has_more is False