Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/auto-code-review.yml

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dev = [
"pytest-cov>=4.0.0",
"httpx>=0.27.0",
"ruff>=0.4.0",
"tomli>=2.0.0; python_version < '3.11'",
]

[project.urls]
Expand Down
4 changes: 2 additions & 2 deletions src/apighost/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import click
import json
import re
import sys
Expand Down Expand Up @@ -374,7 +373,8 @@ def scenario_delete(name) -> None:
"--output", "-o", default=None, help="Output path for the generated scenario"
)
@click.option("--name", "-n", default=None, help="Scenario name")
def generate(spec, output, name) -> None:
@click.option("--max-endpoints", "-m", type=int, default=0, help="Maximum number of endpoints to process (0 = all)")
def generate(spec, output, name, max_endpoints) -> None:
"""Generate sample data and create a scenario from an OpenAPI spec."""
api_spec = parse_spec(spec)
scenario_name = name or f"generated-{api_spec.title.replace(' ', '-').lower()}"
Expand Down
1 change: 0 additions & 1 deletion src/apighost/faker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import random
from collections.abc import Callable
from faker import Faker
from typing import Any

from faker import Faker
Expand Down
7 changes: 6 additions & 1 deletion src/apighost/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import logging
import random
import re
import time
from collections.abc import Callable
from flask import Flask, Response, jsonify, request
from typing import Any

from flask import Flask, Response, jsonify, request
Expand Down Expand Up @@ -128,6 +128,11 @@ def _apighost_health() -> Any:

def make_handler(endpoint: Endpoint, scenario: Scenario | None) -> Callable:
def handler(**path_params) -> Any:
# Apply latency if configured
if latency_range[1] > 0:
delay = random.uniform(*latency_range)
time.sleep(delay)

# Capture request info for recording
req_method = request.method
req_path = request.path
Expand Down
16 changes: 11 additions & 5 deletions tests/test_edge_cases_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

from __future__ import annotations

import sys
from pathlib import Path

import tomllib
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib # type: ignore[import-not-found]
from click.testing import CliRunner

from apighost.cli import cli
Expand All @@ -32,11 +36,13 @@ def test_package_data_includes_py_typed(self):
with open(pyproject, "rb") as f:
data = tomllib.load(f)
pkg_data = data.get("tool", {}).get("setuptools", {}).get("package-data", {})
assert "apighost" in pkg_data, (
"Expected [tool.setuptools.package-data] section for 'apighost'"
assert any(k in pkg_data for k in ("apighost", "*")), (
"Expected [tool.setuptools.package-data] section for 'apighost' or '*'"
)
assert "py.typed" in pkg_data["apighost"], (
f"Expected 'py.typed' in package-data, got {pkg_data['apighost']}"
# The key may be "apighost" or "*" — check whichever exists
pkg_key = next(k for k in ("apighost", "*") if k in pkg_data)
assert "py.typed" in pkg_data[pkg_key], (
f"Expected 'py.typed' in package-data, got {pkg_data[pkg_key]}"
)

def test_ruff_known_first_party(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parser_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import json
import tempfile
from pathlib import Path

from apighost.parser import (
_extract_example,
_infer_type,
Expand All @@ -13,7 +15,6 @@
load_spec,
parse_spec,
)
from pathlib import Path

# --- _resolve_ref edge cases ---

Expand Down
6 changes: 3 additions & 3 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ def test_extract_path_params_no_match():


def test_make_response_with_dict():
"""_make_response with dict body returns jsonify tuple (covers line 37)."""
"""_make_response with dict body returns jsonify Response (covers line 37)."""
from flask import Flask

from apighost.server import _make_response

app = Flask(__name__)
with app.app_context():
resp = _make_response(201, {"id": 1, "name": "test"})
assert resp[1] == 201
data = json.loads(resp[0].get_data(as_text=True))
assert resp.status_code == 201
data = json.loads(resp.get_data(as_text=True))
assert data["name"] == "test"


Expand Down
Loading