Initial commit: add Gitea PyPI publish workflow
This commit is contained in:
55
tests/test_wiki.py
Normal file
55
tests/test_wiki.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Tests for the DokuWiki client."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
|
||||
from conduit_client import AsyncConduitClient, ConduitClient
|
||||
from conduit_client.models.wiki import WriteWikiPageRequest
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_raw(api_key: str) -> None:
|
||||
route = respx.get("https://api.example.com/wiki/pages/foo%3Abar/raw").mock(
|
||||
return_value=Response(200, json={"id": "foo:bar", "text": "hello"})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.wiki.get_raw("foo:bar")
|
||||
assert result.text == "hello"
|
||||
assert route.calls[0].request.url.path == "/wiki/pages/foo:bar/raw"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_write(api_key: str) -> None:
|
||||
route = respx.put("https://api.example.com/wiki/pages/foo%3Abar").mock(
|
||||
return_value=Response(200, json={"id": "foo:bar", "url": "https://wiki.example.com/foo:bar", "verified": True})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.wiki.write(
|
||||
"foo:bar",
|
||||
WriteWikiPageRequest(text="new content", summary="update", verify=False),
|
||||
)
|
||||
assert result.url == "https://wiki.example.com/foo:bar"
|
||||
assert json.loads(route.calls[0].request.content) == {
|
||||
"text": "new content",
|
||||
"summary": "update",
|
||||
"verify": False,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_async_write(api_key: str) -> None:
|
||||
respx.put("https://api.example.com/wiki/pages/foo%3Abar").mock(
|
||||
return_value=Response(200, json={"id": "foo:bar", "url": "https://wiki.example.com/foo:bar", "verified": True})
|
||||
)
|
||||
async with AsyncConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = await client.wiki.write(
|
||||
"foo:bar",
|
||||
WriteWikiPageRequest(text="new content"),
|
||||
)
|
||||
assert result.verified is True
|
||||
Reference in New Issue
Block a user