From f6a92ce02924447f0c378939423dcb76dd85e4be Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 14:01:13 +0100 Subject: [PATCH 1/7] Fix upload to a public share path: send the ! of /SHARED/! unencoded urlencode() encodes the exclamation mark of a public share token as %21. The server expects it unencoded, as the web UI sends it. The fix-up in upload() never applied because it searched for "%%2FSHARED%2F%21" with a doubled percent sign, so uploads to a public upload-only share failed. Its guard was also always true since str.find() returns -1 when nothing matches. Replace "%2FSHARED%2F%21" with "%2FSHARED%2F!" in both the empty file and the chunked branch, and add unit tests for both branches plus a path outside /SHARED/ that keeps its encoded !. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/fcserver.py | 12 +++---- filecloudapi/tests/test_fcserver.py | 53 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 91aa095..193e8b6 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -849,10 +849,8 @@ def close(self): params_str = urlencode(params) - if params_str.find("%2FSHARED%2F%21"): - params_str = params_str.replace( - "%%2FSHARED%2F%21", "%2FSHARED%2F!" - ) # WEBUI DOES NOT ENCODE THE ! + # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!/...) + params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!") resp = self.session.post( self.url + "/core/upload?" + params_str, @@ -904,10 +902,8 @@ def close(self): params_str = urlencode(params) - if params_str.find("%2FSHARED%2F%21"): - params_str = params_str.replace( - "%%2FSHARED%2F%21", "%2FSHARED%2F!" - ) # WEBUI DOES NOT ENCODE THE ! + # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!/...) + params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!") if complete == 1: headers[SEND_ETAG_HEADER] = "1" diff --git a/filecloudapi/tests/test_fcserver.py b/filecloudapi/tests/test_fcserver.py index 3db1a6b..18d08fc 100644 --- a/filecloudapi/tests/test_fcserver.py +++ b/filecloudapi/tests/test_fcserver.py @@ -1,5 +1,58 @@ # Copyright (c) 2024 FileCloud. All Rights Reserved. +import datetime +from io import BufferedReader, BytesIO +from urllib.parse import parse_qs, urlsplit + +import pytest + +from filecloudapi.fcserver import FCServer + def test_noop(): pass + + +class _FakeResponse: + text = "OK" + headers = {"ETag": '"etag1"'} + + def raise_for_status(self): + pass + + +def _upload_and_capture_urls(serverpath: str, data: bytes) -> list[str]: + server = FCServer("https://fc.example.com/", None, "user", "pass", login=False) + urls: list[str] = [] + + def fake_post(url, **_kwargs): + urls.append(url) + return _FakeResponse() + + server.session.post = fake_post # type: ignore + server.upload( + BufferedReader(BytesIO(data)), # type: ignore + serverpath, + datetime.datetime(2024, 1, 1), + ) + return urls + + +# An empty upload and a non-empty upload build their query in separate branches +@pytest.mark.parametrize("data", [b"", b"data"]) +def test_upload_to_public_share_keeps_exclamation_mark_unencoded(data): + urls = _upload_and_capture_urls("/SHARED/!abc123/share1/file.txt", data) + + assert len(urls) == 1 + query = urlsplit(urls[0]).query + assert "path=%2FSHARED%2F!abc123%2Fshare1&" in query + assert "%21" not in query + assert parse_qs(query)["path"] == ["/SHARED/!abc123/share1"] + + +@pytest.mark.parametrize("data", [b"", b"data"]) +def test_upload_outside_public_share_keeps_exclamation_mark_encoded(data): + urls = _upload_and_capture_urls("/user/folder!1/file.txt", data) + + assert len(urls) == 1 + assert "path=%2Fuser%2Ffolder%211&" in urlsplit(urls[0]).query From c17785d90d6fdbf32a057a79cdbf244520ea3f3e Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 14:01:13 +0100 Subject: [PATCH 2/7] Increment version to 0.5.4 Co-Authored-By: Claude Opus 5.5 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3b4a2ee..b4a794c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "filecloudapi-python" -version = "0.5.3" +version = "0.5.4" description = "A Python library to connect to a Filecloud server" packages = [{ include = "filecloudapi" }] From 5f182c052b05410fb50277e92fa1cb421ba04e13 Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 17:14:49 +0100 Subject: [PATCH 3/7] Build the upload query in one helper so the empty file and chunked branches cannot drift apart Review comment on #22. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/fcserver.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 193e8b6..19423b1 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -197,6 +197,14 @@ def _extract_etag(self, etag: str): else: return etag + @staticmethod + def _upload_query(params: Dict) -> str: + """ + Encode the query of an upload request + """ + # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!/...) + return urlencode(params).replace("%2FSHARED%2F%21", "%2FSHARED%2F!") + def login(self) -> None: """ Try to login to FC server with the credentials @@ -847,10 +855,7 @@ def close(self): if ifetag is not None: params["ifetag"] = ifetag - params_str = urlencode(params) - - # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!/...) - params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!") + params_str = self._upload_query(params) resp = self.session.post( self.url + "/core/upload?" + params_str, @@ -900,10 +905,7 @@ def close(self): if data_size is not None: params["filesize"] = data_size - params_str = urlencode(params) - - # WEBUI DOES NOT ENCODE THE ! of a public share path (/SHARED/!/...) - params_str = params_str.replace("%2FSHARED%2F%21", "%2FSHARED%2F!") + params_str = self._upload_query(params) if complete == 1: headers[SEND_ETAG_HEADER] = "1" From 0bed0f0a1f1ebfdf0c4fa60585607ab7626b4195 Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 17:15:27 +0100 Subject: [PATCH 4/7] PolicyList and ServerSettings keep their entries per instance entries was a class attribute (a list in PolicyList, a dict in ServerSettings), so every instance in the process appended to the same object. A filtered get_all_policies returned the policies of all earlier listings and admin_get_config_settings returned the settings of earlier calls. Set entries in __init__ instead. Review comment on #22. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/datastructures.py | 8 +++-- filecloudapi/tests/test_datastructures.py | 38 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 filecloudapi/tests/test_datastructures.py diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index 5027624..c107286 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -255,7 +255,7 @@ class PolicyEntry: class PolicyList: """Convienience class represents policy list""" - entries: list[PolicyEntry] = [] + entries: list[PolicyEntry] def first(self) -> PolicyEntry | None: if len(self.entries) >= 1: @@ -267,6 +267,8 @@ def __iter__(self): def __init__(self, a_response: Element): """""" + # Per instance: a class level list collected the policies of every listing + self.entries = [] self._set_entries(response=a_response) def _set_entries(self, response: Element): @@ -286,13 +288,15 @@ def _set_entries(self, response: Element): class ServerSettings: """Convienience class represents server settings""" - entries: dict = {} + entries: dict def __iter__(self): return iter(self.entries) def __init__(self, a_response: Element): """""" + # Per instance: a class level dict collected the settings of every response + self.entries = {} self._set_entries(response=a_response) def _set_entries(self, response: Element): diff --git a/filecloudapi/tests/test_datastructures.py b/filecloudapi/tests/test_datastructures.py new file mode 100644 index 0000000..5d56eef --- /dev/null +++ b/filecloudapi/tests/test_datastructures.py @@ -0,0 +1,38 @@ +# Copyright (c) 2024 FileCloud. All Rights Reserved. + +import xml.etree.ElementTree as ET + +from filecloudapi.datastructures import PolicyList, ServerSettings + + +def _policies(*names: str) -> ET.Element: + policies = "".join( + f"id_{name}{name}" + for name in names + ) + return ET.fromstring(f"{policies}") + + +def _settings(**settings: str) -> ET.Element: + entries = "".join( + f"{name}{value}" + for name, value in settings.items() + ) + return ET.fromstring(f"{entries}") + + +def test_policy_list_holds_only_its_own_response(): + first = PolicyList(_policies("a")) + second = PolicyList(_policies("b")) + + assert [p.policyname for p in first] == ["a"] + assert [p.policyname for p in second] == ["b"] + assert second.first().policyid == "id_b" # type: ignore + + +def test_server_settings_hold_only_their_own_response(): + first = ServerSettings(_settings(TONIDOCLOUD_A="1")) + second = ServerSettings(_settings(TONIDOCLOUD_B="2")) + + assert first.entries == {"TONIDOCLOUD_A": "1"} + assert second.entries == {"TONIDOCLOUD_B": "2"} From 139c1b9e1c69116e05ec7a11678d332f1819f25f Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 17:17:13 +0100 Subject: [PATCH 5/7] Add the server wrappers the FCD integration tests work around - admin_createnewgroup returns the group id the server answers with - deleteshare takes adminproxyuserid, so a share owned by another user (for example a team folder share) can be deleted through the admin proxy - New wrappers: updateshare, deleteuserfromshare, getsystemstatus (appversion and uploadchunksize as SystemStatus), admin_deletememberfromgroup, admin_addusertoexternal, admin_deleteuserfromexternal, admin_deleteexternal - FileListEntry carries createdepochutc (getfilelist and fileinfo, servers 23.253 and later) and systemcreatedepochutc (fileinfo, when the server stores the OS creation date). Both default to "" so code that builds a FileListEntry positionally keeps working. updateshare answers with the share on success and with a meta error or a command result on failure, both raise ServerError. The others answer with a command result. Unit tests check the request each wrapper sends and that a failed command raises. Review comment on #22. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/datastructures.py | 13 ++ filecloudapi/fcserver.py | 121 +++++++++++++++++- filecloudapi/tests/test_fcserver.py | 184 ++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+), 4 deletions(-) diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index c107286..e5d2151 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -47,6 +47,11 @@ class FileListEntry: issyncable: bool isdatasyncable: bool etag: ETag + # Empty when the server does not report them: createdepochutc (getfilelist + # and fileinfo, 23.253 and later), systemcreatedepochutc (fileinfo, only when + # the server stores the OS creation date) + createdepochutc: str = "" + systemcreatedepochutc: str = "" @dataclass @@ -309,6 +314,14 @@ def _set_entries(self, response: Element): self.entries[list(elem)[0].text] = list(elem)[1].text +@dataclass +class SystemStatus: + """Fields of getsystemstatus, empty when the server does not report them""" + + appversion: str + uploadchunksize: str + + @dataclass class StorageRootDetails: type: str diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 19423b1..9401ecc 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -40,6 +40,7 @@ SortDir, SyncDeltaItem, SyncFolder, + SystemStatus, TeamFolderInfo, UserStatus, ) @@ -328,6 +329,8 @@ def shared_opt(txt: Optional[str]) -> SharedType: entry.findtext("./issyncable", "1") == "1", entry.findtext("./isdatasyncable", "1") == "1", entry.findtext("./etag", ""), + entry.findtext("./createdepochutc", ""), + entry.findtext("./systemcreatedepochutc", ""), ) def getfilelist( @@ -387,6 +390,17 @@ def bool_opt(txt: Union[None, str]) -> bool: entries, ) + def getsystemstatus(self) -> SystemStatus: + """ + Returns the server version and the upload chunk size (MiB) + """ + resp = self._api_call("/core/getsystemstatus", {}) + + return SystemStatus( + resp.findtext("./status/appversion", ""), + resp.findtext("./status/uploadchunksize", ""), + ) + def fileinfo_no_retry(self, path: str) -> FileListEntry: """ Returns information about file/directory 'path' @@ -992,10 +1006,54 @@ def quickshare(self, sharelocation: str, adminproxyuserid: str = "") -> FCShare: str_to_bool(resp.findtext("./share/allowpublicuploadonly", "")), ) - def deleteshare(self, share: FCShare) -> None: + def deleteshare(self, share: FCShare, adminproxyuserid: str = "") -> None: + """ + Delete share. A share owned by another user (for example a team folder + share) is deleted through the admin proxy 'adminproxyuserid' + """ resp = self._api_call( "/core/deleteshare", - {"shareid": share.shareid}, + {"shareid": share.shareid, "adminproxyuserid": adminproxyuserid}, + ) + self._raise_exception_from_command(resp) + + def updateshare( + self, + share: FCShare, + sharename: str, + allowpublicaccess: bool, + adminproxyuserid: str = "", + ) -> None: + """ + Rename share and set its public access + """ + resp = self._api_call( + "/core/updateshare", + { + "shareid": share.shareid, + "sharename": sharename, + "allowpublicaccess": 1 if allowpublicaccess else 0, + "adminproxyuserid": adminproxyuserid, + }, + ) + + # Success answers with the updated share, a failure with a meta error + # or a command result + if resp.find("./share") is None: + message = ( + resp.findtext("./meta/error") + or resp.findtext("./command/message") + or "Failed to update share" + ) + self._raise_exception_from_server_message(message) + + def deleteuserfromshare(self, share: FCShare, userid: str) -> None: + """ + Remove user from share + """ + resp = self._api_call( + "/core/deleteuserfromshare", + {"shareid": share.shareid, "userid": userid}, ) self._raise_exception_from_command(resp) @@ -2009,8 +2067,10 @@ def admin_getgroups( return group_list - def admin_createnewgroup(self, groupname: str): - """List all policies""" + def admin_createnewgroup(self, groupname: str) -> str: + """ + Create group and return its group id + """ resp = self._api_call( "/admin/addgroup", {"op": "addgroup", "groupname": groupname}, @@ -2019,6 +2079,8 @@ def admin_createnewgroup(self, groupname: str): if resp.findtext("./group/groupname") is None: raise ServerError("", "Failed to create group") + return resp.findtext("./group/groupid", "") + def admin_groupisinshare( self, share: FCShare, @@ -2094,6 +2156,57 @@ def admin_addmembertogroup(self, groupid: str, username: str) -> None: ) self._raise_exception_from_command(resp) + def admin_deletememberfromgroup(self, groupid: str, userid: str) -> None: + """ + Remove user from group + """ + resp = self._api_call( + "/admin/deletememberfromgroup", + {"op": "deletememberfromgroup", "groupid": groupid, "userid": userid}, + ) + self._raise_exception_from_command(resp) + + def admin_addusertoexternal( + self, externalid: str, userid: str, writemode: str = "1" + ) -> None: + """ + Allow user access to external + """ + resp = self._api_call( + "/admin/addusertoexternal", + { + "op": "addusertoexternal", + "externalid": externalid, + "userid": userid, + "writemode": writemode, + }, + ) + self._raise_exception_from_command(resp) + + def admin_deleteuserfromexternal(self, externalid: str, userid: str) -> None: + """ + Revoke user access to external + """ + resp = self._api_call( + "/admin/deleteuserfromexternal", + { + "op": "deleteuserfromexternal", + "externalid": externalid, + "userid": userid, + }, + ) + self._raise_exception_from_command(resp) + + def admin_deleteexternal(self, externalid: str) -> None: + """ + Delete external + """ + resp = self._api_call( + "/admin/deleteexternal", + {"op": "deleteexternal", "externalid": externalid}, + ) + self._raise_exception_from_command(resp) + def admin_setgroupaccessforshare( self, share: Optional[FCShare], diff --git a/filecloudapi/tests/test_fcserver.py b/filecloudapi/tests/test_fcserver.py index 18d08fc..60ee3f4 100644 --- a/filecloudapi/tests/test_fcserver.py +++ b/filecloudapi/tests/test_fcserver.py @@ -6,6 +6,8 @@ import pytest +from filecloudapi.datastructures import FCShare, SystemStatus +from filecloudapi.exceptions import ServerError from filecloudapi.fcserver import FCServer @@ -56,3 +58,185 @@ def test_upload_outside_public_share_keeps_exclamation_mark_encoded(data): assert len(urls) == 1 assert "path=%2Fuser%2Ffolder%211&" in urlsplit(urls[0]).query + + +OK_COMMAND = ( + "1" +) +FAILED_COMMAND = "0denied" + + +class _FakeApiResponse: + headers: dict = {} + + def __init__(self, xml: str): + self.content = xml.encode() + + def raise_for_status(self): + pass + + +def _server_answering(xml: str) -> tuple[FCServer, list[tuple[str, dict]]]: + """ + A server whose API calls are recorded as (url, form data) and answered with 'xml' + """ + server = FCServer("https://fc.example.com", None, "user", "pass", login=False) + calls: list[tuple[str, dict]] = [] + + def fake_post(url, data=None, **_kwargs): + calls.append((url, data)) + return _FakeApiResponse(xml) + + server.session.post = fake_post # type: ignore + return server, calls + + +SHARE = FCShare("share1", "", "", False, False, False, False) + + +def test_deleteshare_sends_admin_proxy_user(): + server, calls = _server_answering(OK_COMMAND) + + server.deleteshare(SHARE, adminproxyuserid="owner") + + assert calls == [ + ( + "https://fc.example.com/core/deleteshare", + {"shareid": "share1", "adminproxyuserid": "owner"}, + ) + ] + + +def test_updateshare_sends_name_and_public_access(): + server, calls = _server_answering( + "share1" + ) + + server.updateshare( + SHARE, "renamed", allowpublicaccess=True, adminproxyuserid="owner" + ) + + assert calls == [ + ( + "https://fc.example.com/core/updateshare", + { + "shareid": "share1", + "sharename": "renamed", + "allowpublicaccess": 1, + "adminproxyuserid": "owner", + }, + ) + ] + + +@pytest.mark.parametrize( + "xml", + [ + "denied", + FAILED_COMMAND, + ], +) +def test_updateshare_raises_on_failure(xml): + server, _ = _server_answering(xml) + + with pytest.raises(ServerError, match="denied"): + server.updateshare(SHARE, "renamed", allowpublicaccess=False) + + +def test_admin_createnewgroup_returns_group_id(): + server, _ = _server_answering( + "g1team" + ) + + assert server.admin_createnewgroup("team") == "g1" + + +def test_getsystemstatus_returns_version_and_chunk_size(): + server, calls = _server_answering( + "23.263.0.35023" + "40" + ) + + assert server.getsystemstatus() == SystemStatus("23.263.0.35023", "40") + assert calls[0][0] == "https://fc.example.com/core/getsystemstatus" + + +def test_getsystemstatus_without_fields_returns_empty_strings(): + server, _ = _server_answering("") + + assert server.getsystemstatus() == SystemStatus("", "") + + +@pytest.mark.parametrize( + "call, endpoint, data", + [ + ( + lambda s: s.deleteuserfromshare(SHARE, "user2"), + "/core/deleteuserfromshare", + {"shareid": "share1", "userid": "user2"}, + ), + ( + lambda s: s.admin_deletememberfromgroup("g1", "user2"), + "/admin/deletememberfromgroup", + {"op": "deletememberfromgroup", "groupid": "g1", "userid": "user2"}, + ), + ( + lambda s: s.admin_addusertoexternal("e1", "user2", writemode="0"), + "/admin/addusertoexternal", + { + "op": "addusertoexternal", + "externalid": "e1", + "userid": "user2", + "writemode": "0", + }, + ), + ( + lambda s: s.admin_deleteuserfromexternal("e1", "user2"), + "/admin/deleteuserfromexternal", + {"op": "deleteuserfromexternal", "externalid": "e1", "userid": "user2"}, + ), + ( + lambda s: s.admin_deleteexternal("e1"), + "/admin/deleteexternal", + {"op": "deleteexternal", "externalid": "e1"}, + ), + ], +) +def test_command_endpoints_send_their_parameters_and_raise_on_failure( + call, endpoint, data +): + server, calls = _server_answering(OK_COMMAND) + call(server) + assert calls == [("https://fc.example.com" + endpoint, data)] + + server, _ = _server_answering(FAILED_COMMAND) + with pytest.raises(ServerError, match="denied"): + call(server) + + +ENTRY = ( + "/user/a.txta.txt1" + "file{extra}" +) + + +def test_fileinfo_reads_creation_dates(): + extra = ( + "1700000000" + "1600000000" + ) + server, _ = _server_answering(f"{ENTRY.format(extra=extra)}") + + entry = server.fileinfo_no_retry("/user/a.txt") + + assert entry.createdepochutc == "1700000000" + assert entry.systemcreatedepochutc == "1600000000" + + +def test_fileinfo_without_creation_dates_returns_empty_strings(): + server, _ = _server_answering(f"{ENTRY.format(extra='')}") + + entry = server.fileinfo_no_retry("/user/a.txt") + + assert entry.createdepochutc == "" + assert entry.systemcreatedepochutc == "" From 02bff8a599cc36184ac2fb7562383aaac25a05e5 Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 17:48:55 +0100 Subject: [PATCH 6/7] Document that updateshare resets the share settings it does not send Checked against the server: ShareController::updateShare fills defaults for missing parameters. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/fcserver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 9401ecc..2864b8d 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -1026,6 +1026,11 @@ def updateshare( ) -> None: """ Rename share and set its public access + + The server resets the share settings this call does not send: the + expiry, the upload size limit, the download limit and count and + hidenotifications, and the password of a share that is public before + the call. Use it on shares that do not rely on those settings. """ resp = self._api_call( "/core/updateshare", From f26d3fdfa459416a89f0e524ca4510b7345828c8 Mon Sep 17 00:00:00 2001 From: Oleksandr Zolotov Date: Wed, 2 Dec 2026 18:10:23 +0100 Subject: [PATCH 7/7] Fix admin_deletegroup and admin_addnewuser, document the deleteuserfromshare and createdepochutc limits - admin_deletegroup returned True only when command/result was 0, so it reported a deleted group as not deleted. It now returns True on result 1. - admin_addnewuser sent the key "authtype " with a trailing space, so the server never got authtype, which /admin/adduser requires as an integer (HTTP 422 on 23.263.3). - deleteuserfromshare: the server validates userid as an email. - FileListEntry.createdepochutc: fileinfo reports it only for a file, getfilelist also for a folder. Review comments on #22. Co-Authored-By: Claude Opus 5.5 --- filecloudapi/datastructures.py | 6 +++--- filecloudapi/fcserver.py | 11 ++++------- filecloudapi/tests/test_fcserver.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index e5d2151..a50fc43 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -47,9 +47,9 @@ class FileListEntry: issyncable: bool isdatasyncable: bool etag: ETag - # Empty when the server does not report them: createdepochutc (getfilelist - # and fileinfo, 23.253 and later), systemcreatedepochutc (fileinfo, only when - # the server stores the OS creation date) + # Empty when the server does not report them: createdepochutc (getfilelist, + # and fileinfo of a file, 23.253 and later), systemcreatedepochutc (fileinfo, + # only when the server stores the OS creation date) createdepochutc: str = "" systemcreatedepochutc: str = "" diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 2864b8d..9f43eda 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -1054,7 +1054,8 @@ def updateshare( def deleteuserfromshare(self, share: FCShare, userid: str) -> None: """ - Remove user from share + Remove user from share. 'userid' is the user's email, the server + answers a user name with HTTP 422 """ resp = self._api_call( "/core/deleteuserfromshare", @@ -1822,7 +1823,7 @@ def admin_addnewuser( "displayname": username, "email": email, "password": password, - "authtype ": authtype, # 0 for default auth and 1 for AD + "authtype": authtype, # 0 for default auth and 1 for AD "status": status, # full(1), guest(0), external(3) or disabled user(2) }, ) @@ -2532,8 +2533,4 @@ def admin_deletegroup(self, groupid: str) -> bool: {"op": "deletegroup", "groupid": groupid}, ) - result = resp.findtext("./command/result") - if result == "0": - return True - else: - return False + return resp.findtext("./command/result") == "1" diff --git a/filecloudapi/tests/test_fcserver.py b/filecloudapi/tests/test_fcserver.py index 60ee3f4..2ad4735 100644 --- a/filecloudapi/tests/test_fcserver.py +++ b/filecloudapi/tests/test_fcserver.py @@ -240,3 +240,19 @@ def test_fileinfo_without_creation_dates_returns_empty_strings(): assert entry.createdepochutc == "" assert entry.systemcreatedepochutc == "" + + +def test_admin_addnewuser_sends_authtype(): + server, calls = _server_answering(OK_COMMAND) + + server.admin_addnewuser("user2", "user2@example.com", "pass", authtype="1") + + assert calls[0][1]["authtype"] == "1" + assert "authtype " not in calls[0][1] + + +@pytest.mark.parametrize("xml, deleted", [(OK_COMMAND, True), (FAILED_COMMAND, False)]) +def test_admin_deletegroup_returns_whether_the_group_was_deleted(xml, deleted): + server, _ = _server_answering(xml) + + assert server.admin_deletegroup("g1") is deleted