diff --git a/.gitignore b/.gitignore index 632f40a..ca9a1a1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ dist/ # Test Reports .coverage -cov/ \ No newline at end of file +cov/ + +boinc_client.log \ No newline at end of file diff --git a/src/boinc_client/boinc_client.py b/src/boinc_client/boinc_client.py index ba7f523..e8b70c3 100644 --- a/src/boinc_client/boinc_client.py +++ b/src/boinc_client/boinc_client.py @@ -2,6 +2,7 @@ from .messages import get_all_notices, message_count, messages, public_notices from .modes import set_cpu_run_mode, set_gpu_run_mode, set_network_mode +from .network import get_proxy_settings from .preferences import ( get_global_prefs_file, get_global_prefs_override, @@ -177,3 +178,6 @@ def set_gpu_run_mode(self, run_mode: str, duration: int = 0) -> dict: def set_network_mode(self, run_mode: str, duration: int = 0) -> dict: return set_network_mode(self.rpc_client, run_mode, duration) + + def get_proxy_settings(self) -> dict: + return get_proxy_settings(self.rpc_client) diff --git a/src/boinc_client/messages.py b/src/boinc_client/messages.py index 5d56aa2..89c51fb 100644 --- a/src/boinc_client/messages.py +++ b/src/boinc_client/messages.py @@ -1,6 +1,7 @@ import logging import xmltodict + from boinc_client.clients.rpc_client import RpcClient from boinc_client.models.message_count import MessageCount from boinc_client.models.messages import Messages diff --git a/src/boinc_client/models/proxy_settings.py b/src/boinc_client/models/proxy_settings.py new file mode 100644 index 0000000..4ce112a --- /dev/null +++ b/src/boinc_client/models/proxy_settings.py @@ -0,0 +1,25 @@ +from marshmallow import Schema, fields + + +class ProxySettings(Schema): + autodetect_port = fields.Str() + autodetect_protocol = fields.Str() + autodetect_server_name = fields.Str() + http_server_name = fields.Str(allow_none=True) + http_server_port = fields.Int(allow_none=True) + http_user_name = fields.Str(allow_none=True) + http_user_passwd = fields.Str(allow_none=True) + no_autodetect = fields.Str(allow_none=True) + no_proxy = fields.Str(allow_none=True) + socks5_remote_dns = fields.Str(allow_none=True) + socks5_user_name = fields.Str(allow_none=True) + socks5_user_passwd = fields.Str(allow_none=True) + socks_server_name = fields.Str(allow_none=True) + socks_server_port = fields.Int(allow_none=True) + use_http_auth = fields.Str() + use_http_proxy = fields.Str() + use_socks_proxy = fields.Str() + + +class ProxyInfo(Schema): + proxy_info = fields.Nested(ProxySettings()) diff --git a/src/boinc_client/network.py b/src/boinc_client/network.py new file mode 100644 index 0000000..62e8a16 --- /dev/null +++ b/src/boinc_client/network.py @@ -0,0 +1,10 @@ +import xmltodict + +from boinc_client.clients.rpc_client import RpcClient +from boinc_client.models.proxy_settings import ProxyInfo + + +def get_proxy_settings(client: RpcClient) -> dict: + rpc_resp = client.make_request("") + rpc_json = xmltodict.parse(rpc_resp) + return ProxyInfo().load(rpc_json) diff --git a/src/boinc_client/preferences.py b/src/boinc_client/preferences.py index 00c72ce..2ab10ae 100644 --- a/src/boinc_client/preferences.py +++ b/src/boinc_client/preferences.py @@ -9,7 +9,7 @@ from boinc_client.models.global_preferences import GlobalPreferences logger = logging.getLogger(__name__) -logging.basicConfig(filename='boinc_client.log', encoding='utf-8', level=logging.DEBUG) +logging.basicConfig(filename="boinc_client.log", encoding="utf-8", level=logging.DEBUG) def get_global_prefs_file(client: RpcClient) -> dict: diff --git a/tests/integration/test_boinc_client.py b/tests/integration/test_boinc_client.py index 825a6fa..f55ea84 100644 --- a/tests/integration/test_boinc_client.py +++ b/tests/integration/test_boinc_client.py @@ -280,7 +280,7 @@ def test_can_sequentially_set_global_overrides(boinc_test_client, project_weak_k @mark.authenticated -def test_can_set_compute_modes(boinc_test_client, project_weak_key): +def test_can_set_compute_modes(boinc_test_client): assert boinc_test_client.set_cpu_run_mode("always", 60) == {"success": True} assert boinc_test_client.set_gpu_run_mode("auto", 0) == {"success": True} assert boinc_test_client.set_network_mode("never") == {"success": True} diff --git a/tests/network/__init__.py b/tests/network/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/network/conftest.py b/tests/network/conftest.py new file mode 100644 index 0000000..437b507 --- /dev/null +++ b/tests/network/conftest.py @@ -0,0 +1,37 @@ +from pytest import fixture + + +@fixture +def proxy_settings_xml() -> str: + return """ + foo + foo + foo + foo + foo + foo + foo + foo + foo + foo + foo + """ + + +@fixture +def proxy_settings_dict() -> dict: + return { + "proxy_info": { + "socks_server_name": "foo", + "socks_server_port": "foo", + "http_server_name": "foo", + "http_server_port": "foo", + "socks5_user_name": "foo", + "socks5_user_passwd": "foo", + "socks5_remote_dns": "foo", + "http_user_name": "foo", + "http_user_passwd": "foo", + "no_autodetect": "foo", + "no_proxy": "foo", + } + } diff --git a/tests/network/test_network.py b/tests/network/test_network.py new file mode 100644 index 0000000..6dea790 --- /dev/null +++ b/tests/network/test_network.py @@ -0,0 +1,12 @@ +from boinc_client.network import get_proxy_settings + + +def test_can_get_proxy_settings( + mocker, mock_rpc_client, proxy_settings_xml, proxy_settings_dict +): + mocker.patch( + "boinc_client.clients.rpc_client.RpcClient.make_request", + return_value=proxy_settings_xml, + ) + assert get_proxy_settings(client=mock_rpc_client) == proxy_settings_dict + assert True