Skip to main content
Glama
cbcoutinho

Nextcloud MCP Server

by cbcoutinho
test_userinfo_routes.py2.15 kB
"""Unit tests for user info routes. Note: Most unit tests were removed as they relied on the old _get_user_info API. The new browser OAuth session-based implementation is covered by integration tests in tests/server/oauth/test_userinfo_integration.py which test the full OAuth flow with real browser sessions, token storage, and IdP interactions. These unit tests cover only the simple _query_idp_userinfo helper function. """ from unittest.mock import AsyncMock, Mock import pytest from nextcloud_mcp_server.auth.userinfo_routes import _query_idp_userinfo pytestmark = pytest.mark.unit async def test_query_idp_userinfo_success(mocker): """Test successful IdP userinfo query.""" mock_response = Mock() mock_response.json.return_value = { "sub": "alice", "email": "alice@example.com", "name": "Alice Smith", } mock_response.raise_for_status = Mock() # Mock the async context manager properly mock_client = AsyncMock() mock_client.get.return_value = mock_response mock_client.__aenter__.return_value = mock_client mock_client.__aexit__.return_value = None mocker.patch( "nextcloud_mcp_server.auth.userinfo_routes.httpx.AsyncClient", return_value=mock_client, ) result = await _query_idp_userinfo("test_token", "https://example.com/userinfo") assert result == { "sub": "alice", "email": "alice@example.com", "name": "Alice Smith", } mock_client.get.assert_called_once_with( "https://example.com/userinfo", headers={"Authorization": "Bearer test_token"}, ) async def test_query_idp_userinfo_failure(mocker): """Test IdP userinfo query failure handling.""" mock_client = AsyncMock() mock_client.get.side_effect = Exception("Network error") mock_client.__aenter__.return_value = mock_client mock_client.__aexit__.return_value = None mocker.patch( "nextcloud_mcp_server.auth.userinfo_routes.httpx.AsyncClient", return_value=mock_client, ) result = await _query_idp_userinfo("test_token", "https://example.com/userinfo") assert result is None

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cbcoutinho/nextcloud-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server