From 535636f6284903095fd7627fbe76444a3b8ae0bb Mon Sep 17 00:00:00 2001 From: kernelport <30635575+kernelport@users.noreply.github.com> Date: Sat, 8 Jan 2022 17:37:23 -0800 Subject: [PATCH] fix: allow updating of sub-pages in wikis Make it possible to update subpages in wikis Update SaveMixin to use utils._url_encode() on the ID if it is a string. Closes: #1079 --- gitlab/mixins.py | 7 +++++-- tests/functional/api/test_wikis.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/functional/api/test_wikis.py diff --git a/gitlab/mixins.py b/gitlab/mixins.py index c02f4c027..fa426aa8d 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -527,7 +527,7 @@ def _get_updated_data(self) -> Dict[str, Any]: return updated_data - def save(self, **kwargs: Any) -> None: + def save(self, **kwargs: Any) -> Optional[Dict[str, Any]]: """Save the changes made to the object to the server. The object is updated to match what the server returns. @@ -542,15 +542,18 @@ def save(self, **kwargs: Any) -> None: updated_data = self._get_updated_data() # Nothing to update. Server fails if sent an empty dict. if not updated_data: - return + return None # call the manager obj_id = self.get_id() if TYPE_CHECKING: assert isinstance(self.manager, UpdateMixin) + if isinstance(obj_id, str): + obj_id = utils._url_encode(obj_id) server_data = self.manager.update(obj_id, updated_data, **kwargs) if server_data is not None: self._update_attrs(server_data) + return server_data class ObjectDeleteMixin(_RestObjectBase): diff --git a/tests/functional/api/test_wikis.py b/tests/functional/api/test_wikis.py new file mode 100644 index 000000000..26ac244ec --- /dev/null +++ b/tests/functional/api/test_wikis.py @@ -0,0 +1,15 @@ +""" +GitLab API: +https://docs.gitlab.com/ee/api/wikis.html +""" + + +def test_wikis(project): + + page = project.wikis.create({"title": "title/subtitle", "content": "test content"}) + page.content = "update content" + page.title = "subtitle" + + page.save() + + page.delete()