From 27635eba37c81f83fa38e59ce221fd1319958978 Mon Sep 17 00:00:00 2001 From: Lewis England Date: Thu, 10 Aug 2023 09:43:44 +0100 Subject: [PATCH] tests: add integration test for global_preferences * The test container does not return the global_preferences file, so errors * Have added some exception handling to the function in case Marshmallow validation fails relates-to: #61 --- src/boinc_client/boinc_client.py | 3 +++ src/boinc_client/preferences.py | 7 ++++++- tests/integration/test_boinc_client.py | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/boinc_client/boinc_client.py b/src/boinc_client/boinc_client.py index 81cede2..ca72394 100644 --- a/src/boinc_client/boinc_client.py +++ b/src/boinc_client/boinc_client.py @@ -126,5 +126,8 @@ def get_client_version(self) -> dict: def get_client_update(self) -> dict: return client_update(client=self.rpc_client) + ############## + # Preferences + ############## def get_global_prefs_file(self) -> dict: return get_global_prefs_file(self.rpc_client) diff --git a/src/boinc_client/preferences.py b/src/boinc_client/preferences.py index 15b5b77..fee8032 100644 --- a/src/boinc_client/preferences.py +++ b/src/boinc_client/preferences.py @@ -1,6 +1,8 @@ import xmltodict +from marshmallow import ValidationError from boinc_client.clients.rpc_client import RpcClient +from boinc_client.models.generic_response import GenericResponse from boinc_client.models.global_preferences import GlobalPreferences @@ -8,4 +10,7 @@ def get_global_prefs_file(client: RpcClient) -> dict: """Get the contents of the global_prefs.xml file if present.""" rpc_resp = client.make_request("") rpc_json = xmltodict.parse(rpc_resp) - return GlobalPreferences().load(rpc_json) + try: + return GlobalPreferences().load(rpc_json) + except ValidationError: + return GenericResponse().load(rpc_json) diff --git a/tests/integration/test_boinc_client.py b/tests/integration/test_boinc_client.py index 632740d..fd2feb2 100644 --- a/tests/integration/test_boinc_client.py +++ b/tests/integration/test_boinc_client.py @@ -142,6 +142,13 @@ def test_container_update(boinc_session_client): assert "update" in result +@mark.integration +def test_global_preferences(boinc_session_client): + result = boinc_session_client.get_global_prefs_file() + assert result + assert "error" in result # No global_preferences file available + + @mark.authenticated def test_can_attach_and_detach_project(boinc_test_client, project_weak_key): boinc_test_client.attach_project(