A Python mock API built with FastAPI for local integration.
POST /oauth2/v1/tokensfor systemic token generationPOST /customTokenOamCustomerUser/v1/tokenfor user token generationGET /{path_name}/v5/statusto serve JSON fixtures from disk- Async endpoints prepared for artificial delays in test scenarios
- Special mocked users such as
noexistinguserandslowuser uv-based project management- Docker support
- Basic pytest coverage
.
├── app
│ ├── api
│ │ └── routes.py
│ ├── core
│ │ └── settings.py
│ ├── data
│ │ └── directories to serve data.
│ ├── models
│ │ └── schemas.py
│ ├── services
│ │ ├── data_loader.py
│ │ ├── mock_behavior_service.py
│ │ └── token_service.py
│ └── main.py
├── tests
│ ├── conftest.py
│ ├── test_api.py
│ └── test_services.py
├── Dockerfile
└── pyproject.toml
NOTE: data directory is able to serve json fixture data to different path_name endpoint. Just name the directory as path_name, and each json as user_id (nationalIdentityCardNr) and it will be delivered as API response,
- Python 3.12+
uv
uv sync
uv run uvicorn app.main:app --reloadThe API will be available at:
http://127.0.0.1:8000- Swagger UI:
http://127.0.0.1:8000/docs - OpenAPI JSON:
http://127.0.0.1:8000/openapi.json
uv sync
uv run pytestcurl --location 'http://127.0.0.1:8000/oauth2/v1/tokens' \
--header 'Authorization: Basic ZGVtbzpkZW1v' \
--header 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
--header 'oam: MDAz' \
--header 'app-key: demo-app' \
--data-raw 'grant_type=password&username=SVC_AGVIRTUAL&password=Vivo@2025&scope=ServiceAccount.Profile'curl --location 'http://127.0.0.1:8000/customTokenOamCustomerUser/v1/token' \
--header 'Content-Type: application/json' \
--header 'Authorization: sys_mock_token' \
--data '{"userid":"12345678A"}'curl --location 'http://127.0.0.1:8000/agreement/v5/status?accountId=ACC-001&newFieldsInd=true&nationalIdentityCardNr=12345678A' \
--header 'Authorization: Bearer user_token'The project includes special identities to simulate upstream behaviors.
userid = noexistinguser→ returns a mocked upstream500userid = slowuser→ delays the response before returning a valid token
nationalIdentityCardNr = slowuser→ delays the response before returning the JSON fixture
You can extend these scenarios in app/services/mock_behavior_service.py.
Environment variables use the MOCK_API_ prefix.
MOCK_API_TOKEN_EXPIRATION_SECONDS=3600MOCK_API_DEFAULT_DELAY_SECONDS=60
Build the image:
docker build -t mock-api .Run the container:
docker run --rm -p 8000:8000 mock-api