44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import importlib
|
|
import pytest
|
|
|
|
server_app_module = importlib.import_module("server.app")
|
|
app = server_app_module.app
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
with app.test_client() as client:
|
|
yield client
|
|
|
|
|
|
def test_get_settings_returns_dict(client):
|
|
# Login as admin first
|
|
client.post('/auth/login', data={'username': 'admin', 'password': 'admin'})
|
|
resp = client.get('/admin/api/settings')
|
|
assert resp.status_code == 200
|
|
body = resp.get_json()
|
|
assert body['status'] == 'ok'
|
|
assert isinstance(body.get('settings'), dict)
|
|
|
|
|
|
def test_update_and_get_newsletter_template(client):
|
|
key = 'newsletter_confirmation_template'
|
|
sample = '<p>Thanks for subscribing, {{email}}</p>'
|
|
|
|
# Update via PUT
|
|
# Login as admin first
|
|
client.post('/auth/login', data={'username': 'admin', 'password': 'admin'})
|
|
|
|
resp = client.put(f'/admin/api/settings/{key}', json={'value': sample})
|
|
assert resp.status_code == 200
|
|
body = resp.get_json()
|
|
assert body['status'] == 'ok'
|
|
|
|
# Retrieve via GET and ensure the value is present
|
|
resp = client.get('/admin/api/settings')
|
|
assert resp.status_code == 200
|
|
body = resp.get_json()
|
|
assert body['status'] == 'ok'
|
|
settings = body.get('settings') or {}
|
|
assert settings.get(key) == sample
|