Merge branch 'main' of github.com:lnbits/lnbits-legend

This commit is contained in:
callebtc 2022-07-24 01:12:56 +02:00
commit 52c889f1d8
2 changed files with 71 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from lnbits.settings import (
SERVICE_FEE,
)
from ...helpers import get_valid_extensions
from ..crud import (
create_account,
create_wallet,
@ -66,6 +67,14 @@ async def extensions(
HTTPStatus.BAD_REQUEST, "You can either `enable` or `disable` an extension."
)
# check if extension exists
if extension_to_enable or extension_to_disable:
ext = extension_to_enable or extension_to_disable
if ext not in [e.code for e in get_valid_extensions()]:
raise HTTPException(
HTTPStatus.BAD_REQUEST, f"Extension '{ext}' doesn't exist."
)
if extension_to_enable:
logger.info(f"Enabling extension: {extension_to_enable} for user {user.id}")
await update_user_extension(

View File

@ -92,8 +92,69 @@ async def test_get_wallet_with_user_and_wallet(client, to_user, to_wallet):
# check GET /wallet: wrong wallet and user, expect 204
@pytest.mark.asyncio
async def test_get_wallet_with_user_and_wrong_wallet(client, to_user, to_wallet):
async def test_get_wallet_with_user_and_wrong_wallet(client, to_user):
response = await client.get("wallet", params={"usr": to_user.id, "wal": "1"})
assert response.status_code == 204, (
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: extensions list
@pytest.mark.asyncio
async def test_get_extensions(client, to_user):
response = await client.get("extensions", params={"usr": to_user.id})
assert response.status_code == 200, (
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: extensions list wrong user, expect 204
@pytest.mark.asyncio
async def test_get_extensions_wrong_user(client, to_user):
response = await client.get("extensions", params={"usr": "1"})
assert response.status_code == 204, (
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: no user given, expect code 204 no content
@pytest.mark.asyncio
async def test_get_extensions_no_user(client):
response = await client.get("extensions")
assert response.status_code == 204, ( # no content
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: enable extension
@pytest.mark.asyncio
async def test_get_extensions_enable(client, to_user):
response = await client.get(
"extensions", params={"usr": to_user.id, "enable": "lnurlp"}
)
assert response.status_code == 200, (
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: enable nonexistent extension, expect code 400 bad request
@pytest.mark.asyncio
async def test_get_extensions_enable_nonexistent_extension(client, to_user):
response = await client.get(
"extensions", params={"usr": to_user.id, "enable": "12341234"}
)
assert response.status_code == 400, (
str(response.url) + " " + str(response.status_code)
)
# check GET /extensions: enable and disable extensions, expect code 400 bad request
@pytest.mark.asyncio
async def test_get_extensions_enable_and_disable(client, to_user):
response = await client.get(
"extensions",
params={"usr": to_user.id, "enable": "lnurlp", "disable": "lnurlp"},
)
assert response.status_code == 400, (
str(response.url) + " " + str(response.status_code)
)