48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
from devplacepy.database.nodes import get_device
|
|
from tests.api.admin.nodes.conftest import admin_headers, make_admin, make_device
|
|
from tests.api.nodes.conftest import make_member
|
|
|
|
|
|
def test_member_cannot_suspend(client):
|
|
member = make_member()
|
|
device = make_device(member["uid"])
|
|
response = client.post(f"/admin/nodes/devices/{device['uid']}/suspend", json={"minutes": 5}, headers=admin_headers(member))
|
|
assert response.status_code == 403
|
|
|
|
|
|
def test_suspend_and_unsuspend_round_trip(client, admin):
|
|
owner = make_member()
|
|
device = make_device(owner["uid"])
|
|
url = f"/admin/nodes/devices/{device['uid']}"
|
|
response = client.post(f"{url}/suspend", json={"minutes": 30, "reason": "noisy"}, headers=admin_headers(admin))
|
|
assert response.json()["data"] == {"uid": device["uid"], "minutes": 30}
|
|
row = get_device(device["uid"])
|
|
assert row["status"] == "suspended"
|
|
assert row["suspend_reason"] == "noisy"
|
|
assert client.post(f"{url}/unsuspend", headers=admin_headers(admin)).status_code == 200
|
|
assert get_device(device["uid"])["status"] == "active"
|
|
assert client.post(f"{url}/unsuspend", headers=admin_headers(admin)).status_code == 409
|
|
|
|
|
|
def test_minutes_are_bounded(client, admin):
|
|
owner = make_member()
|
|
device = make_device(owner["uid"])
|
|
url = f"/admin/nodes/devices/{device['uid']}/suspend"
|
|
for minutes in (0, 10081):
|
|
assert client.post(url, json={"minutes": minutes}, headers=admin_headers(admin)).status_code in (400, 422)
|
|
|
|
|
|
def test_unknown_device_is_404(client, admin):
|
|
response = client.post("/admin/nodes/devices/nope/suspend", json={"minutes": 5}, headers=admin_headers(admin))
|
|
assert response.status_code == 404
|
|
|
|
|
|
def test_junior_admin_cannot_suspend_a_senior_admins_device(client):
|
|
senior = make_admin()
|
|
junior = make_admin()
|
|
device = make_device(senior["uid"])
|
|
client.post(f"/admin/nodes/devices/{device['uid']}/suspend", json={"minutes": 5}, headers=admin_headers(junior))
|
|
assert get_device(device["uid"])["status"] == "active"
|