Skip to content

Commit

Permalink
tests: add integration test for global_preferences
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SplinterHead committed Aug 10, 2023
1 parent 766847a commit 27635eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/boinc_client/boinc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 6 additions & 1 deletion src/boinc_client/preferences.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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


def get_global_prefs_file(client: RpcClient) -> dict:
"""Get the contents of the global_prefs.xml file if present."""
rpc_resp = client.make_request("<get_global_prefs_file/>")
rpc_json = xmltodict.parse(rpc_resp)
return GlobalPreferences().load(rpc_json)
try:
return GlobalPreferences().load(rpc_json)
except ValidationError:
return GenericResponse().load(rpc_json)
7 changes: 7 additions & 0 deletions tests/integration/test_boinc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 27635eb

Please sign in to comment.