# Path: modernrpc/exceptions.py
# RPC_METHOD_NOT_FOUND = -32601
# 
# RPC_INVALID_PARAMS = -32602
# 
# RPC_CUSTOM_ERROR_BASE = -32099


import pytest
from modernrpc.exceptions import (
    RPC_METHOD_NOT_FOUND,
    RPC_INVALID_PARAMS,
    RPC_CUSTOM_ERROR_BASE,
)


def test_available_methods(jsonrpc_client, xmlrpc_client):
    methods_list = jsonrpc_client.call("system.listMethods")
    assert "json_only" in methods_list
    assert "xml_only" not in methods_list

    methods_list = xmlrpc_client.call("system.listMethods")
    assert "json_only" not in methods_list
    assert "xml_only" in methods_list


def test_specific_methods_return(jsonrpc_client, xmlrpc_client):
    assert jsonrpc_client.call("json_only") == "JSON only"
    assert xmlrpc_client.call("xml_only") == "XML only"


def test_specific_methods_not_found(jsonrpc_client, xmlrpc_client):
    exc_match = r'Method not found: "xml_only"'
    with pytest.raises(
        jsonrpc_client.error_response_exception, match=exc_match
    ) as exc_info:
        jsonrpc_client.call("xml_only")
    xmlrpc_client.assert_exception_code(exc_info.value, RPC_METHOD_NOT_FOUND)

    exc_match = r'Method not found: "json_only"'
    with pytest.raises(
        xmlrpc_client.error_response_exception, match=exc_match
    ) as exc_info:
        xmlrpc_client.call("json_only")

# Path: modernrpc/exceptions.py
# RPC_METHOD_NOT_FOUND = -32601
# 
# RPC_INVALID_PARAMS = -32602
# 
# RPC_CUSTOM_ERROR_BASE = -32099


# Path: tests/functional/test_protocol_specific.py
import pytest
from modernrpc.exceptions import (
    RPC_METHOD_NOT_FOUND,
    RPC_INVALID_PARAMS,
    RPC_CUSTOM_ERROR_BASE,
)



def test_available_methods(jsonrpc_client, xmlrpc_client):
    methods_list = jsonrpc_client.call("system.listMethods")
    assert "json_only" in methods_list
    assert "xml_only" not in methods_list

    methods_list = xmlrpc_client.call("system.listMethods")
    assert "json_only" not in methods_list
    assert "xml_only" in methods_list


def test_specific_methods_return(jsonrpc_client, xmlrpc_client):
    assert jsonrpc_client.call("json_only") == "JSON only"
    assert xmlrpc_client.call("xml_only") == "XML only"


def test_specific_methods_not_found(jsonrpc_client, xmlrpc_client):
    exc_match = r'Method not found: "xml_only"'
    with pytest.raises(
        jsonrpc_client.error_response_exception, match=exc_match
    ) as exc_info:
        jsonrpc_client.call("xml_only")
    xmlrpc_client.assert_exception_code(exc_info.value, RPC_METHOD_NOT_FOUND)

    exc_match = r'Method not found: "json_only"'
    with pytest.raises(
        xmlrpc_client.error_response_exception, match=exc_match
    ) as exc_info:
        xmlrpc_client.call("json_only")

    xmlrpc_client.assert_exception_code(exc_info.value, RPC_METHOD_NOT_FOUND)