forked from VallariAg/teuthology-api
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unittests for /presets endpoint Signed-off-by: Devansh Singh <[email protected]>
- Loading branch information
1 parent
44cf716
commit 84b0091
Showing
1 changed file
with
50 additions
and
0 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
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 |