From 4e1aff0ae155d167edcd752ab8a35f08a167eaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=ADaz?= Date: Tue, 14 Oct 2025 13:00:40 -0300 Subject: [PATCH 1/2] feature(rest): Add initial rest structure --- docker-compose.yml | 9 +++++---- requirements/base.txt | 3 ++- requirements/prod.txt | 4 +++- rest/__init__.py | 0 rest/api.py | 8 ++++++++ rest/tests/__init__.py | 0 rest/tests/test_health.py | 17 +++++++++++++++++ 7 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 rest/__init__.py create mode 100644 rest/api.py create mode 100644 rest/tests/__init__.py create mode 100644 rest/tests/test_health.py diff --git a/docker-compose.yml b/docker-compose.yml index 53b0131..d0e5b37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,18 @@ version: "3.9" services: - mailing: + api: build: context: . dockerfile: Dockerfile - container_name: python_mailing + container_name: python_mailing_api volumes: - .:/app - command: tail -f /dev/null + command: bash -lc "uvicorn rest.api:app --host 0.0.0.0 --port 6245" environment: - PYTHONUNBUFFERED=1 - tty: true + ports: + - "6245:6245" depends_on: - rabbitmq diff --git a/requirements/base.txt b/requirements/base.txt index ff120a9..abe0b1f 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -3,4 +3,5 @@ pytest==8.4.2 pytest-mock==3.15.1 sendgrid==6.12.5 resend==2.16.0 -celery==5.5.3 \ No newline at end of file +celery==5.5.3 +fastapi==0.119.0 diff --git a/requirements/prod.txt b/requirements/prod.txt index 9c9dec9..706c480 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1 +1,3 @@ --r base.txt \ No newline at end of file +-r base.txt + +uvicorn[standard]==0.30.6 \ No newline at end of file diff --git a/rest/__init__.py b/rest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rest/api.py b/rest/api.py new file mode 100644 index 0000000..af8aee3 --- /dev/null +++ b/rest/api.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI(title="Python Mailing REST API") + + +@app.get("/health") +def health(): + return {"status": "ok"} diff --git a/rest/tests/__init__.py b/rest/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rest/tests/test_health.py b/rest/tests/test_health.py new file mode 100644 index 0000000..4bfa2e9 --- /dev/null +++ b/rest/tests/test_health.py @@ -0,0 +1,17 @@ +from fastapi import status +from fastapi.testclient import TestClient + +from rest.api import app + + +client = TestClient(app) + + +class TestHealth: + def test_health_status_code_ok(self): + response = client.get("/health") + assert response.status_code == status.HTTP_200_OK + + def test_health_response_body_ok(self): + response = client.get("/health") + assert response.json() == {"status": "ok"} From e81823850a7da38cb29c7dc4fec80b4eea43f6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=ADaz?= Date: Tue, 14 Oct 2025 13:02:59 -0300 Subject: [PATCH 2/2] feature(rest): Add missing requirement --- requirements/base.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/base.txt b/requirements/base.txt index abe0b1f..09af423 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -5,3 +5,4 @@ sendgrid==6.12.5 resend==2.16.0 celery==5.5.3 fastapi==0.119.0 +httpx==0.28.1 \ No newline at end of file