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..09af423 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -3,4 +3,6 @@ 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 +httpx==0.28.1 \ No newline at end of file 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"}