Skip to content

Commit eed6f11

Browse files
authored
fix+test for users.create(groups=xxx) (#68)
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 9846852 commit eed6f11

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file.
99
- Finished documentation.
1010
- Different small adjustments to API, to be it more consistent.
1111

12+
### Fixed
13+
14+
- Assign groups in user creation
15+
1216
## [0.0.27 - 2023-08-05]
1317

1418
### Added

nc_py_api/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def create(self, user_id: str, **kwargs) -> None:
7070
* ``password`` - password that should be set for user.
7171
* ``email`` - email of the new user. If ``password`` is not provided, then this field should be filled.
7272
* ``displayname`` - display name of the new user.
73-
* ``groups`` - groups IDs to which user belongs.
73+
* ``groups`` - list of groups IDs to which user belongs.
7474
* ``subadmin`` - boolean indicating is user should be the subadmin.
7575
* ``quota`` - quota for the user, if needed.
7676
* ``language`` - default language for the user.
@@ -83,7 +83,7 @@ def create(self, user_id: str, **kwargs) -> None:
8383
for k in ("password", "displayname", "email", "groups", "subadmin", "quota", "language"):
8484
if k in kwargs:
8585
data[k] = kwargs[k]
86-
self._session.ocs(method="POST", path=ENDPOINT, params=data)
86+
self._session.ocs(method="POST", path=ENDPOINT, json=data)
8787

8888
def delete(self, user_id: str) -> None:
8989
"""Deletes user from the Nextcloud server.

tests/users_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ def test_create_user(nc):
4545
nc.users.create(TEST_USER_NAME, password=TEST_USER_PASSWORD)
4646
with pytest.raises(NextcloudException):
4747
nc.users.create(TEST_USER_NAME, password=TEST_USER_PASSWORD)
48+
nc.users.delete(TEST_USER_NAME)
49+
50+
51+
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1][0], Nextcloud), reason="Not available for NextcloudApp.")
52+
@pytest.mark.parametrize("nc", NC_TO_TEST[:1])
53+
def test_create_user_with_groups(nc):
54+
try:
55+
nc.users.delete(TEST_USER_NAME)
56+
except NextcloudException:
57+
pass
58+
nc.users.create(TEST_USER_NAME, password=TEST_USER_PASSWORD, groups=["admin"])
59+
admin_group = nc.users.groups.get_members("admin")
60+
assert TEST_USER_NAME in admin_group
61+
nc.users.delete(TEST_USER_NAME)
4862

4963

5064
@pytest.mark.skipif(not isinstance(NC_TO_TEST[:1][0], Nextcloud), reason="Not available for NextcloudApp.")

0 commit comments

Comments
 (0)