-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove extra function 🔥, Update unit test ✅
- Loading branch information
Showing
2 changed files
with
24 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
import uuid | ||
from main import app | ||
import json | ||
|
||
client = TestClient(app) | ||
rarendom = uuid.uuid4() | ||
testURL = f"http://localhost/{rarendom}" | ||
data = {"url": testURL, "ttl": -1} | ||
dataJson = json.dumps(data) | ||
short = 0 | ||
|
||
|
||
def test_read_main(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "Welcome to url shortening app"} | ||
|
||
|
||
def test_create_new_short(): | ||
global short | ||
response = client.post("/", dataJson) | ||
assert response.status_code == 200 | ||
returnData = response.json() | ||
short = str(returnData["short"]) | ||
assert len(returnData["short"]) == 6 | ||
|
||
|
||
def test_get_url(): | ||
response = client.get(f"/{short}") | ||
assert response.status_code == 200 |