Local Development and Run

Application Local Run

You can run the Check Application locally with the following command. It doesn’t require any dependencies installation because the application and its dependencies, including PostgreSQL, will be run in a Docker environment:

make up

This will start the application in a Docker container. Ensure that Docker is installed on your system before running this command.

Once the application is running, you can access its API documentation at http://localhost:8000/docs (or http://0.0.0.0:8000/docs). The documentation is autogenerated using OpenAPI/Swagger and provides a self-documented interface for the API.

Local Development

To start developing locally, first, create a Python virtual environment. Then, with the environment activated, install all required dependencies by running the following command (this step is necessary for syntax highlighting in your editor):

pip3 install -r requirements.txt

Application Build

You can force the application build by running the following command:

make build

This command runs docker compose build check-app, ensuring all dependencies and configurations reflect the latest codebase state.

Testing with pytest

To run the test suite, use the following command:

make test

This will execute the test suite inside the check-app-test container using pytest. For debugging and rerunning the last failed test, add the –pdb and –lf keys to the pytest section in setup.cfg.

Note

The test suite does not include cases for invalid user input, as such scenarios are already validated by FastAPI and Pydantic.

Running Tests with Coverage

To ensure full test coverage, use:

make coverage

This will run pytest with coverage inside the container and generate a coverage report.

Note

100% test coverage is the target for the project.

Linting and Static Analysis

To run the linting and static analysis tools, use the following command:

make lint

This will run flake8 for code style checks, isort for sorting imports, mypy for type checking, and yamllint for YAML file validation.

Security Testing

To run the security tests using bandit, use the following command:

make sec

This will run bandit to check for potential security vulnerabilities in the code.

Note

Tests, linting, and security checks are included in the CI workflow (GitHub Actions).

Seeding the Database

You can seed the local database with dummy data using the following command.

make seed

This command starts the application in detached mode and executes a script inside the container to populate the database with test data. Once the process is complete, you should see output similar to the following, displaying the generated users along with their login credentials:

Container is running, executing script...
Inserted 10 users and 1000 checks into the DB
User login: user1, password: clkzxkwx6x
User login: user2, password: hk0y73v5ax
User login: user3, password: 34tt9fty8o
User login: user4, password: spjt4bkbbu
User login: user5, password: s9vj6nghuk
User login: user6, password: cecehvm7fs
User login: user7, password: 3c6eqij9lq
User login: user8, password: v6bntoks5w
User login: user9, password: esm1wh50ru
User login: user10, password: 2vwxlqotqn

This test data can be used to generate a text representation of the check entity and its related items using the appropriate API endpoint.

Example of generated text:

    Weather-resistant Handmade Smart
            Products 511 Co.
========================================
3.00 x 75.36
Compact Top-tier
Professional Hygienic Modern
Advanced Vintage Item             226.08
----------------------------------------
3.00 x 10.92
All-season Handmade
Sustainable Anti-slip
Affordable Item                    32.76
----------------------------------------
1.00 x 51.72
Classic High-quality
Customizable Professional
Exclusive Sustainable Vegan
Item                               51.72
----------------------------------------
1.00 x 24.93
Stackable Colorful Classic
Recyclable Eco-friendly
Fast-charging Heavy-duty
Compact Custom Item                24.93
----------------------------------------
4.00 x 11.77
Heavy-duty Trendy High-
performance Item                   47.08
========================================
TOTAL                             382.57
Cash                              446.49
Change                             63.92
========================================
            05.03.2025 06:30
      Thank you for your purchase!

Shut Down Services

To shut down the application and stop the services, use:

make down

This will stop the Docker containers without removing any associated volumes.

Shut Down and Remove Volumes

To shut down the application and remove all existing volumes, run:

make down-v

This will stop the Docker containers and remove any persistent volumes associated with the application.

Clean Up

To clean up temporary files: .pytest_cache, .mypy_cache, .coverage, run:

make clean