Skip to content

Commit

Permalink
added cli unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jell-o-fishi committed Oct 21, 2023
1 parent 1e7eb8e commit b1bd9bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def pipe_tcp(unused_tcp_port):


@pytest.fixture
async def lazy_pipe_tcp(aiohttp_raw_server, unused_tcp_port): # noqa: F811
async def lazy_pipe_tcp(unused_tcp_port): # noqa: F811
logging.info('Testing transport tcp (explicitly) on port %s (lazy)', unused_tcp_port)

yield functools.partial(pipe_factory_tcp, unused_tcp_port)
Expand Down
43 changes: 41 additions & 2 deletions tests/rsocket/test_cli_command.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import io
import sys
import tempfile
from asyncio import sleep

import pytest
from asyncclick.testing import CliRunner
from decoy import Decoy

from rsocket.awaitable.awaitable_rsocket import AwaitableRSocket
from rsocket.cli.command import parse_uri, build_composite_metadata, create_request_payload, get_metadata_value, \
create_setup_payload, normalize_data, normalize_limit_rate, RequestType, get_request_type, parse_headers, \
normalize_metadata_mime_type, execute_request
normalize_metadata_mime_type, execute_request, command
from rsocket.extensions.helpers import route, authenticate_simple, authenticate_bearer
from rsocket.extensions.mimetypes import WellKnownMimeTypes
from rsocket.frame import MAX_REQUEST_N
from rsocket.helpers import create_future
from rsocket.helpers import create_future, create_response
from rsocket.payload import Payload
from rsocket.request_handler import BaseRequestHandler
from tests.rsocket.helpers import create_data
from tests.tools.fixtures_quart import pipe_factory_quart_websocket
from tests.tools.fixtures_tcp import pipe_factory_tcp


def test_parse_uri():
Expand Down Expand Up @@ -218,3 +223,37 @@ async def test_execute_request_fnf(decoy: Decoy):
result = await execute_request(client, RequestType.fnf, 3, Payload())

assert result is None


async def test_execute_command_tcp_request(unused_tcp_port):
class Handler(BaseRequestHandler):
async def request_response(self, request: Payload):
await sleep(4)
return create_response(b'response from test')

async with pipe_factory_tcp(unused_tcp_port,
client_arguments={},
server_arguments={'handler_factory': Handler}):
runner = CliRunner()
uri = f'tcp://localhost:{unused_tcp_port}'
result = await runner.invoke(command, ['--request', uri])

assert result.stdout == 'response from test\n'
assert result.exit_code == 0


async def test_execute_command_websocket_request(unused_tcp_port):
class Handler(BaseRequestHandler):
async def request_response(self, request: Payload):
await sleep(4)
return create_response(b'response from test')

async with pipe_factory_quart_websocket(unused_tcp_port,
client_arguments={},
server_arguments={'handler_factory': Handler}):
runner = CliRunner()
uri = f'ws://localhost:{unused_tcp_port}'
result = await runner.invoke(command, ['--request', uri])

assert result.stdout == 'response from test\n'
assert result.exit_code == 0

0 comments on commit b1bd9bc

Please sign in to comment.