2023-09-12 11:59:32 +02:00
|
|
|
import pytest
|
2025-01-23 15:01:54 +02:00
|
|
|
from httpx import AsyncClient
|
2023-09-12 11:59:32 +02:00
|
|
|
|
2024-10-29 09:58:22 +01:00
|
|
|
from lnbits.settings import Settings
|
2023-09-12 11:59:32 +02:00
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2023-09-12 11:59:32 +02:00
|
|
|
async def test_admin_get_settings_permission_denied(client, from_user):
|
2024-03-28 08:59:28 +01:00
|
|
|
response = await client.get(f"/admin/api/v1/settings?usr={from_user.id}")
|
2025-05-05 11:55:58 +03:00
|
|
|
assert response.status_code == 403
|
2023-09-12 11:59:32 +02:00
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2025-01-23 15:01:54 +02:00
|
|
|
async def test_admin_get_settings(client: AsyncClient, superuser_token: str):
|
|
|
|
|
response = await client.get(
|
|
|
|
|
"/admin/api/v1/settings",
|
|
|
|
|
headers={"Authorization": f"Bearer {superuser_token}"},
|
|
|
|
|
)
|
2023-09-12 11:59:32 +02:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
result = response.json()
|
|
|
|
|
assert "super_user" not in result
|
|
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2025-01-23 15:01:54 +02:00
|
|
|
async def test_admin_update_settings(
|
|
|
|
|
client: AsyncClient, superuser_token: str, settings: Settings
|
|
|
|
|
):
|
2023-09-12 11:59:32 +02:00
|
|
|
new_site_title = "UPDATED SITETITLE"
|
|
|
|
|
response = await client.put(
|
2025-01-23 15:01:54 +02:00
|
|
|
"/admin/api/v1/settings",
|
2023-09-12 11:59:32 +02:00
|
|
|
json={"lnbits_site_title": new_site_title},
|
2025-01-23 15:01:54 +02:00
|
|
|
headers={"Authorization": f"Bearer {superuser_token}"},
|
2023-09-12 11:59:32 +02:00
|
|
|
)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
result = response.json()
|
|
|
|
|
assert "status" in result
|
|
|
|
|
assert result.get("status") == "Success"
|
|
|
|
|
assert settings.lnbits_site_title == new_site_title
|
|
|
|
|
|
|
|
|
|
|
2024-12-11 10:39:28 +01:00
|
|
|
@pytest.mark.anyio
|
2025-01-23 15:01:54 +02:00
|
|
|
async def test_admin_update_noneditable_settings(
|
|
|
|
|
client: AsyncClient,
|
|
|
|
|
superuser_token: str,
|
|
|
|
|
):
|
2023-09-12 11:59:32 +02:00
|
|
|
response = await client.put(
|
2025-01-23 15:01:54 +02:00
|
|
|
"/admin/api/v1/settings",
|
2023-09-12 11:59:32 +02:00
|
|
|
json={"super_user": "UPDATED"},
|
2025-01-23 15:01:54 +02:00
|
|
|
headers={"Authorization": f"Bearer {superuser_token}"},
|
2023-09-12 11:59:32 +02:00
|
|
|
)
|
|
|
|
|
assert response.status_code == 400
|