feat: extra log for tests phases (#2604)

* fix: set `corelightning_rest_cert`
* feat: extra log for tests phases

---------

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
dni ⚡
2024-07-31 11:40:25 +02:00
committed by GitHub
parent 0387db3b55
commit b41705167f
3 changed files with 46 additions and 14 deletions

View File

@@ -5,6 +5,7 @@
"settings": { "settings": {
"corelightning_rest_url": "http://127.0.0.1:8555", "corelightning_rest_url": "http://127.0.0.1:8555",
"corelightning_rest_macaroon": "eNcRyPtEdMaCaRoOn", "corelightning_rest_macaroon": "eNcRyPtEdMaCaRoOn",
"corelightning_rest_cert": false,
"user_agent": "LNbits/Tests" "user_agent": "LNbits/Tests"
} }
}, },

View File

@@ -3,6 +3,7 @@ from typing import Dict, Union
from urllib.parse import urlencode from urllib.parse import urlencode
import pytest import pytest
from loguru import logger
from pytest_httpserver import HTTPServer from pytest_httpserver import HTTPServer
from werkzeug.wrappers import Response from werkzeug.wrappers import Response
@@ -34,14 +35,27 @@ def httpserver_listen_address():
ids=build_test_id, ids=build_test_id,
) )
async def test_rest_wallet(httpserver: HTTPServer, test_data: WalletTest): async def test_rest_wallet(httpserver: HTTPServer, test_data: WalletTest):
if test_data.skip: test_id = build_test_id(test_data)
pytest.skip() logger.info(f"[{test_id}]: test start")
try:
if test_data.skip:
logger.info(f"[{test_id}]: test skip")
pytest.skip()
for mock in test_data.mocks: logger.info(f"[{test_id}]: apply {len(test_data.mocks)} mocks")
_apply_mock(httpserver, mock) for mock in test_data.mocks:
_apply_mock(httpserver, mock)
wallet = load_funding_source(test_data.funding_source) logger.info(f"[{test_id}]: load funding source")
await check_assertions(wallet, test_data) wallet = load_funding_source(test_data.funding_source)
logger.info(f"[{test_id}]: check assertions")
await check_assertions(wallet, test_data)
except Exception as exc:
logger.info(f"[{test_id}]: test failed: {exc}")
raise exc
finally:
logger.info(f"[{test_id}]: test end")
def _apply_mock(httpserver: HTTPServer, mock: Mock): def _apply_mock(httpserver: HTTPServer, mock: Mock):

View File

@@ -3,6 +3,7 @@ from typing import Dict, List, Optional
from unittest.mock import AsyncMock, Mock from unittest.mock import AsyncMock, Mock
import pytest import pytest
from loguru import logger
from pytest_mock.plugin import MockerFixture from pytest_mock.plugin import MockerFixture
from lnbits.core.models import BaseWallet from lnbits.core.models import BaseWallet
@@ -24,19 +25,35 @@ from tests.wallets.helpers import (
ids=build_test_id, ids=build_test_id,
) )
async def test_wallets(mocker: MockerFixture, test_data: WalletTest): async def test_wallets(mocker: MockerFixture, test_data: WalletTest):
if test_data.skip: test_id = build_test_id(test_data)
pytest.skip() logger.info(f"[{test_id}]: test start")
for mock in test_data.mocks: try:
_apply_rpc_mock(mocker, mock) if test_data.skip:
logger.info(f"[{test_id}]: test skip")
pytest.skip()
wallet = load_funding_source(test_data.funding_source) logger.info(f"[{test_id}]: apply {len(test_data.mocks)} mocks")
for mock in test_data.mocks:
_apply_rpc_mock(mocker, mock)
expected_calls = _spy_mocks(mocker, test_data, wallet) logger.info(f"[{test_id}]: load funding source")
wallet = load_funding_source(test_data.funding_source)
await check_assertions(wallet, test_data) logger.info(f"[{test_id}]: spy mocks")
expected_calls = _spy_mocks(mocker, test_data, wallet)
_check_calls(expected_calls) logger.info(f"[{test_id}]: check assertions")
await check_assertions(wallet, test_data)
logger.info(f"[{test_id}]: check calls")
_check_calls(expected_calls)
except Exception as exc:
logger.info(f"[{test_id}]: test failed: {exc}")
raise exc
finally:
logger.info(f"[{test_id}]: test end")
def _apply_rpc_mock(mocker: MockerFixture, mock: RpcMock): def _apply_rpc_mock(mocker: MockerFixture, mock: RpcMock):