chore: update to latest pytest (#2800)
This commit is contained in:
parent
8ff4962e86
commit
291c69e470
27 changed files with 303 additions and 310 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue