test: wip
This commit is contained in:
parent
855ec09df3
commit
90cdfc61fb
2 changed files with 46 additions and 3 deletions
42
tests/test_clients.py
Normal file
42
tests/test_clients.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
from typing import Any, Optional
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from fastapi import WebSocket
|
||||
from unittest import mock
|
||||
|
||||
from lnbits.extensions.nostrrelay.client_manager import NostrClientConnection, NostrClientManager
|
||||
|
||||
def simple_urandom():
|
||||
# print('### simple_urandom', x)
|
||||
return 3
|
||||
|
||||
class MockWebSocket(WebSocket):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
async def accept(self):
|
||||
print('### mock accept')
|
||||
|
||||
async def receive_text(self) -> str:
|
||||
print('### mock receive_text')
|
||||
return "mock_receive_data"
|
||||
|
||||
async def send_text(self, s:str):
|
||||
print('### mock send_text',s)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@mock.patch('os.listdir', side_effect=simple_urandom)
|
||||
async def test_xxx(value):
|
||||
print('### test_xxx', value)
|
||||
client_manager = NostrClientManager()
|
||||
|
||||
v = os.listdir()
|
||||
print('### os.listdir', v)
|
||||
websocket = MockWebSocket()
|
||||
client = NostrClientConnection(websocket=websocket)
|
||||
client_manager.add_client(client)
|
||||
await client.start()
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from typing import List, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
from typing import List, Optional
|
||||
from loguru import logger
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -49,10 +49,11 @@ async def test_valid_event_crud(valid_events: List[EventFixture]):
|
|||
reply_event_id = "6b2b6cb9c72caaf3dfbc5baa5e68d75ac62f38ec011b36cc83832218c36e4894"
|
||||
all_events = [f.data for f in valid_events]
|
||||
|
||||
# insert all events in DB before doing an query
|
||||
for e in all_events:
|
||||
await create_event(RELAY_ID, e)
|
||||
|
||||
# insert all events before doing an query
|
||||
|
||||
for f in valid_events:
|
||||
await get_by_id(f.data, f.name)
|
||||
await filter_by_id(all_events, f.data, f.name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue