Improve test coverance and fixes according to tests
This commit is contained in:
@@ -1,17 +1,38 @@
|
||||
# URL-shortener
|
||||
URL-shortener project to showcase python use
|
||||
# URL Shortener API
|
||||
|
||||
Production-ready URL Shortener built with FastAPI, PostgreSQL, Docker, and Alembic.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Techstack
|
||||
|
||||
FastAPI, PostgreSQL, SQLAlchemy 2.0, Alembic, Docker, Pytest and Pydantic v2
|
||||
|
||||
## Features
|
||||
|
||||
Shorten URLs, Redirect, Click tracking, Stats endpoint, Collision handling, 90%+ test coverage, Dockerized and Alembic migrations
|
||||
|
||||
## Local Setup
|
||||
|
||||
## Create venv
|
||||
```bash
|
||||
cd /opt/kjc/int/URL-shortener
|
||||
cd <your-repo-url>
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
## Run locally
|
||||
```bash
|
||||
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
||||
Create .env:
|
||||
```
|
||||
DATABASE_URL=sqlite:///./test.db
|
||||
BASE_URL=http://localhost:8000
|
||||
```
|
||||
|
||||
Run:
|
||||
```bash
|
||||
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 9995
|
||||
```
|
||||
|
||||
Then check:<br>
|
||||
http://localhost:9995<br>
|
||||
http://localhost:9995/docs
|
||||
@@ -19,21 +40,19 @@ http://localhost:9995/docs
|
||||
Test Short URL Endpoint:<br>
|
||||
http://localhost:9995/shorten
|
||||
|
||||
## Running a test
|
||||
## Run Tests
|
||||
```bash
|
||||
PYTHONPATH=./ pytest
|
||||
export PYTHONPATH=$(pwd)
|
||||
python -m pytest --cov=app --cov-report=term-missing
|
||||
pytest --cov=app --cov-report=term-missing
|
||||
```
|
||||
|
||||
## Running Alembic revision
|
||||
```bash
|
||||
cd /opt/kjc/int/URL-shortener
|
||||
cd <your-repo-url>
|
||||
alembic revision --autogenerate -m "create urls table"
|
||||
```
|
||||
|
||||
## Running project in Docker container
|
||||
```bash
|
||||
cd /opt/kjc/int/URL-shortener
|
||||
cd <your-repo-url>
|
||||
docker compose up --build
|
||||
```
|
||||
Reference in New Issue
Block a user