From 83bd8dee781251a76513f06c23545f6f46af1cf7 Mon Sep 17 00:00:00 2001 From: Orlando Alvarez Date: Mon, 4 May 2026 20:40:28 -0700 Subject: [PATCH 1/2] Add pytest health check and CI workflow --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ tests/test_health.py | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/test_health.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bdd47ed --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: ["main", "feat/**"] + pull_request: + branches: ["main"] + +jobs: + test: + name: Run pytest + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Upgrade pip + run: python -m pip install --upgrade pip + + - name: Install project and test dependencies + run: python -m pip install -e . pytest httpx + + - name: Run tests + run: python -m pytest \ No newline at end of file diff --git a/tests/test_health.py b/tests/test_health.py new file mode 100644 index 0000000..05c7c66 --- /dev/null +++ b/tests/test_health.py @@ -0,0 +1,18 @@ +from fastapi.testclient import TestClient + +from app.main import app + + +client = TestClient(app) + + +def test_health_endpoint_returns_ok(): + response = client.get("/api/v1/health") + + assert response.status_code == 200 + + data = response.json() + + assert data["status"] == "ok" + assert data["service"] == "ticket-api" + assert "version" in data \ No newline at end of file From a6111573339d40891c87f4d8face277ed18030fa Mon Sep 17 00:00:00 2001 From: Orlando Alvarez Date: Mon, 4 May 2026 20:57:40 -0700 Subject: [PATCH 2/2] Document testing and CI workflow --- README.md | 142 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 28350f2..110ebc2 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,65 @@ -# ticket-api +# Ticket-API -Backend API de tickets e incidentes orientada a portafolio para roles junior de backend, cloud o platform. Esta primera fase entrega una base limpia de FastAPI con versionado de rutas, healthcheck y manejo básico de errores. +Ticket-API is a backend API for a portfolio-oriented ticketing and incident management system. It is designed for junior backend, cloud, and platform engineering roles. -## Requisitos +This first phase provides a clean FastAPI foundation with versioned routes, a health check endpoint, basic error handling, automated testing with `pytest`, and a GitHub Actions CI workflow. + +## Project Goals + +This project is being built to demonstrate practical backend and cloud-readiness skills, including: + +- Python backend development with FastAPI +- Clean API structure and versioned routing +- Basic service health checks +- Consistent error handling +- Automated testing with `pytest` +- Continuous Integration with GitHub Actions +- Preparation for future PostgreSQL persistence +- Preparation for Docker and cloud deployment + +## Requirements - Python 3.11+ - `pip` -## Instalacion local +## Local Installation + +Create and activate a virtual environment: ```bash python -m venv .venv .venv\Scripts\activate +``` + +Install the project locally: + +```bash pip install -e . ``` -## Ejecutar la API +For testing, install the testing dependencies: + +```bash +pip install pytest httpx +``` + +## Run the API ```bash uvicorn app.main:app --reload ``` -La API quedara disponible en: +The API will be available at: - `http://127.0.0.1:8000/docs` - `http://127.0.0.1:8000/redoc` - `http://127.0.0.1:8000/api/v1/health` -## Endpoint disponible +## Available Endpoint ### `GET /api/v1/health` -Respuesta esperada: +Expected response: ```json { @@ -41,7 +69,62 @@ Respuesta esperada: } ``` -## Estructura actual +This endpoint is used to verify that the API is running correctly. + +## Testing + +The project includes automated tests using `pytest`. + +Run the tests locally: + +```bash +python -m pytest +``` + +Current test coverage includes the health check endpoint: + +```http +GET /api/v1/health +``` + +The test validates that the API: + +- Returns HTTP status code `200` +- Returns `status: "ok"` +- Returns `service: "ticket-api"` +- Includes a `version` field + +Test file: + +```text +tests/test_health.py +``` + +## Continuous Integration + +The project includes a GitHub Actions CI workflow located at: + +```text +.github/workflows/ci.yml +``` + +The workflow runs automatically on: + +- Pushes to `main` +- Pushes to branches matching `feat/**` +- Pull requests targeting `main` + +The CI pipeline performs the following steps: + +1. Checks out the repository. +2. Sets up Python. +3. Upgrades `pip`. +4. Installs the project and test dependencies. +5. Runs the test suite with `pytest`. + +This helps verify that the project continues to work after each change. + +## Current Project Structure ```text app/ @@ -50,14 +133,43 @@ app/ core/ schemas/ main.py + +tests/ + test_health.py + +.github/ + workflows/ + ci.yml ``` -## Manejo de errores incluido +## Error Handling Included + +The API currently includes basic error handling for: + +- `404` responses in a consistent JSON format +- `422` validation errors +- `500` internal server errors with a generic message that avoids exposing internal details + +## Current Status + +Completed: + +- FastAPI project skeleton +- Versioned API routing +- Health check endpoint +- Basic error handling +- Initial README +- Automated health endpoint test with `pytest` +- GitHub Actions CI workflow + +## Next Phase + +The next phase will add persistence with PostgreSQL and initial domain models without breaking the current project structure. -- `404` en formato JSON consistente -- `422` para errores de validacion -- `500` con mensaje generico sin exponer detalles internos +Planned models: -## Siguiente fase +- User +- Ticket +- Incident -La siguiente fase agregara persistencia con PostgreSQL y modelos de dominio, sin romper la estructura creada aqui. +Future phases will include authentication, role-based access control, Docker, CI/CD improvements, and cloud deployment.