Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf02f9e

Browse files
chore: correct type-hints forban() andunban()
The functions return Optional[bool].Add tests for their behavior
1 parent2e88cd4 commitbf02f9e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

‎gitlab/v4/objects/users.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def reject(self, **kwargs: Any) -> gitlab.client.HttpResponseType:
326326

327327
@cli.register_custom_action("User")
328328
@exc.on_http_error(exc.GitlabBanError)
329-
defban(self,**kwargs:Any)->gitlab.client.HttpResponseType:
329+
defban(self,**kwargs:Any)->bool:
330330
"""Ban the user.
331331
332332
Args:
@@ -340,14 +340,16 @@ def ban(self, **kwargs: Any) -> gitlab.client.HttpResponseType:
340340
Whether the user has been banned
341341
"""
342342
path=f"/users/{self.encoded_id}/ban"
343-
server_data=self.manager.gitlab.http_post(path,**kwargs)
344-
ifserver_data:
343+
# NOTE: Undocumented behavior of the GitLab API is that it returns True
344+
# on success.
345+
server_data=cast(bool,self.manager.gitlab.http_post(path,**kwargs))
346+
ifserver_dataisTrue:
345347
self._attrs["state"]="banned"
346348
returnserver_data
347349

348350
@cli.register_custom_action("User")
349351
@exc.on_http_error(exc.GitlabUnbanError)
350-
defunban(self,**kwargs:Any)->gitlab.client.HttpResponseType:
352+
defunban(self,**kwargs:Any)->bool:
351353
"""Unban the user.
352354
353355
Args:
@@ -361,8 +363,10 @@ def unban(self, **kwargs: Any) -> gitlab.client.HttpResponseType:
361363
Whether the user has been unbanned
362364
"""
363365
path=f"/users/{self.encoded_id}/unban"
364-
server_data=self.manager.gitlab.http_post(path,**kwargs)
365-
ifserver_data:
366+
# NOTE: Undocumented behavior of the GitLab API is that it returns True
367+
# on success.
368+
server_data=cast(bool,self.manager.gitlab.http_post(path,**kwargs))
369+
ifserver_dataisTrue:
366370
self._attrs["state"]="active"
367371
returnserver_data
368372

‎tests/functional/api/test_users.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
https://docs.gitlab.com/ee/api/users.html
44
https://docs.gitlab.com/ee/api/users.html#delete-authentication-identity-from-user
55
"""
6+
importpytest
67
importrequests
78

9+
importgitlab.exceptions
10+
811

912
deftest_create_user(gl,fixture_dir):
1013
user=gl.users.create(
@@ -45,19 +48,29 @@ def test_block_user(gl, user):
4548

4649
# unblock again
4750
result=user.unblock()
48-
# Trying to unblock an already blocked user returns False
51+
# Trying to unblock an alreadyun-blocked user returns False
4952
assertresultisFalse
5053

5154

5255
deftest_ban_user(gl,user):
53-
user.ban()
56+
result=user.ban()
57+
assertresultisTrue
5458
retrieved_user=gl.users.get(user.id)
5559
assertretrieved_user.state=="banned"
5660

57-
user.unban()
61+
# ban an already banned user raises an exception
62+
withpytest.raises(gitlab.exceptions.GitlabBanError):
63+
user.ban()
64+
65+
result=user.unban()
66+
assertresultisTrue
5867
retrieved_user=gl.users.get(user.id)
5968
assertretrieved_user.state=="active"
6069

70+
# unban an already un-banned user raises an exception
71+
withpytest.raises(gitlab.exceptions.GitlabUnbanError):
72+
user.unban()
73+
6174

6275
deftest_delete_user(gl,wait_for_sidekiq):
6376
new_user=gl.users.create(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp