chore: update to latest pytest (#2800)

This commit is contained in:
dni ⚡ 2024-12-11 10:39:28 +01:00 committed by GitHub
parent 8ff4962e86
commit 291c69e470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 303 additions and 310 deletions

View file

@ -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}",

View file

@ -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",
[

View file

@ -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
):

View file

@ -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

View file

@ -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

View file

@ -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",