test: Replace unittest class with simple tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""Interactive integration tests for OAuth authentication."""
|
"""Interactive integration tests for OAuth authentication."""
|
||||||
|
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|||||||
@@ -9,51 +9,46 @@ logger = logging.getLogger(__name__)
|
|||||||
pytestmark = [pytest.mark.integration, pytest.mark.oauth]
|
pytestmark = [pytest.mark.integration, pytest.mark.oauth]
|
||||||
|
|
||||||
|
|
||||||
class TestOAuthPlaywright:
|
async def test_playwright_oauth_token_acquisition(playwright_oauth_token: str):
|
||||||
"""Test automated Playwright OAuth authentication."""
|
"""Test that Playwright can acquire an OAuth token automatically."""
|
||||||
|
assert playwright_oauth_token is not None
|
||||||
|
assert isinstance(playwright_oauth_token, str)
|
||||||
|
assert len(playwright_oauth_token) > 0
|
||||||
|
logger.info(
|
||||||
|
f"Successfully acquired OAuth token via Playwright: {playwright_oauth_token[:20]}..."
|
||||||
|
)
|
||||||
|
|
||||||
async def test_playwright_oauth_token_acquisition(
|
|
||||||
self, playwright_oauth_token: str
|
|
||||||
):
|
|
||||||
"""Test that Playwright can acquire an OAuth token automatically."""
|
|
||||||
assert playwright_oauth_token is not None
|
|
||||||
assert isinstance(playwright_oauth_token, str)
|
|
||||||
assert len(playwright_oauth_token) > 0
|
|
||||||
logger.info(
|
|
||||||
f"Successfully acquired OAuth token via Playwright: {playwright_oauth_token[:20]}..."
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_oauth_client_with_playwright_flow(self, nc_oauth_client_playwright):
|
async def test_oauth_client_with_playwright_flow(nc_oauth_client_playwright):
|
||||||
"""Test that OAuth client created via Playwright flow can access Nextcloud APIs."""
|
"""Test that OAuth client created via Playwright flow can access Nextcloud APIs."""
|
||||||
# Test 1: Check capabilities
|
# Test 1: Check capabilities
|
||||||
capabilities = await nc_oauth_client_playwright.capabilities()
|
capabilities = await nc_oauth_client_playwright.capabilities()
|
||||||
assert capabilities is not None
|
assert capabilities is not None
|
||||||
logger.info("OAuth client (Playwright) successfully fetched capabilities")
|
logger.info("OAuth client (Playwright) successfully fetched capabilities")
|
||||||
|
|
||||||
# Test 2: List notes
|
# Test 2: List notes
|
||||||
notes = await nc_oauth_client_playwright.notes.get_all_notes()
|
notes = await nc_oauth_client_playwright.notes.get_all_notes()
|
||||||
assert isinstance(notes, list)
|
assert isinstance(notes, list)
|
||||||
logger.info(f"OAuth client (Playwright) successfully listed {len(notes)} notes")
|
logger.info(f"OAuth client (Playwright) successfully listed {len(notes)} notes")
|
||||||
|
|
||||||
async def test_mcp_oauth_client_with_playwright(
|
|
||||||
self, nc_mcp_oauth_client_playwright
|
|
||||||
):
|
|
||||||
"""Test that MCP OAuth client via Playwright can execute tools."""
|
|
||||||
import json
|
|
||||||
|
|
||||||
# Test: Execute the 'nc_notes_search_notes' tool
|
async def test_mcp_oauth_client_with_playwright(nc_mcp_oauth_client_playwright):
|
||||||
result = await nc_mcp_oauth_client_playwright.call_tool(
|
"""Test that MCP OAuth client via Playwright can execute tools."""
|
||||||
"nc_notes_search_notes", arguments={"query": ""}
|
import json
|
||||||
)
|
|
||||||
|
|
||||||
assert result.isError is False, f"Tool execution failed: {result.content}"
|
# Test: Execute the 'nc_notes_search_notes' tool
|
||||||
assert result.content is not None
|
result = await nc_mcp_oauth_client_playwright.call_tool(
|
||||||
response_data = json.loads(result.content[0].text)
|
"nc_notes_search_notes", arguments={"query": ""}
|
||||||
|
)
|
||||||
|
|
||||||
# The search response should have a 'results' field containing the list
|
assert result.isError is False, f"Tool execution failed: {result.content}"
|
||||||
assert "results" in response_data
|
assert result.content is not None
|
||||||
assert isinstance(response_data["results"], list)
|
response_data = json.loads(result.content[0].text)
|
||||||
|
|
||||||
logger.info(
|
# The search response should have a 'results' field containing the list
|
||||||
f"Successfully executed 'nc_notes_search_notes' tool on Playwright OAuth MCP server and got {len(response_data['results'])} notes."
|
assert "results" in response_data
|
||||||
)
|
assert isinstance(response_data["results"], list)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Successfully executed 'nc_notes_search_notes' tool on Playwright OAuth MCP server and got {len(response_data['results'])} notes."
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user