- 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
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
"""Integration tests for documentation generation."""
|
||||
{"""Integration tests for documentation generation."""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import tempfile
|
||||
import os
|
||||
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."""
|
||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
||||
from docgen.generators import HTMLGenerator
|
||||
|
||||
endpoints = [
|
||||
Endpoint(
|
||||
path="/api/users",
|
||||
@@ -26,29 +25,26 @@ class TestHTMLGeneration:
|
||||
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."""
|
||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
||||
from docgen.generators import HTMLGenerator
|
||||
|
||||
endpoints = [
|
||||
Endpoint(
|
||||
path="/users",
|
||||
@@ -61,11 +57,11 @@ class TestHTMLGeneration:
|
||||
tags=["items"],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
generator = HTMLGenerator(DocConfig())
|
||||
generator.generate(endpoints, Path(tmpdir))
|
||||
|
||||
|
||||
output_static = Path(tmpdir) / "static"
|
||||
assert output_static.exists()
|
||||
|
||||
@@ -75,9 +71,6 @@ class TestMarkdownGeneration:
|
||||
|
||||
def test_markdown_generator_basic(self):
|
||||
"""Test basic Markdown generation."""
|
||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
||||
from docgen.generators import MarkdownGenerator
|
||||
|
||||
endpoints = [
|
||||
Endpoint(
|
||||
path="/api/users",
|
||||
@@ -85,19 +78,19 @@ class TestMarkdownGeneration:
|
||||
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
|
||||
@@ -109,17 +102,13 @@ class TestOpenAPIGeneration:
|
||||
|
||||
def test_openapi_generator_basic(self):
|
||||
"""Test basic OpenAPI generation."""
|
||||
from docgen.models import Endpoint, HTTPMethod, DocConfig, Parameter, ParameterIn
|
||||
from docgen.generators import OpenAPIGenerator
|
||||
import json
|
||||
|
||||
param = Parameter(
|
||||
name="id",
|
||||
type="integer",
|
||||
required=True,
|
||||
location=ParameterIn.PATH,
|
||||
)
|
||||
|
||||
|
||||
endpoints = [
|
||||
Endpoint(
|
||||
path="/users/{id}",
|
||||
@@ -128,19 +117,19 @@ class TestOpenAPIGeneration:
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user