Integration testing framework demonstrating microservices communication patterns. Two REST services (FastAPI + Flask) with cross-service validation and error handling.
Order Service (Flask) ──HTTP──> User Service (FastAPI)
Port 8002 Port 8001
Order Service validates users by calling User Service before creating orders. Tests verify the integration works correctly including error scenarios.
- Python 3.11
- FastAPI 0.104.1 (User Service)
- Flask 3.0.0 (Order Service)
- pytest 7.4.3
- requests
- Docker & Docker Compose
Setup:
git clone https://github.com/arturdmt-alt/QA_Integration_Microservices.git
cd QA_Integration_MicroservicesRun with Docker Compose:
# Build containers (first time only)
docker compose build
# Start services
docker compose up -d
# Install test dependencies locally
pip install -r requirements.txt
# Run tests
pytest tests/ -v
# Stop services
docker compose downResults: 13/13 passed in 0.56s
Setup:
py -3.11 -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r requirements.txtRun services (3 separate terminals):
Terminal 1 - User Service:
cd user-service
python main.pyTerminal 2 - Order Service:
cd order-service
python app.pyTerminal 3 - Tests:
pytest tests/ -vResults: 13/13 passed in 43.07s
User Service (8001):
GET /health- Health checkGET /users/{id}- Get user by IDGET /users?active=true- Filter active usersPOST /users- Create userDELETE /users/{id}- Delete user
Order Service (8002):
GET /health- Health checkGET /orders/{id}- Get order with user detailsGET /orders/user/{user_id}- Get orders by userPOST /orders- Create order (validates user exists and is active)
The test suite validates cross-service communication:
User Service Tests (5):
- Health endpoint responds
- Get user by ID returns correct data
- Non-existent user returns 404
- Get all users works
- Filter by active status works
Order Service Tests (3):
- Health endpoint responds
- Get order by ID returns data
- Get all orders works
Integration Tests (5):
- Order includes user details from User Service
- Get orders by user ID works
- Create order for valid active user succeeds
- Create order for inactive user fails with 400
- Create order for non-existent user fails with 404
Results: 13/13 passed in 0.56s
QA_Integration_Microservices/
├── user-service/
│ ├── main.py # FastAPI app
│ ├── Dockerfile
│ └── __init__.py
├── order-service/
│ ├── app.py # Flask app
│ ├── Dockerfile
│ └── __init__.py
├── tests/
│ └── test_integration.py
├── docker-compose.yml
├── requirements.txt
└── README.md
- Service Communication: Order Service makes HTTP calls to User Service
- Data Enrichment: Orders fetch and include user details
- Business Logic: Order creation validates user exists and is active
- Error Handling: Proper HTTP status codes (404, 400) for edge cases
- Integration Testing: Tests verify services work together, not just individually
- Containerization: Docker Compose orchestrates multiple services
Order Service connects to User Service via environment variable:
USER_SERVICE_URL = os.getenv("USER_SERVICE_URL", "http://localhost:8001")In Docker Compose:
environment:
- USER_SERVICE_URL=http://user-service:8001Images:
qa_integration_microservices-user-service(Python 3.11-slim + FastAPI)qa_integration_microservices-order-service(Python 3.11-slim + Flask)
Network:
- Custom bridge network
microservices-networkfor service communication
Benefits:
- Consistent environment across machines
- Isolated dependencies
- 76x faster test execution (0.56s vs 43s)
- Production-like setup
Artur Dmytriyev
QA Automation Engineer
GitHub: https://github.com/arturdmt-alt
LinkedIn: https://www.linkedin.com/in/arturdmytriyev
