Skip to content

Commit

Permalink
tests: setup basic testing
Browse files Browse the repository at this point in the history
  • Loading branch information
royleochan committed Jul 9, 2022
1 parent f6d57d0 commit 6933dd8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
venv
.env
.env
test.db
2 changes: 1 addition & 1 deletion backend/app/routers/url_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)


@router.post("", response_model=Url)
@router.post("", response_model=Url, status_code=201)
def create_url(original_url: OriginalUrl, db: Session = Depends(get_db)):
new_url = url_service.create_url(db=db, url_create=original_url)

Expand Down
Empty file.
14 changes: 14 additions & 0 deletions backend/app/tests/routers/test_url_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ..test_setup import test_db, client

prefix = "/url"


def test_create_url(test_db):
original_url = "http://test.com"
response = client.post(prefix, json={"originalUrl": original_url})
result = response.json()

assert response.status_code == 201
assert result['id'] >= 0
assert result['originalUrl'] == original_url
assert len(result['shortenedUrl']) >= 4
8 changes: 8 additions & 0 deletions backend/app/tests/routers/test_url_shortener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ..test_setup import test_db, client


def test_read_root(test_db):
response = client.get("/")

assert response.status_code == 200
assert response.json() == {"message": "Welcome to MinionUrl."}

0 comments on commit 6933dd8

Please sign in to comment.