feat: add comprehensive pytest test suite

Implemented full test coverage for existing features:
- Unit tests (18 tests): Validation logic for email, phone, firstName
- Integration tests (29 tests): Member model, GraphQL queries/mutations
- E2E tests (5 tests): Complete GraphQL API flows over HTTP
- MCP server tests (12 tests): All 6 MCP tools

Test organization:
- tests/unit/ - Pure logic tests
- tests/integration/ - Database and resolver tests
- tests/e2e/ - Full API request/response tests
- tests/mcp/ - MCP server tool tests
- tests/conftest.py - Shared fixtures

All 57 tests passing ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-21 19:56:03 +01:00
co-authored by Claude
parent e041684acd
commit 2f9865abde
9 changed files with 1102 additions and 0 deletions
+67
View File
@@ -379,6 +379,73 @@ Result: Returns member 5's contact details
- Working with complex queries or filters (future)
- You need the raw JSON response
## Running Tests
This project uses pytest for automated testing. All tests are organized in the `tests/` directory.
### Run All Tests
```bash
uv run pytest
```
### Run Specific Test Categories
```bash
# Unit tests only (validation logic)
uv run pytest tests/unit
# Integration tests only (database and resolvers)
uv run pytest tests/integration
# E2E tests only (complete API flows)
uv run pytest tests/e2e
# MCP server tests only
uv run pytest tests/mcp
```
### Run Tests with Verbose Output
```bash
uv run pytest --verbose
```
### Run Tests with Coverage
```bash
uv run pytest --cov=src --cov-report=term-missing
```
## Test Organization
The test suite is organized into four categories:
### Unit Tests (`tests/unit/`)
Pure logic tests for validation functions and utilities.
- **`test_validation.py`** - Email, phone, and firstName validation
### Integration Tests (`tests/integration/`)
Tests for database operations and GraphQL resolvers.
- **`test_member_model.py`** - SQLAlchemy Member model
- **`test_member_queries.py`** - GraphQL queries (member, members)
- **`test_member_mutations.py`** - GraphQL mutations (create, update, delete)
### E2E Tests (`tests/e2e/`)
Complete API request/response flows over HTTP.
- **`test_graphql_api.py`** - GraphQL API endpoints, introspection
### MCP Tests (`tests/mcp/`)
MCP server tools and functionality.
- **`test_mcp_server.py`** - All 6 MCP tools (list_members, get_member, create_member, update_member, get_graphql_schema, execute_graphql_query)
### Test Fixtures
Shared fixtures are defined in `tests/conftest.py`:
- **`test_engine`** - In-memory SQLite database
- **`async_session`** - Async database session
- **`graphql_client`** - FastAPI test client for GraphQL
## Development Workflow
This project uses [OpenSpec](https://openspec.dev) for specification-driven development: