| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4a8b416 commit 00b3e26
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -326,7 +326,7 @@ def reject(self, **kwargs: Any) -> gitlab.client.HttpResponseType: | |||
| 326 | 326 | ||
| 327 | 327 | @cli.register_custom_action("User") | |
| 328 | 328 | @exc.on_http_error(exc.GitlabBanError) | |
| 329 | - def ban(self, **kwargs: Any) -> gitlab.client.HttpResponseType: | ||
| 329 | + def ban(self, **kwargs: Any) -> bool: | ||
| 330 | 330 | """Ban the user. | |
| 331 | 331 | ||
| 332 | 332 | Args: | |
@@ -340,14 +340,16 @@ def ban(self, **kwargs: Any) -> gitlab.client.HttpResponseType: | |||
| 340 | 340 | Whether the user has been banned | |
| 341 | 341 | """ | |
| 342 | 342 | path = f"/users/{self.encoded_id}/ban" | |
| 343 | - server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
| 344 | - if server_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 | + if server_data is True: | ||
| 345 | 347 | self._attrs["state"] = "banned" | |
| 346 | 348 | return server_data | |
| 347 | 349 | ||
| 348 | 350 | @cli.register_custom_action("User") | |
| 349 | 351 | @exc.on_http_error(exc.GitlabUnbanError) | |
| 350 | - def unban(self, **kwargs: Any) -> gitlab.client.HttpResponseType: | ||
| 352 | + def unban(self, **kwargs: Any) -> bool: | ||
| 351 | 353 | """Unban the user. | |
| 352 | 354 | ||
| 353 | 355 | Args: | |
@@ -361,8 +363,10 @@ def unban(self, **kwargs: Any) -> gitlab.client.HttpResponseType: | |||
| 361 | 363 | Whether the user has been unbanned | |
| 362 | 364 | """ | |
| 363 | 365 | path = f"/users/{self.encoded_id}/unban" | |
| 364 | - server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
| 365 | - if server_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 | + if server_data is True: | ||
| 366 | 370 | self._attrs["state"] = "active" | |
| 367 | 371 | return server_data | |
| 368 | 372 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,11 @@ | |||
| 3 | 3 | https://docs.gitlab.com/ee/api/users.html | |
| 4 | 4 | https://docs.gitlab.com/ee/api/users.html#delete-authentication-identity-from-user | |
| 5 | 5 | """ | |
| 6 | + import pytest | ||
| 6 | 7 | import requests | |
| 7 | 8 | ||
| 9 | + import gitlab.exceptions | ||
| 10 | + | ||
| 8 | 11 | ||
| 9 | 12 | def test_create_user(gl, fixture_dir): | |
| 10 | 13 | user = gl.users.create( | |
@@ -45,19 +48,29 @@ def test_block_user(gl, user): | |||
| 45 | 48 | ||
| 46 | 49 | # unblock again | |
| 47 | 50 | result = user.unblock() | |
| 48 | - # Trying to unblock an already blocked user returns False | ||
| 51 | + # Trying to unblock an already un-blocked user returns False | ||
| 49 | 52 | assert result is False | |
| 50 | 53 | ||
| 51 | 54 | ||
| 52 | 55 | def test_ban_user(gl, user): | |
| 53 | - user.ban() | ||
| 56 | + result = user.ban() | ||
| 57 | + assert result is True | ||
| 54 | 58 | retrieved_user = gl.users.get(user.id) | |
| 55 | 59 | assert retrieved_user.state == "banned" | |
| 56 | 60 | ||
| 57 | - user.unban() | ||
| 61 | + # ban an already banned user raises an exception | ||
| 62 | + with pytest.raises(gitlab.exceptions.GitlabBanError): | ||
| 63 | + user.ban() | ||
| 64 | + | ||
| 65 | + result = user.unban() | ||
| 66 | + assert result is True | ||
| 58 | 67 | retrieved_user = gl.users.get(user.id) | |
| 59 | 68 | assert retrieved_user.state == "active" | |
| 60 | 69 | ||
| 70 | + # unban an already un-banned user raises an exception | ||
| 71 | + with pytest.raises(gitlab.exceptions.GitlabUnbanError): | ||
| 72 | + user.unban() | ||
| 73 | + | ||
| 61 | 74 | ||
| 62 | 75 | def test_delete_user(gl, wait_for_sidekiq): | |
| 63 | 76 | new_user = gl.users.create( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments