Skip to content

Commit 0bc2010

Browse files
committed
cli - added unit tests
1 parent 83ff73b commit 0bc2010

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

tests/rsocket/test_cli_command.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
import sys
33
import tempfile
44

5+
import pytest
6+
57
from rsocket.cli.command import parse_uri, build_composite_metadata, create_request_payload, get_metadata_value, \
6-
create_setup_payload, normalize_data, normalize_limit_rate
8+
create_setup_payload, normalize_data, normalize_limit_rate, RequestType, get_request_type, parse_headers
9+
from rsocket.extensions.helpers import route, authenticate_simple, authenticate_bearer
710
from rsocket.frame import MAX_REQUEST_N
811
from tests.rsocket.helpers import create_data
912

@@ -25,12 +28,21 @@ def test_parse_uri_wss():
2528
assert parsed.path == 'path'
2629

2730

28-
def test_build_composite_metadata():
29-
composite = build_composite_metadata(
30-
None, None, None
31-
)
31+
@pytest.mark.parametrize('route_path, auth_simple, auth_bearer, expected', (
32+
(None, None, None, []),
33+
('path1', None, None, [route('path1')]),
34+
('path1', 'user:pass', None, [route('path1'), authenticate_simple('user', 'pass')]),
35+
('path1', None, 'token', [route('path1'), authenticate_bearer('token')]),
36+
('path1', 'user:pass', 'token', Exception),
37+
))
38+
def test_build_composite_metadata(route_path, auth_simple, auth_bearer, expected):
39+
if isinstance(expected, list):
40+
actual = build_composite_metadata(auth_simple, route_path, auth_bearer)
3241

33-
assert len(composite) == 0
42+
assert actual == expected
43+
else:
44+
with pytest.raises(expected):
45+
build_composite_metadata(auth_simple, route_path, auth_bearer)
3446

3547

3648
def test_create_request_payload():
@@ -100,3 +112,34 @@ def test_normalize_limit_rate():
100112
result = normalize_limit_rate(None)
101113

102114
assert result == MAX_REQUEST_N
115+
116+
117+
@pytest.mark.parametrize('is_request, stream, fnf, metadata_push, channel, interaction_model, expected', (
118+
(True, None, None, None, None, None, RequestType.response),
119+
(None, True, None, None, None, None, RequestType.stream),
120+
(None, None, True, None, None, None, RequestType.fnf),
121+
(None, None, None, True, None, None, RequestType.metadata_push),
122+
(None, None, None, None, True, None, RequestType.channel),
123+
(None, None, None, None, None, 'request_channel', RequestType.channel),
124+
(None, None, None, None, True, RequestType.response, Exception),
125+
(None, None, None, True, True, None, Exception),
126+
))
127+
def test_get_request_type(is_request, stream, fnf, metadata_push, channel, interaction_model, expected):
128+
if isinstance(expected, RequestType):
129+
actual = get_request_type(is_request, stream, fnf, metadata_push, channel, interaction_model)
130+
131+
assert actual == expected
132+
else:
133+
with pytest.raises(expected):
134+
get_request_type(is_request, stream, fnf, metadata_push, channel, interaction_model)
135+
136+
137+
@pytest.mark.parametrize('headers, expected', (
138+
(None, None),
139+
(['a=b'], {'a': 'b'}),
140+
([], None),
141+
))
142+
def test_parse_headers(headers, expected):
143+
actual = parse_headers(headers)
144+
145+
assert actual == expected

0 commit comments

Comments
 (0)