testing adjustments
This commit is contained in:
@@ -72,8 +72,8 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_list_basic(self, pages_endpoint, sample_page_data):
|
def test_list_basic(self, pages_endpoint, sample_page_data):
|
||||||
"""Test basic page listing."""
|
"""Test basic page listing."""
|
||||||
# Mock the GraphQL response
|
# Mock the GraphQL response structure that matches Wiki.js schema
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call list method
|
# Call list method
|
||||||
@@ -93,7 +93,7 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_list_with_parameters(self, pages_endpoint, sample_page_data):
|
def test_list_with_parameters(self, pages_endpoint, sample_page_data):
|
||||||
"""Test page listing with filter parameters."""
|
"""Test page listing with filter parameters."""
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call with parameters
|
# Call with parameters
|
||||||
@@ -157,7 +157,7 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_get_success(self, pages_endpoint, sample_page_data):
|
def test_get_success(self, pages_endpoint, sample_page_data):
|
||||||
"""Test getting a page by ID."""
|
"""Test getting a page by ID."""
|
||||||
mock_response = {"data": {"page": sample_page_data}}
|
mock_response = {"data": {"pages": {"single": sample_page_data}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call method
|
# Call method
|
||||||
@@ -221,7 +221,16 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_create_success(self, pages_endpoint, sample_page_create, sample_page_data):
|
def test_create_success(self, pages_endpoint, sample_page_create, sample_page_data):
|
||||||
"""Test creating a new page."""
|
"""Test creating a new page."""
|
||||||
mock_response = {"data": {"createPage": sample_page_data}}
|
mock_response = {
|
||||||
|
"data": {
|
||||||
|
"pages": {
|
||||||
|
"create": {
|
||||||
|
"responseResult": {"succeeded": True},
|
||||||
|
"page": sample_page_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call method
|
# Call method
|
||||||
@@ -246,7 +255,16 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_create_with_dict(self, pages_endpoint, sample_page_data):
|
def test_create_with_dict(self, pages_endpoint, sample_page_data):
|
||||||
"""Test creating a page with dict data."""
|
"""Test creating a page with dict data."""
|
||||||
mock_response = {"data": {"createPage": sample_page_data}}
|
mock_response = {
|
||||||
|
"data": {
|
||||||
|
"pages": {
|
||||||
|
"create": {
|
||||||
|
"responseResult": {"succeeded": True},
|
||||||
|
"page": sample_page_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
page_dict = {
|
page_dict = {
|
||||||
@@ -357,7 +375,7 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_search_success(self, pages_endpoint, sample_page_data):
|
def test_search_success(self, pages_endpoint, sample_page_data):
|
||||||
"""Test searching pages."""
|
"""Test searching pages."""
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call method
|
# Call method
|
||||||
@@ -385,7 +403,7 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_get_by_tags_match_all(self, pages_endpoint, sample_page_data):
|
def test_get_by_tags_match_all(self, pages_endpoint, sample_page_data):
|
||||||
"""Test getting pages by tags (match all)."""
|
"""Test getting pages by tags (match all)."""
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call method
|
# Call method
|
||||||
@@ -450,7 +468,7 @@ class TestPagesEndpoint:
|
|||||||
# Mock Page constructor to raise an exception
|
# Mock Page constructor to raise an exception
|
||||||
mock_page_class.side_effect = ValueError("Parsing error")
|
mock_page_class.side_effect = ValueError("Parsing error")
|
||||||
|
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
with pytest.raises(APIError, match="Failed to parse page data"):
|
with pytest.raises(APIError, match="Failed to parse page data"):
|
||||||
@@ -458,7 +476,7 @@ class TestPagesEndpoint:
|
|||||||
|
|
||||||
def test_graphql_query_structure(self, pages_endpoint, sample_page_data):
|
def test_graphql_query_structure(self, pages_endpoint, sample_page_data):
|
||||||
"""Test that GraphQL queries have correct structure."""
|
"""Test that GraphQL queries have correct structure."""
|
||||||
mock_response = {"data": {"pages": [sample_page_data]}}
|
mock_response = {"data": {"pages": {"list": [sample_page_data]}}}
|
||||||
pages_endpoint._post = Mock(return_value=mock_response)
|
pages_endpoint._post = Mock(return_value=mock_response)
|
||||||
|
|
||||||
# Call list method
|
# Call list method
|
||||||
@@ -469,8 +487,8 @@ class TestPagesEndpoint:
|
|||||||
query_data = call_args[1]["json_data"]
|
query_data = call_args[1]["json_data"]
|
||||||
|
|
||||||
assert "query" in query_data
|
assert "query" in query_data
|
||||||
assert "variables" in query_data
|
# variables key may or may not be present depending on whether parameters were passed
|
||||||
assert "pages(" in query_data["query"]
|
assert "list(" in query_data["query"] # Updated to match new GraphQL structure
|
||||||
assert "id" in query_data["query"]
|
assert "id" in query_data["query"]
|
||||||
assert "title" in query_data["query"]
|
assert "title" in query_data["query"]
|
||||||
assert "content" in query_data["query"]
|
assert "content" in query_data["query"]
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ class TestWikiJSClientIntegration:
|
|||||||
mock_response.ok = True
|
mock_response.ok = True
|
||||||
mock_response.json.return_value = {
|
mock_response.json.return_value = {
|
||||||
"data": {
|
"data": {
|
||||||
"pages": [
|
"pages": {
|
||||||
|
"list": [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"title": "Test Page",
|
"title": "Test Page",
|
||||||
@@ -46,6 +47,7 @@ class TestWikiJSClientIntegration:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mock_session.request.return_value = mock_response
|
mock_session.request.return_value = mock_response
|
||||||
|
|
||||||
# Create client
|
# Create client
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ class WikiJSClient:
|
|||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make HTTP request to Wiki.js API.
|
"""Make HTTP request to Wiki.js API.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -195,7 +195,7 @@ class WikiJSClient:
|
|||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
raise APIError(f"Request failed: {str(e)}") from e
|
raise APIError(f"Request failed: {str(e)}") from e
|
||||||
|
|
||||||
def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
|
def _handle_response(self, response: requests.Response) -> Any:
|
||||||
"""Handle HTTP response and extract data.
|
"""Handle HTTP response and extract data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class BaseEndpoint:
|
|||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make HTTP request through the client.
|
"""Make HTTP request through the client.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -54,7 +54,7 @@ class BaseEndpoint:
|
|||||||
|
|
||||||
def _get(
|
def _get(
|
||||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make GET request.
|
"""Make GET request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -73,7 +73,7 @@ class BaseEndpoint:
|
|||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make POST request.
|
"""Make POST request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -95,7 +95,7 @@ class BaseEndpoint:
|
|||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make PUT request.
|
"""Make PUT request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -113,7 +113,7 @@ class BaseEndpoint:
|
|||||||
|
|
||||||
def _delete(
|
def _delete(
|
||||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
||||||
) -> Dict[str, Any]:
|
) -> Any:
|
||||||
"""Make DELETE request.
|
"""Make DELETE request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -84,15 +84,24 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
if order_direction not in ["ASC", "DESC"]:
|
if order_direction not in ["ASC", "DESC"]:
|
||||||
raise ValidationError("order_direction must be ASC or DESC")
|
raise ValidationError("order_direction must be ASC or DESC")
|
||||||
|
|
||||||
# Build GraphQL query using actual Wiki.js schema
|
# Build GraphQL query with variables using actual Wiki.js schema
|
||||||
query = """
|
query = """
|
||||||
query {
|
query($limit: Int, $offset: Int, $search: String, $tags: [String], $locale: String, $authorId: Int, $orderBy: String, $orderDirection: String) {
|
||||||
pages {
|
pages {
|
||||||
list {
|
list(limit: $limit, offset: $offset, search: $search, tags: $tags, locale: $locale, authorId: $authorId, orderBy: $orderBy, orderDirection: $orderDirection) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
path
|
path
|
||||||
|
content
|
||||||
|
description
|
||||||
isPublished
|
isPublished
|
||||||
|
isPrivate
|
||||||
|
tags
|
||||||
|
locale
|
||||||
|
authorId
|
||||||
|
authorName
|
||||||
|
authorEmail
|
||||||
|
editor
|
||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
@@ -100,8 +109,31 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Make request (no variables needed for simple list query)
|
# Build variables object
|
||||||
response = self._post("/graphql", json_data={"query": query})
|
variables = {}
|
||||||
|
if limit is not None:
|
||||||
|
variables["limit"] = limit
|
||||||
|
if offset is not None:
|
||||||
|
variables["offset"] = offset
|
||||||
|
if search is not None:
|
||||||
|
variables["search"] = search
|
||||||
|
if tags is not None:
|
||||||
|
variables["tags"] = tags
|
||||||
|
if locale is not None:
|
||||||
|
variables["locale"] = locale
|
||||||
|
if author_id is not None:
|
||||||
|
variables["authorId"] = author_id
|
||||||
|
if order_by is not None:
|
||||||
|
variables["orderBy"] = order_by
|
||||||
|
if order_direction is not None:
|
||||||
|
variables["orderDirection"] = order_direction
|
||||||
|
|
||||||
|
# Make request with query and variables
|
||||||
|
json_data = {"query": query}
|
||||||
|
if variables:
|
||||||
|
json_data["variables"] = variables
|
||||||
|
|
||||||
|
response = self._post("/graphql", json_data=json_data)
|
||||||
|
|
||||||
# Parse response
|
# Parse response
|
||||||
if "errors" in response:
|
if "errors" in response:
|
||||||
@@ -277,9 +309,29 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
|
|
||||||
# Build GraphQL mutation using actual Wiki.js schema
|
# Build GraphQL mutation using actual Wiki.js schema
|
||||||
mutation = """
|
mutation = """
|
||||||
mutation($content: String!, $description: String!, $editor: String!, $isPublished: Boolean!, $isPrivate: Boolean!, $locale: String!, $path: String!, $tags: [String]!, $title: String!) {
|
mutation(
|
||||||
|
$content: String!,
|
||||||
|
$description: String!,
|
||||||
|
$editor: String!,
|
||||||
|
$isPublished: Boolean!,
|
||||||
|
$isPrivate: Boolean!,
|
||||||
|
$locale: String!,
|
||||||
|
$path: String!,
|
||||||
|
$tags: [String]!,
|
||||||
|
$title: String!
|
||||||
|
) {
|
||||||
pages {
|
pages {
|
||||||
create(content: $content, description: $description, editor: $editor, isPublished: $isPublished, isPrivate: $isPrivate, locale: $locale, path: $path, tags: $tags, title: $title) {
|
create(
|
||||||
|
content: $content,
|
||||||
|
description: $description,
|
||||||
|
editor: $editor,
|
||||||
|
isPublished: $isPublished,
|
||||||
|
isPrivate: $isPrivate,
|
||||||
|
locale: $locale,
|
||||||
|
path: $path,
|
||||||
|
tags: $tags,
|
||||||
|
title: $title
|
||||||
|
) {
|
||||||
responseResult {
|
responseResult {
|
||||||
succeeded
|
succeeded
|
||||||
errorCode
|
errorCode
|
||||||
@@ -381,7 +433,15 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
|
|
||||||
# Build GraphQL mutation
|
# Build GraphQL mutation
|
||||||
mutation = """
|
mutation = """
|
||||||
mutation($id: Int!, $title: String, $content: String, $description: String, $isPublished: Boolean, $isPrivate: Boolean, $tags: [String]) {
|
mutation(
|
||||||
|
$id: Int!,
|
||||||
|
$title: String,
|
||||||
|
$content: String,
|
||||||
|
$description: String,
|
||||||
|
$isPublished: Boolean,
|
||||||
|
$isPrivate: Boolean,
|
||||||
|
$tags: [String]
|
||||||
|
) {
|
||||||
updatePage(
|
updatePage(
|
||||||
id: $id,
|
id: $id,
|
||||||
title: $title,
|
title: $title,
|
||||||
@@ -602,7 +662,7 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
# Handle tags - convert from Wiki.js format
|
# Handle tags - convert from Wiki.js format
|
||||||
if "tags" in page_data:
|
if "tags" in page_data:
|
||||||
if isinstance(page_data["tags"], list):
|
if isinstance(page_data["tags"], list):
|
||||||
# Handle both formats: ["tag1", "tag2"] or [{"tag": "tag1"}, {"tag": "tag2"}]
|
# Handle both formats: ["tag1", "tag2"] or [{"tag": "tag1"}]
|
||||||
tags = []
|
tags = []
|
||||||
for tag in page_data["tags"]:
|
for tag in page_data["tags"]:
|
||||||
if isinstance(tag, dict) and "tag" in tag:
|
if isinstance(tag, dict) and "tag" in tag:
|
||||||
|
|||||||
Reference in New Issue
Block a user