- 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 tempfile
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from docgen.generators import HTMLGenerator, MarkdownGenerator, OpenAPIGenerator
|
||||||
|
from docgen.models import DocConfig, Endpoint, HTTPMethod, Parameter, ParameterIn
|
||||||
|
|
||||||
|
|
||||||
class TestHTMLGeneration:
|
class TestHTMLGeneration:
|
||||||
"""Tests for HTML documentation generation."""
|
"""Tests for HTML documentation generation."""
|
||||||
|
|
||||||
def test_html_generator_basic(self):
|
def test_html_generator_basic(self):
|
||||||
"""Test basic HTML generation."""
|
"""Test basic HTML generation."""
|
||||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
|
||||||
from docgen.generators import HTMLGenerator
|
|
||||||
|
|
||||||
endpoints = [
|
endpoints = [
|
||||||
Endpoint(
|
Endpoint(
|
||||||
path="/api/users",
|
path="/api/users",
|
||||||
@@ -26,29 +25,26 @@ class TestHTMLGeneration:
|
|||||||
summary="Create user",
|
summary="Create user",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
config = DocConfig(
|
config = DocConfig(
|
||||||
title="Test API",
|
title="Test API",
|
||||||
description="A test API",
|
description="A test API",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
generator = HTMLGenerator(config)
|
generator = HTMLGenerator(config)
|
||||||
output_path = generator.generate(endpoints, Path(tmpdir))
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
||||||
|
|
||||||
assert output_path.exists()
|
assert output_path.exists()
|
||||||
assert output_path.name == "index.html"
|
assert output_path.name == "index.html"
|
||||||
|
|
||||||
content = output_path.read_text()
|
content = output_path.read_text()
|
||||||
assert "Test API" in content
|
assert "Test API" in content
|
||||||
assert "/api/users" in content
|
assert "/api/users" in content
|
||||||
|
|
||||||
def test_html_generator_grouped_endpoints(self):
|
def test_html_generator_grouped_endpoints(self):
|
||||||
"""Test endpoint grouping in HTML."""
|
"""Test endpoint grouping in HTML."""
|
||||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
|
||||||
from docgen.generators import HTMLGenerator
|
|
||||||
|
|
||||||
endpoints = [
|
endpoints = [
|
||||||
Endpoint(
|
Endpoint(
|
||||||
path="/users",
|
path="/users",
|
||||||
@@ -61,11 +57,11 @@ class TestHTMLGeneration:
|
|||||||
tags=["items"],
|
tags=["items"],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
generator = HTMLGenerator(DocConfig())
|
generator = HTMLGenerator(DocConfig())
|
||||||
generator.generate(endpoints, Path(tmpdir))
|
generator.generate(endpoints, Path(tmpdir))
|
||||||
|
|
||||||
output_static = Path(tmpdir) / "static"
|
output_static = Path(tmpdir) / "static"
|
||||||
assert output_static.exists()
|
assert output_static.exists()
|
||||||
|
|
||||||
@@ -75,9 +71,6 @@ class TestMarkdownGeneration:
|
|||||||
|
|
||||||
def test_markdown_generator_basic(self):
|
def test_markdown_generator_basic(self):
|
||||||
"""Test basic Markdown generation."""
|
"""Test basic Markdown generation."""
|
||||||
from docgen.models import Endpoint, HTTPMethod, DocConfig
|
|
||||||
from docgen.generators import MarkdownGenerator
|
|
||||||
|
|
||||||
endpoints = [
|
endpoints = [
|
||||||
Endpoint(
|
Endpoint(
|
||||||
path="/api/users",
|
path="/api/users",
|
||||||
@@ -85,19 +78,19 @@ class TestMarkdownGeneration:
|
|||||||
summary="Get all users",
|
summary="Get all users",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
config = DocConfig(
|
config = DocConfig(
|
||||||
title="My API",
|
title="My API",
|
||||||
description="API documentation",
|
description="API documentation",
|
||||||
)
|
)
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
generator = MarkdownGenerator(config)
|
generator = MarkdownGenerator(config)
|
||||||
output_path = generator.generate(endpoints, Path(tmpdir))
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
||||||
|
|
||||||
assert output_path.exists()
|
assert output_path.exists()
|
||||||
assert output_path.name == "README.md"
|
assert output_path.name == "README.md"
|
||||||
|
|
||||||
content = output_path.read_text()
|
content = output_path.read_text()
|
||||||
assert "# My API" in content
|
assert "# My API" in content
|
||||||
assert "GET" in content
|
assert "GET" in content
|
||||||
@@ -109,17 +102,13 @@ class TestOpenAPIGeneration:
|
|||||||
|
|
||||||
def test_openapi_generator_basic(self):
|
def test_openapi_generator_basic(self):
|
||||||
"""Test basic OpenAPI generation."""
|
"""Test basic OpenAPI generation."""
|
||||||
from docgen.models import Endpoint, HTTPMethod, DocConfig, Parameter, ParameterIn
|
|
||||||
from docgen.generators import OpenAPIGenerator
|
|
||||||
import json
|
|
||||||
|
|
||||||
param = Parameter(
|
param = Parameter(
|
||||||
name="id",
|
name="id",
|
||||||
type="integer",
|
type="integer",
|
||||||
required=True,
|
required=True,
|
||||||
location=ParameterIn.PATH,
|
location=ParameterIn.PATH,
|
||||||
)
|
)
|
||||||
|
|
||||||
endpoints = [
|
endpoints = [
|
||||||
Endpoint(
|
Endpoint(
|
||||||
path="/users/{id}",
|
path="/users/{id}",
|
||||||
@@ -128,19 +117,19 @@ class TestOpenAPIGeneration:
|
|||||||
parameters=[param],
|
parameters=[param],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
config = DocConfig(
|
config = DocConfig(
|
||||||
title="Test API",
|
title="Test API",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
generator = OpenAPIGenerator(config)
|
generator = OpenAPIGenerator(config)
|
||||||
output_path = generator.generate(endpoints, Path(tmpdir))
|
output_path = generator.generate(endpoints, Path(tmpdir))
|
||||||
|
|
||||||
assert output_path.exists()
|
assert output_path.exists()
|
||||||
assert output_path.name == "openapi.json"
|
assert output_path.name == "openapi.json"
|
||||||
|
|
||||||
spec = json.loads(output_path.read_text())
|
spec = json.loads(output_path.read_text())
|
||||||
assert spec["openapi"] == "3.0.3"
|
assert spec["openapi"] == "3.0.3"
|
||||||
assert spec["info"]["title"] == "Test API"
|
assert spec["info"]["title"] == "Test API"
|
||||||
|
|||||||
Reference in New Issue
Block a user