api-testing
БесплатноБез исполняемых скриптовНе проверенTest FastAPI endpoints with pytest and generate API documentation. Use when creating new APIs or verifying existing endpoints work correctly.
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
You help test FastAPI endpoints for the QA Team Portal backend using pytest and manual testing tools.
When to Use This Skill
- Testing new API endpoints after creation
- Verifying authentication/authorization works
- Testing CRUD operations
- Checking error handling and validation
- Load/stress testing APIs
- Generating API documentation examples
Testing Approaches
1. Automated Testing with Pytest
Unit Tests (Fast, Isolated)
# tests/unit/test_team_service.py
import pytest
from app.services.team_service import TeamService
def test_validate_team_member_data():
service = TeamService()
data = {"name": "John Doe", "role": "QA Lead"}
assert service.validate(data) is True
def test_validate_rejects_invalid_email():
service = TeamService()
data = {"name": "John", "email": "invalid"}
with pytest.raises(ValueError):
service.validate(data)
Integration Tests (Full API Flow)
# tests/integration/test_api_team_members.py
import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_get_team_members():
response = client.get("/api/v1/team-members")
assert response.status_code == 200
assert isinstance(response.json(), list)
def test_create_team_member_requires_auth():
data = {"name": "John Doe", "role": "QA Lead"}
response = client.post("/api/v1/team-members", json=data)
assert response.status_code == 401
def test_create_team_member_with_auth(admin_token):
headers = {"Authorization": f"Bearer {admin_token}"}
data = {
"name": "John Doe",
"role": "QA Lead",
"email": "[email protected]"
}
response = client.post("/api/v1/team-members", json=data, headers=headers)
assert response.status_code == 201
assert response.json()["name"] == "John Doe"
def test_update_team_member(admin_token, test_team_member):
headers = {"Authorization": f"Bearer {admin_token}"}
data = {"name": "Jane Doe"}
response = client.put(
f"/api/v1/team-members/{test_team_member.id}",
json=data,
headers=headers
)
assert response.status_code == 200
assert response.json()["name"] == "Jane Doe"
def test_delete_team_member(admin_token, test_team_member):
headers = {"Authorization": f"Bearer {admin_token}"}
response = client.delete(
f"/api/v1/team-members/{test_team_member.id}",
headers=headers
)
assert response.status_code == 204
Pytest Fixtures
# tests/conftest.py
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.main import app
from app.db.base import Base
from app.api.deps import get_db
# Test database
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
TestingSessionLocal = sessionmaker(bind=engine)
@pytest.fixture(scope="function")
def db():
Base.metadata.create_all(bind=engine)
db = TestingSessionLocal()
try:
yield db
finally:
db.close()
Base.metadata.drop_all(bind=engine)
@pytest.fixture
def client(db):
def override_get_db():
try:
yield db
finally:
db.close()
app.dependency_overrides[get_db] = override_get_db
return TestClient(app)
@pytest.fixture
def admin_token(client):
response = client.post("/api/v1/auth/login", json={
"email": "[email protected]",
"password": "testpass123"
})
return response.json()["access_token"]
@pytest.fixture
def test_team_member(db):
from app.models.team_member import TeamMember
member = TeamMember(
name="Test User",
role="QA Engineer",
email="[email protected]"
)
db.add(member)
db.commit()
db.refresh(member)
return member
2. Manual Testing with curl
# Health check
curl http://localhost:8000/health
# Get all team members (public)
curl http://localhost:8000/api/v1/team-members
# Login
TOKEN=$(curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"pass"}' \
| jq -r '.access_token')
# Create team member (admin)
curl -X POST http://localhost:8000/api/v1/team-members \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"role": "QA Lead",
"email": "[email protected]"
}'
# Upload profile photo
curl -X POST http://localhost:8000/api/v1/team-members/123/photo \
-H "Authorization: Bearer $TOKEN" \
-F "[email protected]"
# Get with filters
curl "http://localhost:8000/api/v1/team-members?role=QA%20Lead&active=true"
3. Testing with HTTPie (Prettier Output)
# Install httpie
pip install httpie
# Login
http POST localhost:8000/api/v1/auth/login [email protected] password=pass
# Create with auth
http POST localhost:8000/api/v1/team-members \
Установить api-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteBashGlobGrepВложенные файлы
FAQ
Что делает скилл api-testing?
Test FastAPI endpoints with pytest and generate API documentation. Use when creating new APIs or verifying existing endpoints work correctly.
Как установить скилл api-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл api-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic