Some checks failed
CI / test (push) Failing after 12s
- Fixed import sorting in cli.py, __main__.py, detectors/__init__.py, base.py, python.py, rust.py, openapi.py, models/__init__.py - Removed unused imports (sys, asyncio, Observer, Text, Parameter, ParameterIn, HTTPMethod, DocConfig, List, Optional) - Removed trailing whitespace from blank lines - Split lines exceeding 100 characters - Added missing __init__ docstrings in generators and static/templates packages
137 lines
3.9 KiB
Python
137 lines
3.9 KiB
Python
{"""Integration tests for documentation generation."""
|
|
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from docgen.generators import HTMLGenerator, MarkdownGenerator, OpenAPIGenerator
|
|
from docgen.models import DocConfig, Endpoint, HTTPMethod, Parameter, ParameterIn
|
|
|
|
|
|
class TestHTMLGeneration:
|
|
"""Tests for HTML documentation generation."""
|
|
|
|
def test_html_generator_basic(self):
|
|
"""Test basic HTML generation."""
|
|
endpoints = [
|
|
Endpoint(
|
|
path="/api/users",
|
|
method=HTTPMethod.GET,
|
|
summary="Get users",
|
|
),
|
|
Endpoint(
|
|
path="/api/users",
|
|
method=HTTPMethod.POST,
|
|
summary="Create user",
|
|
),
|
|
]
|
|
|
|
config = DocConfig(
|
|
title="Test API",
|
|
description="A test API",
|
|
version="1.0.0",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
generator = HTMLGenerator(config)
|
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
|
|
|
assert output_path.exists()
|
|
assert output_path.name == "index.html"
|
|
|
|
content = output_path.read_text()
|
|
assert "Test API" in content
|
|
assert "/api/users" in content
|
|
|
|
def test_html_generator_grouped_endpoints(self):
|
|
"""Test endpoint grouping in HTML."""
|
|
endpoints = [
|
|
Endpoint(
|
|
path="/users",
|
|
method=HTTPMethod.GET,
|
|
tags=["users"],
|
|
),
|
|
Endpoint(
|
|
path="/items",
|
|
method=HTTPMethod.GET,
|
|
tags=["items"],
|
|
),
|
|
]
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
generator = HTMLGenerator(DocConfig())
|
|
generator.generate(endpoints, Path(tmpdir))
|
|
|
|
output_static = Path(tmpdir) / "static"
|
|
assert output_static.exists()
|
|
|
|
|
|
class TestMarkdownGeneration:
|
|
"""Tests for Markdown documentation generation."""
|
|
|
|
def test_markdown_generator_basic(self):
|
|
"""Test basic Markdown generation."""
|
|
endpoints = [
|
|
Endpoint(
|
|
path="/api/users",
|
|
method=HTTPMethod.GET,
|
|
summary="Get all users",
|
|
),
|
|
]
|
|
|
|
config = DocConfig(
|
|
title="My API",
|
|
description="API documentation",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
generator = MarkdownGenerator(config)
|
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
|
|
|
assert output_path.exists()
|
|
assert output_path.name == "README.md"
|
|
|
|
content = output_path.read_text()
|
|
assert "# My API" in content
|
|
assert "GET" in content
|
|
assert "/api/users" in content
|
|
|
|
|
|
class TestOpenAPIGeneration:
|
|
"""Tests for OpenAPI specification generation."""
|
|
|
|
def test_openapi_generator_basic(self):
|
|
"""Test basic OpenAPI generation."""
|
|
param = Parameter(
|
|
name="id",
|
|
type="integer",
|
|
required=True,
|
|
location=ParameterIn.PATH,
|
|
)
|
|
|
|
endpoints = [
|
|
Endpoint(
|
|
path="/users/{id}",
|
|
method=HTTPMethod.GET,
|
|
summary="Get user by ID",
|
|
parameters=[param],
|
|
),
|
|
]
|
|
|
|
config = DocConfig(
|
|
title="Test API",
|
|
version="1.0.0",
|
|
)
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
generator = OpenAPIGenerator(config)
|
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
|
|
|
assert output_path.exists()
|
|
assert output_path.name == "openapi.json"
|
|
|
|
spec = json.loads(output_path.read_text())
|
|
assert spec["openapi"] == "3.0.3"
|
|
assert spec["info"]["title"] == "Test API"
|
|
assert "/users/{id}" in spec["paths"]
|