chore: update to latest pytest (#2800)
This commit is contained in:
parent
8ff4962e86
commit
291c69e470
27 changed files with 303 additions and 310 deletions
|
|
@ -4,13 +4,13 @@ from lnbits.core.models import User
|
|||
from lnbits.settings import Settings
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
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
|
||||
@pytest.mark.anyio
|
||||
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
|
||||
|
|
@ -18,7 +18,7 @@ async def test_admin_get_settings(client, superuser):
|
|||
assert "super_user" not in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_admin_update_settings(client, superuser: User, settings: Settings):
|
||||
new_site_title = "UPDATED SITETITLE"
|
||||
response = await client.put(
|
||||
|
|
@ -32,7 +32,7 @@ async def test_admin_update_settings(client, superuser: User, settings: Settings
|
|||
assert settings.lnbits_site_title == new_site_title
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_admin_update_noneditable_settings(client, superuser):
|
||||
response = await client.put(
|
||||
f"/admin/api/v1/settings?usr={superuser.id}",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from ..helpers import (
|
|||
|
||||
|
||||
# create account POST /api/v1/account
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_account(client, settings: Settings):
|
||||
settings.lnbits_allow_new_accounts = False
|
||||
response = await client.post("/api/v1/account", json={"name": "test"})
|
||||
|
|
@ -37,7 +37,7 @@ async def test_create_account(client, settings: Settings):
|
|||
|
||||
# check POST and DELETE /api/v1/wallet with adminkey:
|
||||
# create additional wallet and delete it
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_wallet_and_delete(client, adminkey_headers_to):
|
||||
response = await client.post(
|
||||
"/api/v1/wallet", json={"name": "test"}, headers=adminkey_headers_to
|
||||
|
|
@ -80,7 +80,7 @@ async def test_create_wallet_and_delete(client, adminkey_headers_to):
|
|||
|
||||
|
||||
# check GET /api/v1/wallet with inkey: wallet info, no balance
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_wallet_inkey(client, inkey_headers_to):
|
||||
response = await client.get("/api/v1/wallet", headers=inkey_headers_to)
|
||||
assert response.status_code == 200
|
||||
|
|
@ -91,7 +91,7 @@ async def test_get_wallet_inkey(client, inkey_headers_to):
|
|||
|
||||
|
||||
# check GET /api/v1/wallet with adminkey: wallet info with balance
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_wallet_adminkey(client, adminkey_headers_to):
|
||||
response = await client.get("/api/v1/wallet", headers=adminkey_headers_to)
|
||||
assert response.status_code == 200
|
||||
|
|
@ -102,21 +102,21 @@ async def test_get_wallet_adminkey(client, adminkey_headers_to):
|
|||
|
||||
|
||||
# check PUT /api/v1/wallet/newwallet: empty request where admin key is needed
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_put_empty_request_expected_admin_keys(client):
|
||||
response = await client.put("/api/v1/wallet/newwallet")
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
# check POST /api/v1/payments: empty request where invoice key is needed
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_post_empty_request_expected_invoice_keys(client):
|
||||
response = await client.post("/api/v1/payments")
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
# check POST /api/v1/payments: invoice creation
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
response = await client.post(
|
||||
|
|
@ -132,7 +132,7 @@ async def test_create_invoice(client, inkey_headers_to):
|
|||
return invoice
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice_fiat_amount(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
data["unit"] = "EUR"
|
||||
|
|
@ -156,7 +156,7 @@ async def test_create_invoice_fiat_amount(client, inkey_headers_to):
|
|||
assert extra["fiat_rate"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize("currency", ("msat", "RRR"))
|
||||
async def test_create_invoice_validates_used_currency(
|
||||
currency, client, inkey_headers_to
|
||||
|
|
@ -172,7 +172,7 @@ async def test_create_invoice_validates_used_currency(
|
|||
|
||||
|
||||
# check POST /api/v1/payments: invoice creation for internal payments only
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_internal_invoice(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
data["internal"] = True
|
||||
|
|
@ -190,7 +190,7 @@ async def test_create_internal_invoice(client, inkey_headers_to):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: invoice with custom expiry
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice_custom_expiry(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
expiry_seconds = 600 * 6 * 24 * 31 # 31 days in the future
|
||||
|
|
@ -205,7 +205,7 @@ async def test_create_invoice_custom_expiry(client, inkey_headers_to):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: make payment
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice(
|
||||
client, from_wallet_ws, invoice: Payment, adminkey_headers_from
|
||||
):
|
||||
|
|
@ -231,7 +231,7 @@ async def test_pay_invoice(
|
|||
|
||||
|
||||
# check GET /api/v1/payments/<hash>: payment status
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_check_payment_without_key(client, invoice: Payment):
|
||||
# check the payment status
|
||||
response = await client.get(f"/api/v1/payments/{invoice.payment_hash}")
|
||||
|
|
@ -247,7 +247,7 @@ async def test_check_payment_without_key(client, invoice: Payment):
|
|||
# If postgres: it will succeed only with inkey_headers_from
|
||||
# If sqlite: it will succeed only with adminkey_headers_to
|
||||
# TODO: fix this
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_check_payment_with_key(client, invoice: Payment, inkey_headers_from):
|
||||
# check the payment status
|
||||
response = await client.get(
|
||||
|
|
@ -261,7 +261,7 @@ async def test_check_payment_with_key(client, invoice: Payment, inkey_headers_fr
|
|||
|
||||
|
||||
# check POST /api/v1/payments: payment with wrong key type
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice_wrong_key(client, invoice, adminkey_headers_from):
|
||||
data = {"out": True, "bolt11": invoice.bolt11}
|
||||
# try payment with wrong key
|
||||
|
|
@ -274,7 +274,7 @@ async def test_pay_invoice_wrong_key(client, invoice, adminkey_headers_from):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: payment with self payment
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice_self_payment(client, adminkey_headers_from):
|
||||
create_invoice = CreateInvoice(out=False, amount=1000, memo="test")
|
||||
response = await client.post(
|
||||
|
|
@ -292,7 +292,7 @@ async def test_pay_invoice_self_payment(client, adminkey_headers_from):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: payment with invoice key [should fail]
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice_invoicekey(client, invoice, inkey_headers_from):
|
||||
data = {"out": True, "bolt11": invoice.bolt11}
|
||||
# try payment with invoice key
|
||||
|
|
@ -303,7 +303,7 @@ async def test_pay_invoice_invoicekey(client, invoice, inkey_headers_from):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: payment with admin key, trying to pay twice [should fail]
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice_adminkey(client, invoice, adminkey_headers_from):
|
||||
data = {"out": True, "bolt11": invoice.bolt11}
|
||||
# try payment with admin key
|
||||
|
|
@ -313,7 +313,7 @@ async def test_pay_invoice_adminkey(client, invoice, adminkey_headers_from):
|
|||
assert response.status_code > 300 # should fail
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_payments(client, inkey_fresh_headers_to, fake_payments):
|
||||
fake_data, filters = fake_payments
|
||||
|
||||
|
|
@ -348,7 +348,7 @@ async def test_get_payments(client, inkey_fresh_headers_to, fake_payments):
|
|||
assert len(payments) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_payments_paginated(client, inkey_fresh_headers_to, fake_payments):
|
||||
fake_data, filters = fake_payments
|
||||
|
||||
|
|
@ -363,7 +363,7 @@ async def test_get_payments_paginated(client, inkey_fresh_headers_to, fake_payme
|
|||
assert paginated["total"] == len(fake_data)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_payments_history(client, inkey_fresh_headers_to, fake_payments):
|
||||
fake_data, filters = fake_payments
|
||||
|
||||
|
|
@ -393,7 +393,7 @@ async def test_get_payments_history(client, inkey_fresh_headers_to, fake_payment
|
|||
|
||||
|
||||
# check POST /api/v1/payments/decode
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_decode_invoice(client, invoice: Payment):
|
||||
data = {"data": invoice.bolt11}
|
||||
response = await client.post(
|
||||
|
|
@ -405,7 +405,7 @@ async def test_decode_invoice(client, invoice: Payment):
|
|||
|
||||
|
||||
# check api_payment() internal function call (NOT API): payment status
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_api_payment_without_key(invoice: Payment):
|
||||
# check the payment status
|
||||
response = await api_payment(invoice.payment_hash)
|
||||
|
|
@ -416,7 +416,7 @@ async def test_api_payment_without_key(invoice: Payment):
|
|||
|
||||
|
||||
# check api_payment() internal function call (NOT API): payment status
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_api_payment_with_key(invoice: Payment, inkey_headers_from):
|
||||
# check the payment status
|
||||
response = await api_payment(invoice.payment_hash, inkey_headers_from["X-Api-Key"])
|
||||
|
|
@ -426,7 +426,7 @@ async def test_api_payment_with_key(invoice: Payment, inkey_headers_from):
|
|||
|
||||
|
||||
# check POST /api/v1/payments: invoice creation with a description hash
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice_with_description_hash(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
description = "asdasdasd"
|
||||
|
|
@ -443,7 +443,7 @@ async def test_create_invoice_with_description_hash(client, inkey_headers_to):
|
|||
return invoice
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice_with_unhashed_description(client, inkey_headers_to):
|
||||
data = await get_random_invoice_data()
|
||||
description = "test description"
|
||||
|
|
@ -461,7 +461,7 @@ async def test_create_invoice_with_unhashed_description(client, inkey_headers_to
|
|||
return invoice
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_update_wallet(client, adminkey_headers_from):
|
||||
name = "new name"
|
||||
currency = "EUR"
|
||||
|
|
@ -481,7 +481,7 @@ async def test_update_wallet(client, adminkey_headers_from):
|
|||
assert response.json()["name"] == name
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fiat_tracking(client, adminkey_headers_from, settings: Settings):
|
||||
async def create_invoice():
|
||||
data = await get_random_invoice_data()
|
||||
|
|
@ -522,7 +522,7 @@ async def test_fiat_tracking(client, adminkey_headers_from, settings: Settings):
|
|||
assert extra["wallet_fiat_rate"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"lnurl_response_data, callback_response_data, expected_response",
|
||||
[
|
||||
|
|
|
|||
|
|
@ -27,11 +27,12 @@ nostr_event = {
|
|||
private_key = secp256k1.PrivateKey(
|
||||
bytes.fromhex("6e00ecda7d3c8945f07b7d6ecc18cfff34c07bc99677309e2b9310d9fc1bb138")
|
||||
)
|
||||
assert private_key.pubkey, "Pubkey not created."
|
||||
pubkey_hex = private_key.pubkey.serialize().hex()[2:]
|
||||
|
||||
|
||||
################################ LOGIN ################################
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_bad_user(http_client: AsyncClient):
|
||||
response = await http_client.post(
|
||||
"/api/v1/auth", json={"username": "non_existing_user", "password": "secret1234"}
|
||||
|
|
@ -41,7 +42,7 @@ async def test_login_bad_user(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Invalid credentials."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_alan_usr(user_alan: User, http_client: AsyncClient):
|
||||
response = await http_client.post("/api/v1/auth/usr", json={"usr": user_alan.id})
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ async def test_login_alan_usr(user_alan: User, http_client: AsyncClient):
|
|||
assert alan["email"] == user_alan.email
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_usr_not_allowed(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -81,7 +82,7 @@ async def test_login_usr_not_allowed(
|
|||
), "Expected access token after login."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_alan_username_password_ok(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -119,7 +120,7 @@ async def test_login_alan_username_password_ok(
|
|||
), f"Expected 1 default wallet, not {len(user.wallets)}."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_alan_email_password_ok(user_alan: User, http_client: AsyncClient):
|
||||
response = await http_client.post(
|
||||
"/api/v1/auth", json={"username": user_alan.email, "password": "secret1234"}
|
||||
|
|
@ -130,7 +131,7 @@ async def test_login_alan_email_password_ok(user_alan: User, http_client: AsyncC
|
|||
assert access_token is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_alan_password_nok(user_alan: User, http_client: AsyncClient):
|
||||
response = await http_client.post(
|
||||
"/api/v1/auth", json={"username": user_alan.username, "password": "bad_pasword"}
|
||||
|
|
@ -140,7 +141,7 @@ async def test_login_alan_password_nok(user_alan: User, http_client: AsyncClient
|
|||
assert response.json().get("detail") == "Invalid credentials."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_username_password_not_allowed(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -165,7 +166,7 @@ async def test_login_username_password_not_allowed(
|
|||
assert response.json().get("access_token") is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_login_alan_change_auth_secret_key(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -196,7 +197,7 @@ async def test_login_alan_change_auth_secret_key(
|
|||
|
||||
|
||||
################################ REGISTER WITH PASSWORD ################################
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_ok(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -229,7 +230,7 @@ async def test_register_ok(http_client: AsyncClient):
|
|||
), f"Expected 1 default wallet, not {len(user.wallets)}."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_email_twice(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -260,7 +261,7 @@ async def test_register_email_twice(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Email already exists."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_username_twice(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -290,7 +291,7 @@ async def test_register_username_twice(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Username already exists."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_passwords_do_not_match(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -307,7 +308,7 @@ async def test_register_passwords_do_not_match(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Passwords do not match."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_bad_email(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -325,7 +326,7 @@ async def test_register_bad_email(http_client: AsyncClient):
|
|||
|
||||
|
||||
################################ CHANGE PASSWORD ################################
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_change_password_ok(http_client: AsyncClient, settings: Settings):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -377,7 +378,7 @@ async def test_change_password_ok(http_client: AsyncClient, settings: Settings):
|
|||
assert response.json().get("access_token") is not None, "Access token created."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_change_password_not_authenticated(http_client: AsyncClient):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.put(
|
||||
|
|
@ -395,7 +396,7 @@ async def test_change_password_not_authenticated(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Missing user ID or access token."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_alan_change_password_old_nok(user_alan: User, http_client: AsyncClient):
|
||||
response = await http_client.post("/api/v1/auth/usr", json={"usr": user_alan.id})
|
||||
|
||||
|
|
@ -419,7 +420,7 @@ async def test_alan_change_password_old_nok(user_alan: User, http_client: AsyncC
|
|||
assert response.json().get("detail") == "Invalid old password."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_alan_change_password_different_user(
|
||||
user_alan: User, http_client: AsyncClient
|
||||
):
|
||||
|
|
@ -445,7 +446,7 @@ async def test_alan_change_password_different_user(
|
|||
assert response.json().get("detail") == "Invalid user ID."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_alan_change_password_auth_threshold_expired(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -481,12 +482,13 @@ async def test_alan_change_password_auth_threshold_expired(
|
|||
################################ REGISTER PUBLIC KEY ################################
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_ok(http_client: AsyncClient, settings: Settings):
|
||||
event = {**nostr_event}
|
||||
event["created_at"] = int(time.time())
|
||||
|
||||
private_key = secp256k1.PrivateKey(bytes.fromhex(os.urandom(32).hex()))
|
||||
assert private_key.pubkey, "Pubkey not created."
|
||||
pubkey_hex = private_key.pubkey.serialize().hex()[2:]
|
||||
event_signed = sign_event(event, pubkey_hex, private_key)
|
||||
base64_event = base64.b64encode(json.dumps(event_signed).encode()).decode("ascii")
|
||||
|
|
@ -521,7 +523,7 @@ async def test_register_nostr_ok(http_client: AsyncClient, settings: Settings):
|
|||
), f"Expected 1 default wallet, not {len(user.wallets)}."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_not_allowed(http_client: AsyncClient, settings: Settings):
|
||||
# exclude 'nostr_auth_nip98'
|
||||
settings.auth_allowed_methods = [AuthMethods.username_and_password.value]
|
||||
|
|
@ -536,7 +538,7 @@ async def test_register_nostr_not_allowed(http_client: AsyncClient, settings: Se
|
|||
settings.auth_allowed_methods = AuthMethods.all()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_bad_header(http_client: AsyncClient):
|
||||
response = await http_client.post("/api/v1/auth/nostr")
|
||||
|
||||
|
|
@ -559,7 +561,7 @@ async def test_register_nostr_bad_header(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Nostr login event cannot be parsed."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_bad_event(http_client: AsyncClient, settings: Settings):
|
||||
settings.auth_allowed_methods = AuthMethods.all()
|
||||
base64_event = base64.b64encode(json.dumps(nostr_event).encode()).decode("ascii")
|
||||
|
|
@ -587,7 +589,7 @@ async def test_register_nostr_bad_event(http_client: AsyncClient, settings: Sett
|
|||
assert response.json().get("detail") == "Nostr login event is not valid."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_bad_event_kind(http_client: AsyncClient):
|
||||
event_bad_kind = {**nostr_event}
|
||||
event_bad_kind["kind"] = "12345"
|
||||
|
|
@ -604,7 +606,7 @@ async def test_register_nostr_bad_event_kind(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Invalid event kind."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_bad_event_tag_u(http_client: AsyncClient):
|
||||
event_bad_kind = {**nostr_event}
|
||||
event_bad_kind["created_at"] = int(time.time())
|
||||
|
|
@ -636,7 +638,7 @@ async def test_register_nostr_bad_event_tag_u(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Invalid value for tag 'method'."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_register_nostr_bad_event_tag_menthod(http_client: AsyncClient):
|
||||
event_bad_kind = {**nostr_event}
|
||||
event_bad_kind["created_at"] = int(time.time())
|
||||
|
|
@ -672,6 +674,7 @@ async def test_register_nostr_bad_event_tag_menthod(http_client: AsyncClient):
|
|||
|
||||
|
||||
################################ CHANGE PUBLIC KEY ################################
|
||||
@pytest.mark.anyio
|
||||
async def test_change_pubkey_npub_ok(http_client: AsyncClient, settings: Settings):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -692,6 +695,7 @@ async def test_change_pubkey_npub_ok(http_client: AsyncClient, settings: Setting
|
|||
access_token_payload = AccessTokenPayload(**payload)
|
||||
|
||||
private_key = secp256k1.PrivateKey(bytes.fromhex(os.urandom(32).hex()))
|
||||
assert private_key.pubkey, "Pubkey not created."
|
||||
pubkey_hex = private_key.pubkey.serialize().hex()[2:]
|
||||
npub = hex_to_npub(pubkey_hex)
|
||||
|
||||
|
|
@ -711,7 +715,7 @@ async def test_change_pubkey_npub_ok(http_client: AsyncClient, settings: Setting
|
|||
assert user.pubkey == pubkey_hex
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_change_pubkey_ok(
|
||||
http_client: AsyncClient, user_alan: User, settings: Settings
|
||||
):
|
||||
|
|
@ -734,6 +738,7 @@ async def test_change_pubkey_ok(
|
|||
access_token_payload = AccessTokenPayload(**payload)
|
||||
|
||||
private_key = secp256k1.PrivateKey(bytes.fromhex(os.urandom(32).hex()))
|
||||
assert private_key.pubkey, "Pubkey not created."
|
||||
pubkey_hex = private_key.pubkey.serialize().hex()[2:]
|
||||
|
||||
response = await http_client.put(
|
||||
|
|
@ -798,7 +803,7 @@ async def test_change_pubkey_ok(
|
|||
assert response.json().get("detail") == "Public key already in use."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_change_pubkey_not_authenticated(
|
||||
http_client: AsyncClient, user_alan: User
|
||||
):
|
||||
|
|
@ -814,7 +819,7 @@ async def test_change_pubkey_not_authenticated(
|
|||
assert response.json().get("detail") == "Missing user ID or access token."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_change_pubkey_other_user(http_client: AsyncClient, user_alan: User):
|
||||
response = await http_client.post("/api/v1/auth/usr", json={"usr": user_alan.id})
|
||||
|
||||
|
|
@ -834,7 +839,7 @@ async def test_change_pubkey_other_user(http_client: AsyncClient, user_alan: Use
|
|||
assert response.json().get("detail") == "Invalid user ID."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_alan_change_pubkey_auth_threshold_expired(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -865,7 +870,7 @@ async def test_alan_change_pubkey_auth_threshold_expired(
|
|||
|
||||
|
||||
################################ RESET PASSWORD ################################
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_request_reset_key_ok(http_client: AsyncClient, settings: Settings):
|
||||
tiny_id = shortuuid.uuid()[:8]
|
||||
response = await http_client.post(
|
||||
|
|
@ -917,7 +922,7 @@ async def test_request_reset_key_ok(http_client: AsyncClient, settings: Settings
|
|||
assert access_token is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_request_reset_key_user_not_found(http_client: AsyncClient):
|
||||
user_id = "926abb2ab59a48ebb2485bcceb58d05e"
|
||||
reset_key = await api_users_reset_password(user_id)
|
||||
|
|
@ -937,7 +942,7 @@ async def test_request_reset_key_user_not_found(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "User not found."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_reset_username_password_not_allowed(
|
||||
http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
@ -964,7 +969,7 @@ async def test_reset_username_password_not_allowed(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_reset_username_passwords_do_not_matcj(
|
||||
http_client: AsyncClient, user_alan: User
|
||||
):
|
||||
|
|
@ -985,7 +990,7 @@ async def test_reset_username_passwords_do_not_matcj(
|
|||
assert response.json().get("detail") == "Passwords do not match."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_reset_username_password_bad_key(http_client: AsyncClient):
|
||||
|
||||
response = await http_client.put(
|
||||
|
|
@ -1000,7 +1005,7 @@ async def test_reset_username_password_bad_key(http_client: AsyncClient):
|
|||
assert response.json().get("detail") == "Invalid reset key."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_reset_password_auth_threshold_expired(
|
||||
user_alan: User, http_client: AsyncClient, settings: Settings
|
||||
):
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_core_views_generic(client):
|
||||
response = await client.get("/")
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /wallet: wrong user, expect 400
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_wallet_with_nonexistent_user(client):
|
||||
response = await client.get("wallet", params={"usr": "1"})
|
||||
assert response.status_code == 400, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /wallet: wallet and user
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_wallet_with_user_and_wallet(client, to_user, to_wallet):
|
||||
response = await client.get(
|
||||
"wallet", params={"usr": to_user.id, "wal": to_wallet.id}
|
||||
|
|
@ -24,28 +24,28 @@ async def test_get_wallet_with_user_and_wallet(client, to_user, to_wallet):
|
|||
|
||||
|
||||
# check GET /wallet: wrong wallet and user, expect 400
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
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 == 400, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /extensions: extensions list
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_extensions(client, to_user):
|
||||
response = await client.get("extensions", params={"usr": to_user.id})
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /extensions: extensions list wrong user, expect 400
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_extensions_wrong_user(client):
|
||||
response = await client.get("extensions", params={"usr": "1"})
|
||||
assert response.status_code == 400, f"{response.url} {response.status_code}"
|
||||
|
||||
|
||||
# check GET /extensions: no user given, expect code 400 bad request
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_extensions_no_user(client):
|
||||
response = await client.get("extensions")
|
||||
# bad request
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ from lnbits.core.models import Payment
|
|||
|
||||
|
||||
# check if the client is working
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_core_views_generic(client):
|
||||
response = await client.get("/")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
# check GET /public/v1/payment/{payment_hash}: correct hash [should pass]
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_api_public_payment_longpolling(client, invoice: Payment):
|
||||
response = await client.get(f"/public/v1/payment/{invoice.payment_hash}")
|
||||
assert response.status_code < 300
|
||||
|
|
@ -19,7 +19,7 @@ async def test_api_public_payment_longpolling(client, invoice: Payment):
|
|||
|
||||
|
||||
# check GET /public/v1/payment/{payment_hash}: wrong hash [should fail]
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_api_public_payment_longpolling_wrong_hash(client, invoice: Payment):
|
||||
response = await client.get(f"/public/v1/payment/{invoice.payment_hash + '0'*64}")
|
||||
assert response.status_code == 404
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from http import HTTPStatus
|
|||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create___bad_body(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -13,7 +13,7 @@ async def test_create___bad_body(client, adminkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create___missing_fields(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -23,7 +23,7 @@ async def test_create___missing_fields(client, adminkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create___bad_access_key(client, inkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -33,7 +33,7 @@ async def test_create___bad_access_key(client, inkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_delete__bad_endpoint_format(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -43,7 +43,7 @@ async def test_delete__bad_endpoint_format(client, adminkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_delete__no_endpoint_param(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -52,7 +52,7 @@ async def test_delete__no_endpoint_param(client, adminkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_delete__no_endpoint_found(client, adminkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -63,7 +63,7 @@ async def test_delete__no_endpoint_found(client, adminkey_headers_from):
|
|||
assert response.json()["count"] == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_delete__bad_access_key(client, inkey_headers_from):
|
||||
response = await client.delete(
|
||||
"/api/v1/webpush",
|
||||
|
|
@ -72,7 +72,7 @@ async def test_delete__bad_access_key(client, inkey_headers_from):
|
|||
assert response.status_code == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_and_delete(client, adminkey_headers_from):
|
||||
response = await client.post(
|
||||
"/api/v1/webpush",
|
||||
|
|
|
|||
|
|
@ -1,18 +1,9 @@
|
|||
# ruff: noqa: E402
|
||||
import asyncio
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import uvloop
|
||||
|
||||
from lnbits.core.views.payment_api import _api_payments_create_invoice
|
||||
from lnbits.wallets.fake import FakeWallet
|
||||
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
import uvloop
|
||||
from asgi_lifespan import LifespanManager
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
|
@ -29,15 +20,24 @@ from lnbits.core.crud import (
|
|||
)
|
||||
from lnbits.core.models import Account, CreateInvoice, PaymentState, User
|
||||
from lnbits.core.services import create_user_account, update_wallet_balance
|
||||
from lnbits.core.views.payment_api import _api_payments_create_invoice
|
||||
from lnbits.db import DB_TYPE, SQLITE, Database
|
||||
from lnbits.settings import AuthMethods, Settings
|
||||
from lnbits.settings import settings as lnbits_settings
|
||||
from lnbits.wallets.fake import FakeWallet
|
||||
from tests.helpers import (
|
||||
get_random_invoice_data,
|
||||
)
|
||||
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def anyio_backend():
|
||||
return "asyncio"
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def settings():
|
||||
# override settings for tests
|
||||
lnbits_settings.lnbits_admin_extensions = []
|
||||
|
|
@ -57,15 +57,8 @@ def run_before_and_after_tests(settings: Settings):
|
|||
_settings_cleanup(settings)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
def event_loop():
|
||||
loop = asyncio.get_event_loop()
|
||||
yield loop
|
||||
loop.close()
|
||||
|
||||
|
||||
# use session scope to run once before and once after all tests
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def app(settings: Settings):
|
||||
app = create_app()
|
||||
async with LifespanManager(app) as manager:
|
||||
|
|
@ -73,7 +66,7 @@ async def app(settings: Settings):
|
|||
yield manager.app
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def client(app, settings: Settings):
|
||||
url = f"http://{settings.host}:{settings.port}"
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url=url) as client:
|
||||
|
|
@ -81,7 +74,7 @@ async def client(app, settings: Settings):
|
|||
|
||||
|
||||
# function scope
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
@pytest.fixture(scope="function")
|
||||
async def http_client(app, settings: Settings):
|
||||
url = f"http://{settings.host}:{settings.port}"
|
||||
|
||||
|
|
@ -94,12 +87,12 @@ def test_client(app):
|
|||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def db():
|
||||
yield Database("database")
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def user_alan():
|
||||
account = await get_account_by_username("alan")
|
||||
if account:
|
||||
|
|
@ -116,13 +109,13 @@ async def user_alan():
|
|||
yield user
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def from_user():
|
||||
user = await create_user_account()
|
||||
yield user
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def from_wallet(from_user):
|
||||
user = from_user
|
||||
|
||||
|
|
@ -134,7 +127,7 @@ async def from_wallet(from_user):
|
|||
yield wallet
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def to_wallet_pagination_tests(to_user):
|
||||
user = to_user
|
||||
wallet = await create_wallet(
|
||||
|
|
@ -143,7 +136,7 @@ async def to_wallet_pagination_tests(to_user):
|
|||
yield wallet
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
@pytest.fixture
|
||||
async def from_wallet_ws(from_wallet, test_client):
|
||||
# wait a bit in order to avoid receiving topup notification
|
||||
await asyncio.sleep(0.1)
|
||||
|
|
@ -151,7 +144,7 @@ async def from_wallet_ws(from_wallet, test_client):
|
|||
yield ws
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def to_user():
|
||||
user = await create_user_account()
|
||||
yield user
|
||||
|
|
@ -165,7 +158,7 @@ def from_super_user(from_user: User, settings: Settings):
|
|||
settings.super_user = prev
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def superuser(settings: Settings):
|
||||
account = await get_account(settings.super_user)
|
||||
assert account, "Superuser not found"
|
||||
|
|
@ -173,7 +166,7 @@ async def superuser(settings: Settings):
|
|||
yield user
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def to_wallet(to_user):
|
||||
user = to_user
|
||||
wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_to")
|
||||
|
|
@ -184,14 +177,14 @@ async def to_wallet(to_user):
|
|||
yield wallet
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def to_fresh_wallet(to_user):
|
||||
user = to_user
|
||||
wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_to_fresh")
|
||||
yield wallet
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
@pytest.fixture
|
||||
async def to_wallet_ws(to_wallet, test_client):
|
||||
# wait a bit in order to avoid receiving topup notification
|
||||
await asyncio.sleep(0.1)
|
||||
|
|
@ -199,7 +192,7 @@ async def to_wallet_ws(to_wallet, test_client):
|
|||
yield ws
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def inkey_fresh_headers_to(to_fresh_wallet):
|
||||
wallet = to_fresh_wallet
|
||||
yield {
|
||||
|
|
@ -208,7 +201,7 @@ async def inkey_fresh_headers_to(to_fresh_wallet):
|
|||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def inkey_headers_from(from_wallet):
|
||||
wallet = from_wallet
|
||||
yield {
|
||||
|
|
@ -217,7 +210,7 @@ async def inkey_headers_from(from_wallet):
|
|||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def adminkey_headers_from(from_wallet):
|
||||
wallet = from_wallet
|
||||
yield {
|
||||
|
|
@ -226,7 +219,7 @@ async def adminkey_headers_from(from_wallet):
|
|||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def inkey_headers_to(to_wallet):
|
||||
wallet = to_wallet
|
||||
yield {
|
||||
|
|
@ -235,7 +228,7 @@ async def inkey_headers_to(to_wallet):
|
|||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def adminkey_headers_to(to_wallet):
|
||||
wallet = to_wallet
|
||||
yield {
|
||||
|
|
@ -244,7 +237,7 @@ async def adminkey_headers_to(to_wallet):
|
|||
}
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def invoice(to_wallet):
|
||||
data = await get_random_invoice_data()
|
||||
invoice_data = CreateInvoice(**data)
|
||||
|
|
@ -253,12 +246,12 @@ async def invoice(to_wallet):
|
|||
del invoice
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
@pytest.fixture(scope="function")
|
||||
async def external_funding_source():
|
||||
yield FakeWallet()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def fake_payments(client, inkey_fresh_headers_to):
|
||||
|
||||
ts = datetime.now(timezone.utc).timestamp()
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
import pytest_asyncio
|
||||
import pytest
|
||||
|
||||
from .helpers import get_hold_invoice, get_real_invoice
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
@pytest.fixture(scope="session")
|
||||
def anyio_backend():
|
||||
return "asyncio"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def hold_invoice():
|
||||
invoice = get_hold_invoice(100)
|
||||
yield invoice
|
||||
del invoice
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
@pytest.fixture(scope="function")
|
||||
async def real_invoice():
|
||||
invoice = get_real_invoice(100)
|
||||
yield {"bolt11": invoice["payment_request"]}
|
||||
del invoice
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
@pytest.fixture(scope="function")
|
||||
async def real_amountless_invoice():
|
||||
invoice = get_real_invoice(0)
|
||||
yield invoice["payment_request"]
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ async def get_node_balance_sats():
|
|||
return balance.node_balance_msats / 1000
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_real_invoice(
|
||||
client, real_invoice, adminkey_headers_from, inkey_headers_from, from_wallet_ws
|
||||
|
|
@ -60,7 +60,7 @@ async def test_pay_real_invoice(
|
|||
assert prev_balance - balance == 100
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_from):
|
||||
prev_balance = await get_node_balance_sats()
|
||||
|
|
@ -106,7 +106,7 @@ async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_
|
|||
await task
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_real_invoice_set_pending_and_check_state(
|
||||
client, real_invoice, adminkey_headers_from, inkey_headers_from
|
||||
|
|
@ -145,7 +145,7 @@ async def test_pay_real_invoice_set_pending_and_check_state(
|
|||
assert payment.success
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_hold_invoice_check_pending(
|
||||
client, hold_invoice, adminkey_headers_from
|
||||
|
|
@ -174,7 +174,7 @@ async def test_pay_hold_invoice_check_pending(
|
|||
assert payment_db_after_settlement
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_hold_invoice_check_pending_and_fail(
|
||||
client, hold_invoice, adminkey_headers_from
|
||||
|
|
@ -209,7 +209,7 @@ async def test_pay_hold_invoice_check_pending_and_fail(
|
|||
assert payment_db_after_settlement.failed is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_pay_hold_invoice_check_pending_and_fail_cancel_payment_task_in_meantime(
|
||||
client, hold_invoice, adminkey_headers_from
|
||||
|
|
@ -248,7 +248,7 @@ async def test_pay_hold_invoice_check_pending_and_fail_cancel_payment_task_in_me
|
|||
assert status.failed
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.skipif(is_fake, reason="this only works in regtest")
|
||||
async def test_receive_real_invoice_set_pending_and_check_state(
|
||||
client, adminkey_headers_from, inkey_headers_from
|
||||
|
|
@ -308,7 +308,7 @@ async def test_receive_real_invoice_set_pending_and_check_state(
|
|||
await task
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_check_fee_reserve(client, adminkey_headers_from):
|
||||
# if regtest, create a real invoice, otherwise create an internal invoice
|
||||
# call /api/v1/payments/fee-reserve?invoice=... with it and check if the fee reserve
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from lnbits.wallets.base import PaymentStatus
|
|||
description = "test create invoice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice(from_wallet):
|
||||
payment = await create_invoice(
|
||||
wallet_id=from_wallet.id,
|
||||
|
|
@ -28,7 +28,7 @@ async def test_create_invoice(from_wallet):
|
|||
assert status.pending
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_internal_invoice(from_wallet):
|
||||
payment = await create_invoice(
|
||||
wallet_id=from_wallet.id, amount=1000, memo=description, internal=True
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from lnbits.exceptions import PaymentError
|
|||
description = "test pay invoice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_services_pay_invoice(to_wallet, real_invoice):
|
||||
payment = await pay_invoice(
|
||||
wallet_id=to_wallet.id,
|
||||
|
|
@ -21,7 +21,7 @@ async def test_services_pay_invoice(to_wallet, real_invoice):
|
|||
assert payment.memo == description
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_services_pay_invoice_0_amount_invoice(
|
||||
to_wallet, real_amountless_invoice
|
||||
):
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from pydantic import parse_obj_as
|
|||
|
||||
from lnbits import bolt11
|
||||
from lnbits.nodes.base import ChannelPoint, ChannelState, NodeChannel
|
||||
from tests.conftest import pytest_asyncio
|
||||
|
||||
from ..helpers import (
|
||||
funding_source,
|
||||
|
|
@ -24,7 +23,7 @@ pytestmark = pytest.mark.skipif(
|
|||
)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture()
|
||||
@pytest.fixture()
|
||||
async def node_client(client, from_super_user, settings):
|
||||
settings.lnbits_node_ui = True
|
||||
settings.lnbits_public_node_ui = False
|
||||
|
|
@ -36,39 +35,39 @@ async def node_client(client, from_super_user, settings):
|
|||
settings.lnbits_node_ui = False
|
||||
|
||||
|
||||
@pytest_asyncio.fixture()
|
||||
@pytest.fixture()
|
||||
async def public_node_client(node_client, settings):
|
||||
settings.lnbits_public_node_ui = True
|
||||
yield node_client
|
||||
settings.lnbits_public_node_ui = False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_node_info_not_found(client, from_super_user, settings):
|
||||
settings.lnbits_node_ui = False
|
||||
response = await client.get("/node/api/v1/info", params={"usr": from_super_user.id})
|
||||
assert response.status_code == HTTPStatus.SERVICE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_public_node_info_not_found(node_client):
|
||||
response = await node_client.get("/node/public/api/v1/info")
|
||||
assert response.status_code == HTTPStatus.SERVICE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_public_node_info(public_node_client):
|
||||
response = await public_node_client.get("/node/public/api/v1/info")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_node_info(node_client):
|
||||
response = await node_client.get("/node/api/v1/info")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_node_invoices(inkey_headers_from, node_client):
|
||||
data = await get_random_invoice_data()
|
||||
response = await node_client.post(
|
||||
|
|
@ -83,7 +82,7 @@ async def test_node_invoices(inkey_headers_from, node_client):
|
|||
assert invoices[0]["payment_hash"] == invoice["payment_hash"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_node_payments(node_client, real_invoice, adminkey_headers_from):
|
||||
response = await node_client.post(
|
||||
"/api/v1/payments", json=real_invoice, headers=adminkey_headers_from
|
||||
|
|
@ -100,7 +99,7 @@ async def test_node_payments(node_client, real_invoice, adminkey_headers_from):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_channel_management(node_client):
|
||||
async def get_channels():
|
||||
response = await node_client.get("/node/api/v1/channels")
|
||||
|
|
@ -147,7 +146,7 @@ async def test_channel_management(node_client):
|
|||
mine_blocks(5)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_peer_management(node_client):
|
||||
connect_uri = get_unconnected_node_uri()
|
||||
peer_id = connect_uri.split("@")[0]
|
||||
|
|
@ -171,7 +170,7 @@ async def test_peer_management(node_client):
|
|||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_connect_invalid_uri(node_client):
|
||||
response = await node_client.post("/node/api/v1/peers", json={"uri": "invalid"})
|
||||
assert response.status_code == 400
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ import asyncio
|
|||
import pytest
|
||||
|
||||
from lnbits.utils.cache import Cache
|
||||
from tests.conftest import pytest_asyncio
|
||||
|
||||
key = "foo"
|
||||
value = "bar"
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
@pytest.fixture
|
||||
async def cache():
|
||||
cache = Cache(interval=0.1)
|
||||
|
||||
|
|
@ -18,7 +17,7 @@ async def cache():
|
|||
task.cancel()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_cache_get_set(cache):
|
||||
cache.set(key, value)
|
||||
assert cache.get(key) == value
|
||||
|
|
@ -26,7 +25,7 @@ async def test_cache_get_set(cache):
|
|||
assert cache.get("i-dont-exist", default="default") == "default"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_cache_expiry(cache):
|
||||
# gets expired by `get` call
|
||||
cache.set(key, value, expiry=0.01)
|
||||
|
|
@ -40,7 +39,7 @@ async def test_cache_expiry(cache):
|
|||
assert not cache.get(key)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_cache_pop(cache):
|
||||
cache.set(key, value)
|
||||
assert cache.pop(key) == value
|
||||
|
|
@ -48,7 +47,7 @@ async def test_cache_pop(cache):
|
|||
assert cache.pop(key, default="a") == "a"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_cache_coro(cache):
|
||||
called = 0
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from lnbits.core.crud import (
|
|||
from lnbits.db import POSTGRES
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_date_conversion(db):
|
||||
if db.type == POSTGRES:
|
||||
row = await db.fetchone("SELECT now()::date as now")
|
||||
|
|
@ -19,7 +19,7 @@ async def test_date_conversion(db):
|
|||
|
||||
|
||||
# make test to create wallet and delete wallet
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_wallet_and_delete_wallet(app, to_user):
|
||||
# create wallet
|
||||
wallet = await create_wallet(user_id=to_user.id, wallet_name="test_wallet_delete")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from tests.helpers import DbTestModel
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
@pytest.fixture(scope="session")
|
||||
async def fetch_page(db):
|
||||
await db.execute("DROP TABLE IF EXISTS test_db_fetch_page")
|
||||
await db.execute(
|
||||
|
|
@ -30,7 +29,7 @@ async def fetch_page(db):
|
|||
await db.execute("DROP TABLE test_db_fetch_page")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_db_fetch_page_simple(fetch_page, db):
|
||||
row = await db.fetch_page(
|
||||
query="select * from test_db_fetch_page",
|
||||
|
|
@ -42,7 +41,7 @@ async def test_db_fetch_page_simple(fetch_page, db):
|
|||
assert len(row.data) == 5
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_db_fetch_page_group_by(fetch_page, db):
|
||||
row = await db.fetch_page(
|
||||
query="select max(id) as id, name from test_db_fetch_page",
|
||||
|
|
@ -53,7 +52,7 @@ async def test_db_fetch_page_group_by(fetch_page, db):
|
|||
assert row.total == 4
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_db_fetch_page_group_by_multiple(fetch_page, db):
|
||||
row = await db.fetch_page(
|
||||
query="select max(id) as id, name, value from test_db_fetch_page",
|
||||
|
|
@ -64,7 +63,7 @@ async def test_db_fetch_page_group_by_multiple(fetch_page, db):
|
|||
assert row.total == 5
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_db_fetch_page_group_by_evil(fetch_page, db):
|
||||
with pytest.raises(ValueError, match="Value for GROUP BY is invalid"):
|
||||
await db.fetch_page(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ test_data = DbTestModel3(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_helpers_insert_query():
|
||||
q = insert_query("test_helpers_query", test_data)
|
||||
assert q == (
|
||||
|
|
@ -36,7 +36,7 @@ async def test_helpers_insert_query():
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_helpers_update_query():
|
||||
q = update_query("test_helpers_query", test_data)
|
||||
assert q == (
|
||||
|
|
@ -65,7 +65,7 @@ test_dict = {
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_helpers_model_to_dict():
|
||||
d = model_to_dict(test_data)
|
||||
assert d.get("id") == test_data.id
|
||||
|
|
@ -75,7 +75,7 @@ async def test_helpers_model_to_dict():
|
|||
assert d == test_dict
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_helpers_dict_to_model():
|
||||
m = dict_to_model(test_dict, DbTestModel3)
|
||||
assert m == test_data
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ from lnbits.wallets.base import PaymentResponse
|
|||
from lnbits.wallets.fake import FakeWallet
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_bolt11(to_wallet):
|
||||
@pytest.mark.anyio
|
||||
async def test_invalid_bolt11(to_wallet: Wallet):
|
||||
with pytest.raises(PaymentError):
|
||||
await pay_invoice(
|
||||
wallet_id=to_wallet.id,
|
||||
|
|
@ -31,7 +31,7 @@ async def test_invalid_bolt11(to_wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_amountless_invoice(to_wallet: Wallet):
|
||||
zero_amount_invoice = (
|
||||
"lnbc1pnsu5z3pp57getmdaxhg5kc9yh2a2qsh7cjf4gnccgkw0qenm8vsqv50w7s"
|
||||
|
|
@ -47,7 +47,7 @@ async def test_amountless_invoice(to_wallet: Wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_bad_wallet_id(to_wallet: Wallet):
|
||||
payment = await create_invoice(wallet_id=to_wallet.id, amount=31, memo="Bad Wallet")
|
||||
bad_wallet_id = to_wallet.id[::-1]
|
||||
|
|
@ -60,11 +60,10 @@ async def test_bad_wallet_id(to_wallet: Wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_payment_limit(to_wallet: Wallet):
|
||||
payment = await create_invoice(wallet_id=to_wallet.id, amount=101, memo="")
|
||||
with pytest.raises(PaymentError, match="Amount in invoice is too high."):
|
||||
|
||||
await pay_invoice(
|
||||
wallet_id=to_wallet.id,
|
||||
max_sat=100,
|
||||
|
|
@ -72,7 +71,7 @@ async def test_payment_limit(to_wallet: Wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_twice(to_wallet: Wallet):
|
||||
payment = await create_invoice(wallet_id=to_wallet.id, amount=3, memo="Twice")
|
||||
await pay_invoice(
|
||||
|
|
@ -86,7 +85,7 @@ async def test_pay_twice(to_wallet: Wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fake_wallet_pay_external(
|
||||
to_wallet: Wallet, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -101,7 +100,7 @@ async def test_fake_wallet_pay_external(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_invoice_changed(to_wallet: Wallet):
|
||||
payment = await create_invoice(wallet_id=to_wallet.id, amount=21, memo="original")
|
||||
|
||||
|
|
@ -126,7 +125,7 @@ async def test_invoice_changed(to_wallet: Wallet):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_for_extension(to_wallet: Wallet, settings: Settings):
|
||||
payment = await create_invoice(wallet_id=to_wallet.id, amount=3, memo="Allowed")
|
||||
await pay_invoice(
|
||||
|
|
@ -144,7 +143,7 @@ async def test_pay_for_extension(to_wallet: Wallet, settings: Settings):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_notification_for_internal_payment(to_wallet: Wallet):
|
||||
test_name = "test_notification_for_internal_payment"
|
||||
|
||||
|
|
@ -168,7 +167,7 @@ async def test_notification_for_internal_payment(to_wallet: Wallet):
|
|||
break # we found our payment, success
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_failed(
|
||||
to_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -194,7 +193,7 @@ async def test_pay_failed(
|
|||
assert payment.amount == -2101_000
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_retry_failed_invoice(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -264,7 +263,7 @@ async def test_retry_failed_invoice(
|
|||
assert ws_notification.call_count == 0, "Websocket notification not sent."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_external_invoice_pending(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -310,7 +309,7 @@ async def test_pay_external_invoice_pending(
|
|||
assert ws_notification.call_count == 0, "Websocket notification not sent."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_retry_pay_external_invoice_pending(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -355,7 +354,7 @@ async def test_retry_pay_external_invoice_pending(
|
|||
assert ws_notification.call_count == 0, "Websocket notification not sent."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_external_invoice_success(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -401,7 +400,7 @@ async def test_pay_external_invoice_success(
|
|||
assert ws_notification.call_count == 1, "Websocket notification sent."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_retry_pay_success(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -446,7 +445,7 @@ async def test_retry_pay_success(
|
|||
assert ws_notification.call_count == 1, "No new websocket notification sent."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_external_invoice_success_bad_checking_id(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -479,7 +478,7 @@ async def test_pay_external_invoice_success_bad_checking_id(
|
|||
assert payment.status == PaymentState.SUCCESS.value
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_no_checking_id(
|
||||
from_wallet: Wallet, mocker: MockerFixture, external_funding_source: FakeWallet
|
||||
):
|
||||
|
|
@ -512,7 +511,7 @@ async def test_no_checking_id(
|
|||
assert payment.status == PaymentState.PENDING.value
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_service_fee(
|
||||
from_wallet: Wallet,
|
||||
to_wallet: Wallet,
|
||||
|
|
@ -552,7 +551,7 @@ async def test_service_fee(
|
|||
assert _payment.preimage == preimage
|
||||
|
||||
service_fee_payment = await get_standalone_payment(
|
||||
f"service_fee_{payment.payment_hash}"
|
||||
f"service_fee_{payment.payment_hash}",
|
||||
)
|
||||
assert service_fee_payment
|
||||
assert service_fee_payment.status == PaymentState.SUCCESS.value
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ from lnbits.core.services import (
|
|||
from lnbits.settings import Settings
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fee_reserve_internal(settings: Settings):
|
||||
fee = settings.fee_reserve(10_000, internal=True)
|
||||
assert fee == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fee_reserve_min(settings: Settings):
|
||||
settings.lnbits_reserve_fee_percent = 2
|
||||
settings.lnbits_reserve_fee_min = 500
|
||||
|
|
@ -21,7 +21,7 @@ async def test_fee_reserve_min(settings: Settings):
|
|||
assert fee == 500
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fee_reserve_percent(settings: Settings):
|
||||
settings.lnbits_reserve_fee_percent = 1
|
||||
settings.lnbits_reserve_fee_min = 100
|
||||
|
|
@ -29,14 +29,14 @@ async def test_fee_reserve_percent(settings: Settings):
|
|||
assert fee == 1000
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_service_fee_no_wallet(settings: Settings):
|
||||
settings.lnbits_service_fee_wallet = ""
|
||||
fee = service_fee(10000)
|
||||
assert fee == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_service_fee_internal(settings: Settings):
|
||||
settings.lnbits_service_fee_wallet = "wallet_id"
|
||||
settings.lnbits_service_fee_ignore_internal = True
|
||||
|
|
@ -44,7 +44,7 @@ async def test_service_fee_internal(settings: Settings):
|
|||
assert fee == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_service_fee(settings: Settings):
|
||||
settings.lnbits_service_fee_wallet = "wallet_id"
|
||||
settings.lnbits_service_fee = 2
|
||||
|
|
@ -52,7 +52,7 @@ async def test_service_fee(settings: Settings):
|
|||
assert fee == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_service_fee_max(settings: Settings):
|
||||
settings.lnbits_service_fee_wallet = "wallet_id"
|
||||
settings.lnbits_service_fee = 2
|
||||
|
|
@ -61,7 +61,7 @@ async def test_service_fee_max(settings: Settings):
|
|||
assert fee / 1000 == 199
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_fee_reserve_total(settings: Settings):
|
||||
settings.lnbits_reserve_fee_percent = 1
|
||||
settings.lnbits_reserve_fee_min = 100
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from lnbits.core.services.payments import check_wallet_daily_withdraw_limit
|
|||
from lnbits.settings import Settings
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_no_wallet_limit(settings: Settings):
|
||||
settings.lnbits_wallet_limit_daily_max_withdraw = 0
|
||||
result = await check_wallet_daily_withdraw_limit(
|
||||
|
|
@ -14,7 +14,7 @@ async def test_no_wallet_limit(settings: Settings):
|
|||
assert result is None, "No limit set."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_wallet_limit_but_no_payments(settings: Settings):
|
||||
settings.lnbits_wallet_limit_daily_max_withdraw = 5
|
||||
result = await check_wallet_daily_withdraw_limit(
|
||||
|
|
@ -24,7 +24,7 @@ async def test_wallet_limit_but_no_payments(settings: Settings):
|
|||
assert result is None, "Limit not reqached."
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_no_wallet_spend_allowed(settings: Settings):
|
||||
settings.lnbits_wallet_limit_daily_max_withdraw = -1
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def outbound_bolt11():
|
|||
return bolt11
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_environment_variables():
|
||||
if use_real_api:
|
||||
assert "X-API-KEY" in headers, "X-API-KEY is not present in headers"
|
||||
|
|
@ -56,7 +56,7 @@ async def test_environment_variables():
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_wallet_id():
|
||||
if use_real_api:
|
||||
wallet_id = await funding_source._init_wallet_id()
|
||||
|
|
@ -66,7 +66,7 @@ async def test_get_wallet_id():
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_status():
|
||||
if use_real_api:
|
||||
status = await funding_source.status()
|
||||
|
|
@ -76,7 +76,7 @@ async def test_status():
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_create_invoice():
|
||||
if use_real_api:
|
||||
invoice_response = await funding_source.create_invoice(amount=1000, memo="test")
|
||||
|
|
@ -107,7 +107,7 @@ async def test_create_invoice():
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_pay_invoice_self_payment():
|
||||
if use_real_api:
|
||||
invoice_response = await funding_source.create_invoice(amount=100, memo="test")
|
||||
|
|
@ -122,7 +122,7 @@ async def test_pay_invoice_self_payment():
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_outbound_invoice_payment(outbound_bolt11):
|
||||
if use_real_api:
|
||||
payment_response = await funding_source.pay_invoice(
|
||||
|
|
@ -138,7 +138,7 @@ async def test_outbound_invoice_payment(outbound_bolt11):
|
|||
assert True, "BLINK_TOKEN is not set. Skipping test using mock api"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
async def test_get_payment_status(payhash):
|
||||
if use_real_api:
|
||||
payment_status = await funding_source.get_payment_status(payhash)
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ async def run(data: WalletTest):
|
|||
await nwcwallet.cleanup()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"test_data",
|
||||
wallet_fixtures_from_json("tests/wallets/fixtures/json/fixtures_nwc.json"),
|
||||
|
|
@ -184,7 +184,7 @@ async def test_nwc_wallet(test_data: WalletTest):
|
|||
await run(test_data)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"test_data",
|
||||
wallet_fixtures_from_json("tests/wallets/fixtures/json/fixtures_nwc_bad.json"),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def httpserver_listen_address():
|
|||
return ("127.0.0.1", 8555)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"test_data",
|
||||
wallet_fixtures_from_json("tests/wallets/fixtures/json/fixtures_rest.json"),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from tests.wallets.helpers import (
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"test_data",
|
||||
wallet_fixtures_from_json("tests/wallets/fixtures/json/fixtures_rpc.json"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue