Exemple #1
0
def test_safe_call_success_response():
    response = safe_call(Request(method="ping", id=1),
                         Methods(ping),
                         debug=True)
    assert isinstance(response, SuccessResponse)
    assert response.result == "pong"
    assert response.id == 1
Exemple #2
0
def test_call_requests_with_context():
    def ping_with_context(context=None):
        assert context is sentinel.context

    call_requests(
        Request("ping_with_context", convert_camel_case=False),
        Methods(ping_with_context),
        debug=True,
    )
Exemple #3
0
def test_request_convert_camel_case():
    request = Request(**{
        "jsonrpc": "2.0",
        "method": "fooBar",
        "params": {
            "fooBar": 1
        }
    },
                      convert_camel_case=True)
    assert request.method == "foo_bar"
Exemple #4
0
def test_call_requests_batch_all_notifications():
    """Should return a BatchResponse response, an empty list"""
    response = call_requests(
        {
            Request(**{
                "jsonrpc": "2.0",
                "method": "notify_sum",
                "params": [1, 2, 4]
            }),
            Request(**{
                "jsonrpc": "2.0",
                "method": "notify_hello",
                "params": [7]
            }),
        },
        Methods(ping),
        debug=True,
    )
    assert str(response) == ""
Exemple #5
0
def test_request_no_args():
    req = Request(method="foo")
    assert req.args == []
    assert req.kwargs == {}
Exemple #6
0
def test_notification_false():
    request = Request(method="foo", id=99)
    assert request.is_notification is False
Exemple #7
0
def test_notification_true():
    request = Request(method="foo")
    assert request.is_notification is True
Exemple #8
0
def test_request():
    assert Request(method="foo").method == "foo"
Exemple #9
0
def test_request_from_string():
    request = Request(
        **json.loads('{"jsonrpc": "2.0", "method": "foo", "id": 1}'))
    assert request.jsonrpc == "2.0"
    assert request.method == "foo"
    assert request.id == 1
Exemple #10
0
def test_request_id():
    assert Request(method="foo", id=99).id == 99
Exemple #11
0
def test_safe_call_invalid_args():
    response = safe_call(Request(method="ping", params=[1], id=1),
                         Methods(ping),
                         debug=True)
    assert isinstance(response, InvalidParamsResponse)
Exemple #12
0
def test_safe_call_method_not_found():
    response = safe_call(Request(method="nonexistant", id=1),
                         Methods(ping),
                         debug=True)
    assert isinstance(response, MethodNotFoundResponse)
Exemple #13
0
def test_safe_call_notification_failure():
    def fail():
        raise ValueError()

    response = safe_call(Request(method="foo"), Methods(fail), debug=True)
    assert isinstance(response, NotificationResponse)
Exemple #14
0
def test_safe_call_notification():
    response = safe_call(Request(method="ping"), Methods(ping), debug=True)
    assert isinstance(response, NotificationResponse)
Exemple #15
0
def test_request_positional_args():
    req = Request(method="foo", params=[2, 3])
    assert req.args == [2, 3]
    assert req.kwargs == {}
Exemple #16
0
def test_request_keyword_args():
    req = Request(method="foo", params={"foo": "bar"})
    assert req.args == []
    assert req.kwargs == {"foo": "bar"}
Exemple #17
0
def test_request_no_id():
    request = Request({"jsonrpc": "2.0", "method": "foo"})
    assert request.id is NOID