[FEAT] improve update_admin_settings (#1903)
* [FEAT] improve update_admin_settings while working on the push notification pr i found it very hard just to update 2 settings inside the db, so i improved upon update_admin_settings. now you just need to provide a dict with key/values you want to update inside db. also debugging the endpoints for update_settings i found despite the type of `EditableSettings` fastapi did in fact pass a dict. * t * use `EditableSettings` as param in update_settings * fix settings model validation we previously overrode the pydantic validation with our own method * make `LnbitsSettings` a `BaseModel` and only add `BaseSettings` later this allows us to instantiate `EditableSettings` without the environment values being loaded in * add test * forbid extra fields in update api * fixup * add test * test datadir * move UpdateSettings * fix compat * fixup webpush --------- Co-authored-by: jacksn <jkranawetter05@gmail.com>
This commit is contained in:
parent
1b2db34e08
commit
bda054415a
6 changed files with 76 additions and 25 deletions
|
|
@ -10,7 +10,7 @@ from fastapi.testclient import TestClient
|
|||
from httpx import AsyncClient
|
||||
|
||||
from lnbits.app import create_app
|
||||
from lnbits.core.crud import create_account, create_wallet
|
||||
from lnbits.core.crud import create_account, create_wallet, get_user
|
||||
from lnbits.core.models import CreateInvoice
|
||||
from lnbits.core.services import update_wallet_balance
|
||||
from lnbits.core.views.api import api_payments_create_invoice
|
||||
|
|
@ -18,7 +18,10 @@ from lnbits.db import Database
|
|||
from lnbits.settings import settings
|
||||
from tests.helpers import get_hold_invoice, get_random_invoice_data, get_real_invoice
|
||||
|
||||
# dont install extensions for tests
|
||||
# override settings for tests
|
||||
settings.lnbits_admin_extensions = []
|
||||
settings.lnbits_data_folder = "./tests/data"
|
||||
settings.lnbits_admin_ui = True
|
||||
settings.lnbits_extensions_default_install = []
|
||||
|
||||
|
||||
|
|
@ -86,6 +89,12 @@ async def to_user():
|
|||
yield user
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
async def superuser():
|
||||
user = await get_user(settings.super_user)
|
||||
yield user
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
async def to_wallet(to_user):
|
||||
user = to_user
|
||||
|
|
|
|||
40
tests/core/views/test_admin_api.py
Normal file
40
tests/core/views/test_admin_api.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import pytest
|
||||
|
||||
from lnbits.settings import settings
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_get_settings_permission_denied(client, from_user):
|
||||
response = await client.get(f"/admin/api/v1/settings/?usr={from_user.id}")
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_get_settings(client, superuser):
|
||||
response = await client.get(f"/admin/api/v1/settings/?usr={superuser.id}")
|
||||
assert response.status_code == 200
|
||||
result = response.json()
|
||||
assert "super_user" not in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_update_settings(client, superuser):
|
||||
new_site_title = "UPDATED SITETITLE"
|
||||
response = await client.put(
|
||||
f"/admin/api/v1/settings/?usr={superuser.id}",
|
||||
json={"lnbits_site_title": new_site_title},
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_update_noneditable_settings(client, superuser):
|
||||
response = await client.put(
|
||||
f"/admin/api/v1/settings/?usr={superuser.id}",
|
||||
json={"super_user": "UPDATED"},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
Loading…
Add table
Add a link
Reference in a new issue