| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ed110bd commit a29cd6c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | https://docs.gitlab.com/ee/api/users.html | |
| 4 | 4 | https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user | |
| 5 | 5 | """ | |
| 6 | - from typing import Any, cast, Dict, List, Union | ||
| 6 | + from typing import Any, cast, Dict, List, Optional, Union | ||
| 7 | 7 | ||
| 8 | 8 | import requests | |
| 9 | 9 | ||
@@ -163,7 +163,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 163 | 163 | ||
| 164 | 164 | @cli.register_custom_action("User") | |
| 165 | 165 | @exc.on_http_error(exc.GitlabBlockError) | |
| 166 | - def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
| 166 | + def block(self, **kwargs: Any) -> Optional[bool]: | ||
| 167 | 167 | """Block the user. | |
| 168 | 168 | ||
| 169 | 169 | Args: | |
@@ -177,7 +177,11 @@ def block(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | |||
| 177 | 177 | Whether the user status has been changed | |
| 178 | 178 | """ | |
| 179 | 179 | path = f"/users/{self.encoded_id}/block" | |
| 180 | - server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
| 180 | + # NOTE: Undocumented behavior of the GitLab API is that it returns a | ||
| 181 | + # boolean or None | ||
| 182 | + server_data = cast( | ||
| 183 | + Optional[bool], self.manager.gitlab.http_post(path, **kwargs) | ||
| 184 | + ) | ||
| 181 | 185 | if server_data is True: | |
| 182 | 186 | self._attrs["state"] = "blocked" | |
| 183 | 187 | return server_data | |
@@ -220,7 +224,7 @@ def unfollow(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | |||
| 220 | 224 | ||
| 221 | 225 | @cli.register_custom_action("User") | |
| 222 | 226 | @exc.on_http_error(exc.GitlabUnblockError) | |
| 223 | - def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | ||
| 227 | + def unblock(self, **kwargs: Any) -> Optional[bool]: | ||
| 224 | 228 | """Unblock the user. | |
| 225 | 229 | ||
| 226 | 230 | Args: | |
@@ -234,7 +238,11 @@ def unblock(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | |||
| 234 | 238 | Whether the user status has been changed | |
| 235 | 239 | """ | |
| 236 | 240 | path = f"/users/{self.encoded_id}/unblock" | |
| 237 | - server_data = self.manager.gitlab.http_post(path, **kwargs) | ||
| 241 | + # NOTE: Undocumented behavior of the GitLab API is that it returns a | ||
| 242 | + # boolean or None | ||
| 243 | + server_data = cast( | ||
| 244 | + Optional[bool], self.manager.gitlab.http_post(path, **kwargs) | ||
| 245 | + ) | ||
| 238 | 246 | if server_data is True: | |
| 239 | 247 | self._attrs["state"] = "active" | |
| 240 | 248 | return server_data | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,8 @@ disallow_incomplete_defs = true | |||
| 13 | 13 | disallow_subclassing_any = true | |
| 14 | 14 | disallow_untyped_decorators = true | |
| 15 | 15 | disallow_untyped_defs = true | |
| 16 | + no_implicit_reexport = true | ||
| 17 | + strict_equality = true | ||
| 16 | 18 | warn_redundant_casts = true | |
| 17 | 19 | warn_unused_configs = true | |
| 18 | 20 | warn_unused_ignores = true | |
@@ -21,8 +23,6 @@ warn_unused_ignores = true | |||
| 21 | 23 | # disallow_any_generics = true | |
| 22 | 24 | # disallow_untyped_calls = true | |
| 23 | 25 | # no_implicit_optional = true | |
| 24 | - no_implicit_reexport = true | ||
| 25 | - # strict_equality = true | ||
| 26 | 26 | # warn_return_any = true | |
| 27 | 27 | ||
| 28 | 28 | [[tool.mypy.overrides]] # Overrides for currently untyped modules | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,14 +28,26 @@ def test_create_user(gl, fixture_dir): | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | def test_block_user(gl, user): | |
| 31 | - user.block() | ||
| 31 | + result = user.block() | ||
| 32 | + assert result is True | ||
| 32 | 33 | users = gl.users.list(blocked=True) | |
| 33 | 34 | assert user in users | |
| 34 | 35 | ||
| 35 | - user.unblock() | ||
| 36 | + # block again | ||
| 37 | + result = user.block() | ||
| 38 | + # Trying to block an already blocked user returns None | ||
| 39 | + assert result is None | ||
| 40 | + | ||
| 41 | + result = user.unblock() | ||
| 42 | + assert result is True | ||
| 36 | 43 | users = gl.users.list(blocked=False) | |
| 37 | 44 | assert user in users | |
| 38 | 45 | ||
| 46 | + # unblock again | ||
| 47 | + result = user.unblock() | ||
| 48 | + # Trying to unblock an already blocked user returns False | ||
| 49 | + assert result is False | ||
| 50 | + | ||
| 39 | 51 | ||
| 40 | 52 | def test_ban_user(gl, user): | |
| 41 | 53 | user.ban() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments