# Integration Tests
Integration tests for the 42crunch MCP Server that require running servers.
## Prerequisites
Before running integration tests, you need to start the servers:
### 1. Start HTTP Server
```bash
# Terminal 1
python http_main.py
```
The HTTP server will run on `http://localhost:8000` by default.
### 2. Start MCP Stdio Server (for MCP tests)
```bash
# Terminal 2
python main.py
```
**Note:** The MCP stdio server tests will automatically start/stop the server process, so you don't need to manually start it for `test_mcp.py`. However, for `test_combined.py`, you may need it running.
## Running Tests
### All Integration Tests
```bash
pytest tests/integration/ -v
```
### HTTP Server Tests Only
```bash
pytest tests/integration/test_http.py -v
```
### MCP Stdio Server Tests Only
```bash
pytest tests/integration/test_mcp.py -v
```
### Combined Comparison Tests
```bash
pytest tests/integration/test_combined.py -v
```
## Test Options
### Skip Tests
```bash
# Skip collection-related tests
pytest tests/integration/ --skip-collection-tests -v
# Skip API-related tests
pytest tests/integration/ --skip-api-tests -v
```
### Provide Test Data
```bash
# Provide API ID for testing get_api_details
pytest tests/integration/ --api-id <uuid> -v
# Provide collection ID for testing get_collection_apis
pytest tests/integration/ --collection-id <uuid> -v
```
### Custom HTTP Server URL
```bash
pytest tests/integration/test_http.py --http-url http://localhost:8080 -v
```
## Test Coverage
⚠️ **All integration tests use REAL API calls - No mocks!**
### HTTP Server Tests (`test_http.py`)
- Health check endpoints
- JSON-RPC 2.0 protocol compliance
- Tools listing
- All three MCP tools **with real API calls**
- Error handling
- Response validation
- Large responses
- Timeout handling
- **Real API data validation**
### MCP Stdio Server Tests (`test_mcp.py`)
- MCP protocol compliance
- Tools listing
- All three MCP tools **with real API calls**
- Error handling
- Connection handling
- Server restart
- Request ID uniqueness
- Large responses
- **Real API data validation**
### Combined Tests (`test_combined.py`)
- Consistency between HTTP and MCP servers **using real API data**
- Response format comparison
- Feature parity verification
- Performance comparison
- Concurrent request handling
- Error message consistency
### Real API Tests (`test_real_api.py`)
- **Dedicated tests using only real API calls**
- End-to-end workflow testing
- Real data validation
- Multiple collections testing
- API details with different options
## Test Structure
- **27 tests** in `test_http.py` (uses real API)
- **23 tests** in `test_mcp.py` (uses real API)
- **9 tests** in `test_combined.py` (uses real API)
- **11 tests** in `test_real_api.py` (real API only)
**Total: 70 integration tests** - All use real API calls, no mocks!
## Troubleshooting
### Server Not Running
If you see:
```
SKIPPED [1] tests/integration/test_http.py: HTTP server is not running. Start it with: python http_main.py
```
Start the HTTP server in another terminal.
### Authentication Errors
Make sure your `.env` file contains a valid `42C_TOKEN`:
```bash
42C_TOKEN=your_token_here
```
### Connection Errors
- Check that servers are running on the expected ports
- Verify firewall settings
- Check network connectivity