diff --git a/README.md b/README.md index ab6d762..2bde86f 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,11 @@ http://127.0.0.1:8000 http://127.0.0.1:8000/docs Test Short URL Endpoint -http://127.0.0.1:8000/shorten \ No newline at end of file +http://127.0.0.1:8000/shorten + +## Running a test +```bash +PYTHONPATH=./ pytest +export PYTHONPATH=$(pwd) +pytest + ``` \ No newline at end of file diff --git a/app/test_main.py b/app/test_main.py new file mode 100644 index 0000000..887e6aa --- /dev/null +++ b/app/test_main.py @@ -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/") \ No newline at end of file diff --git a/urls.db b/urls.db index c22e4bb..7ef956d 100644 Binary files a/urls.db and b/urls.db differ