Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for API endpoints using TestClient library from fast-api #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/tests/test_teuthology_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys
sys.path.append('src')
from fastapi.testclient import TestClient
import json
from src.main import app



client = TestClient(app)

def test_read_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"root": "success"}


def test_get_suites():
response = client.get("/suites")
assert response.status_code == 404
assert response.json() == {'detail': 'Not Found'}

def test_get_suite_by_name():
suite_name = "suite1"
response = client.get(f"/suites/{suite_name}")
assert response.status_code == 404
if response.status_code == 200:
assert response.json()["name"] == suite_name


def test_create_suite():
suite_name = "suite4"
data = {"name": suite_name, "description": "Suite 4"}
response = client.post("/suites", json.dumps(data))
assert response.status_code == 404
if response.status_code == 201:
assert response.json()["name"] == suite_name

def test_update_suite():
suite_name = "suite1"
data = {"name": suite_name, "description": "Updated Suite 1"}
response = client.put(f"/suites/{suite_name}", json.dumps(data))
assert response.status_code == 404
if response.status_code == 200:
assert response.json()["description"] == data["description"]

def test_delete_suite():
suite_name = "suite3"
response = client.delete(f"/suites/{suite_name}")
assert response.status_code == 404
if response.status_code == 204:
assert client.get(f"/suites/{suite_name}").status_code == 404