https://github.com/mvahaste/unit-ci-testing
π Learning unit testing & CI pipelines
https://github.com/mvahaste/unit-ci-testing
ci cicd fastapi python testing unittest
Last synced: about 2 months ago
JSON representation
π Learning unit testing & CI pipelines
- Host: GitHub
- URL: https://github.com/mvahaste/unit-ci-testing
- Owner: mvahaste
- Created: 2025-03-18T17:44:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-18T18:28:48.000Z (over 1 year ago)
- Last Synced: 2025-03-18T18:48:41.875Z (over 1 year ago)
- Topics: ci, cicd, fastapi, python, testing, unittest
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π Learning Unit Testing & CI Pipelines
This project is a simple FastAPI-based application designed to manage a todo list. I made it to learn FastAPI, testing with pytest, and integrating GitHub Actions for continuous integration (CI).
# Table of contents
1. [π¨ Features](#-features)
2. [ποΈ Application Structure](#-application-structure)
3. [βοΈ Installation](#-installation)
4. [π‘ Endpoints](#-endpoints)
5. [π§ͺ Testing](#-testing)
6. [π GitHub Actions](#-github-actions)
## π¨ Features
- **Create a Todo**: Add a new todo item with a title and optional description.
- **Read Todos**: View all todos or a specific todo by its ID.
- **Update a Todo**: Modify the title or description of an existing todo.
- **Delete a Todo**: Remove a todo from the list.
- **Error Handling**: The app provides error responses when a resource is not found or when required data is missing.
## ποΈ Application Structure
- `app/main.py`: Contains the FastAPI application and its routes.
- `tests/test_main.py`: Contains tests for the application using `pytest` and FastAPI's test client.
## βοΈ Installation
To run the project locally, follow these steps:
1. Clone the repository:
```
git clone https://github.com/mvahaste/unit-ci-testing
cd unit-ci-testing
```
2. Create a virtual environment (optional but recommended):
```
python3 -m venv venv
source venv/bin/activate
```
3. Install the dependencies:
```
python3 -m pip install -r requirements.txt
```
4. Run the application:
```
uvicorn app.main:app --reload
```
Your FastAPI app will be running at http://127.0.0.1:8000.
## π‘ Endpoints
- GET /: Returns a greeting message.
- GET /todos: Returns all todos.
- GET /todos/{todo_id}: Returns a specific todo by ID.
- POST /todos: Creates a new todo.
- PUT /todos/{todo_id}: Updates an existing todo.
- DELETE /todos/{todo_id}: Deletes a todo by ID.
## π§ͺ Testing
This project includes tests to ensure the functionality of the application. Tests are written using pytest and FastAPIβs test client.
To run the tests, use the following command:
```
pytest -v --tb=short --disable-warnings
```
## π GitHub Actions
This project includes GitHub Actions for continuous integration.
It automatically runs tests whenever changes are pushed to the repository, generates a test report with `pytest-md` and `pytest-emoji`, and adds it to the job summary. The `main` branch also has protections on it, which require all tests to pass before accepting a pull request.
### Example
