Files
devplacepy/tests/api/sync/settings.py
T
2026-10-16 07:20:44 +02:00

40 lines
1.6 KiB
Python

# retoor <retoor@molodetz.nl>
from devplacepy.database import get_setting, set_setting
from tests.api.sync.conftest import sync_ok, unique, user_record
def test_admin_settings_save_normalizes_sync_origins(client, admin):
previous = get_setting("sync_origins", "")
try:
response = client.post(
"/admin/settings",
json={"sync_origins": "A.example.org, b.example.org\nA.example.org"},
headers=admin["headers"],
)
assert response.status_code == 200, response.text
set_setting_cache_free = get_setting("sync_origins", "")
assert set_setting_cache_free == "a.example.org,b.example.org"
refused = client.post(
"/admin/settings", json={"sync_origins": "bad origin!"}, headers=admin["headers"]
)
assert refused.status_code in (400, 422)
finally:
set_setting("sync_origins", previous)
def test_admin_settings_page_shows_sync_controls(client, admin):
page = client.get("/admin/settings", headers={"X-API-KEY": admin["headers"]["X-API-KEY"]})
assert page.status_code == 200
assert 'name="sync_enabled"' in page.text and 'name="sync_origins"' in page.text
def test_clearing_sync_origins_removes_the_allowlist(client, admin, origin):
set_setting("sync_origins", "only.example.org")
try:
client.post("/admin/settings", json={"sync_origins": ""}, headers=admin["headers"])
assert get_setting("sync_origins", "x") == ""
sync_ok(client, admin, "users", origin, [user_record("u1", unique("any"))])
finally:
set_setting("sync_origins", "")