Update README with test instructions and add unit tests

This commit is contained in:
2026-03-01 13:38:18 +02:00
parent 43fb1cb6d5
commit 97901f02a6
3 changed files with 32 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
from fastapi.testclient import TestClient
from app.main import app
import sys
import os
# Add the 'app' folder to the sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from app.main import app # Now this should work correctly
client = TestClient(app)
def test_home():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "URL Shortener API"}
def test_shorten_url():
response = client.post("/shorten", json={"url": "https://google.com"})
assert response.status_code == 200
data = response.json()
assert "short_url" in data
short_url = data["short_url"]
assert short_url.startswith("http://localhost:8000/")