Skip to content

Commit

Permalink
Add tests/test_preset.py
Browse files Browse the repository at this point in the history
Add unittests for /presets endpoint

Signed-off-by: Devansh Singh <[email protected]>
  • Loading branch information
Devansh3712 committed Jul 1, 2024
1 parent 44cf716 commit 84b0091
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from urllib.parse import urlencode

from fastapi.testclient import TestClient
from sqlmodel import Session

preset_payload = {
"username": "user1",
"name": "test",
"suite": "teuthology:no-ceph",
"cmd": '{"owner": "user1"}',
}


def test_create_preset(session: Session, client: TestClient):
response = client.post("/presets/add", json=preset_payload)
assert response.status_code == 201


def test_get_preset_by_name(session: Session, client: TestClient):
params = {"username": "user1", "name": "test"}
response = client.get(f"/presets?{urlencode(params)}")
data = response.json()

assert response.status_code == 200
assert data["username"] == "user1"
assert data["name"] == "test"


def test_get_all_presets(session: Session, client: TestClient):
params = {"username": "user1"}
response = client.get(f"/presets/list?{urlencode(params)}")
data = response.json()

assert response.status_code == 200
assert len(data) == 1


def test_update_preset(session: Session, client: TestClient):
preset_payload["name"] = "test-updated"
response = client.put("/presets/edit/1", json=preset_payload)
data = response.json()

assert response.status_code == 200
assert data["username"] == "user1"
assert data["name"] == "test-updated"


def test_delete_preset(session: Session, client: TestClient):
response = client.delete("/presets/delete/1")
assert response.status_code == 204

0 comments on commit 84b0091

Please sign in to comment.