Please make sure that API, Elasticsearch and Redis are running and available.
Set environment variables if needed.
# Run poetry shell
$ poetry shell
# Install dependencies
$ poetry install
# Run tests with pytest
$ pytest tests
docker-compose up --build --exit-code-from tests
Already preconfigured docker-compose.yml file for running tests in Docker.
Environment variables are already set in docker-compose.yml file.
- RUN_CMD=tests
- ES_URL=http://elasticsearch:9200
- REDIS_HOST=redis
- API_URL=http://api:8000
- Tests are written using pytest and pytest-asyncio
- Tests are located in the tests folder
- There are three tests files:
- test_films.py
- test_genres.py
- test_persons.py
- Dependencies
- elasticsearch
- redis
- fastapi
- Docker-compose file for running tests in Docker
- Tests using the same Docker image as API
- What is going on if you run tests in Docker:
- API image is built
- Docker-compose file starts three containers:
- Redis
- Elasticsearch
- API
- Elasticsearch and Redis containers are started without preconfiguring
- Docker-compose file starts tests container
- Tests container waits for Elasticsearch and Redis services are up
- Tests container configure and fill Elasticsearch with test data
- Tests container runs tests
- Docker-compose waits for tests container to exit
- Docker-compose stops all containers
Value | Type | Default | Description |
---|---|---|---|
RUN_CMD | string | Only for run in Docker. Use "tests" | |
ES_URL | string | http://localhost:9200 | Elastic Search URL |
REDIS_HOST | string | localhost | Redis hostname |
REDIS_PORT | int | 6379 | Redis port |
API_URL | string | http://localhost:8000 | FastAPI URL |
API_BASE_PATH | string | /api/v1 | API base path with version |