| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7a13b9b commit a57334f
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,9 @@ def get_for_api(self) -> Any: | |||
| 32 | 32 | return self._value | |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | - class CommaSeparatedListAttribute(GitlabAttribute): | ||
| 35 | + class _ListArrayAttribute(GitlabAttribute): | ||
| 36 | + """Helper class to support `list` / `array` types.""" | ||
| 37 | + | ||
| 36 | 38 | def set_from_cli(self, cli_value: str) -> None: | |
| 37 | 39 | if not cli_value.strip(): | |
| 38 | 40 | self._value = [] | |
@@ -49,6 +51,17 @@ def get_for_api(self) -> str: | |||
| 49 | 51 | return ",".join([str(x) for x in self._value]) | |
| 50 | 52 | ||
| 51 | 53 | ||
| 54 | + class ArrayAttribute(_ListArrayAttribute): | ||
| 55 | + """To support `array` types as documented in | ||
| 56 | + https://docs.gitlab.com/ee/api/#array""" | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + class CommaSeparatedListAttribute(_ListArrayAttribute): | ||
| 60 | + """For values which are sent to the server as a Comma Separated Values | ||
| 61 | + (CSV) string. We allow them to be specified as a list and we convert it | ||
| 62 | + into a CSV""" | ||
| 63 | + | ||
| 64 | + | ||
| 52 | 65 | class LowercaseStringAttribute(GitlabAttribute): | |
| 53 | 66 | def get_for_api(self) -> str: | |
| 54 | 67 | return str(self._value).lower() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -314,10 +314,7 @@ class GroupManager(CRUDMixin, RESTManager): | |||
| 314 | 314 | "shared_runners_setting", | |
| 315 | 315 | ), | |
| 316 | 316 | ) | |
| 317 | - _types = { | ||
| 318 | - "avatar": types.ImageAttribute, | ||
| 319 | - "skip_groups": types.CommaSeparatedListAttribute, | ||
| 320 | - } | ||
| 317 | + _types = {"avatar": types.ImageAttribute, "skip_groups": types.ArrayAttribute} | ||
| 321 | 318 | ||
| 322 | 319 | def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Group: | |
| 323 | 320 | return cast(Group, super().get(id=id, lazy=lazy, **kwargs)) | |
@@ -377,7 +374,7 @@ class GroupSubgroupManager(ListMixin, RESTManager): | |||
| 377 | 374 | "with_custom_attributes", | |
| 378 | 375 | "min_access_level", | |
| 379 | 376 | ) | |
| 380 | - _types = {"skip_groups": types.CommaSeparatedListAttribute} | ||
| 377 | + _types = {"skip_groups": types.ArrayAttribute} | ||
| 381 | 378 | ||
| 382 | 379 | ||
| 383 | 380 | class GroupDescendantGroup(RESTObject): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,10 +65,7 @@ class IssueManager(RetrieveMixin, RESTManager): | |||
| 65 | 65 | "updated_after", | |
| 66 | 66 | "updated_before", | |
| 67 | 67 | ) | |
| 68 | - _types = { | ||
| 69 | - "iids": types.CommaSeparatedListAttribute, | ||
| 70 | - "labels": types.CommaSeparatedListAttribute, | ||
| 71 | - } | ||
| 68 | + _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute} | ||
| 72 | 69 | ||
| 73 | 70 | def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Issue: | |
| 74 | 71 | return cast(Issue, super().get(id=id, lazy=lazy, **kwargs)) | |
@@ -98,10 +95,7 @@ class GroupIssueManager(ListMixin, RESTManager): | |||
| 98 | 95 | "updated_after", | |
| 99 | 96 | "updated_before", | |
| 100 | 97 | ) | |
| 101 | - _types = { | ||
| 102 | - "iids": types.CommaSeparatedListAttribute, | ||
| 103 | - "labels": types.CommaSeparatedListAttribute, | ||
| 104 | - } | ||
| 98 | + _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute} | ||
| 105 | 99 | ||
| 106 | 100 | ||
| 107 | 101 | class ProjectIssue( | |
@@ -239,10 +233,7 @@ class ProjectIssueManager(CRUDMixin, RESTManager): | |||
| 239 | 233 | "discussion_locked", | |
| 240 | 234 | ), | |
| 241 | 235 | ) | |
| 242 | - _types = { | ||
| 243 | - "iids": types.CommaSeparatedListAttribute, | ||
| 244 | - "labels": types.CommaSeparatedListAttribute, | ||
| 245 | - } | ||
| 236 | + _types = {"iids": types.ArrayAttribute, "labels": types.CommaSeparatedListAttribute} | ||
| 246 | 237 | ||
| 247 | 238 | def get( | |
| 248 | 239 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ class GroupMemberManager(CRUDMixin, RESTManager): | |||
| 41 | 41 | _update_attrs = RequiredOptional( | |
| 42 | 42 | required=("access_level",), optional=("expires_at",) | |
| 43 | 43 | ) | |
| 44 | - _types = {"user_ids": types.CommaSeparatedListAttribute} | ||
| 44 | + _types = {"user_ids": types.ArrayAttribute} | ||
| 45 | 45 | ||
| 46 | 46 | def get( | |
| 47 | 47 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
@@ -101,7 +101,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager): | |||
| 101 | 101 | _update_attrs = RequiredOptional( | |
| 102 | 102 | required=("access_level",), optional=("expires_at",) | |
| 103 | 103 | ) | |
| 104 | - _types = {"user_ids": types.CommaSeparatedListAttribute} | ||
| 104 | + _types = {"user_ids": types.ArrayAttribute} | ||
| 105 | 105 | ||
| 106 | 106 | def get( | |
| 107 | 107 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,8 +95,8 @@ class MergeRequestManager(ListMixin, RESTManager): | |||
| 95 | 95 | "deployed_after", | |
| 96 | 96 | ) | |
| 97 | 97 | _types = { | |
| 98 | - "approver_ids": types.CommaSeparatedListAttribute, | ||
| 99 | - "approved_by_ids": types.CommaSeparatedListAttribute, | ||
| 98 | + "approver_ids": types.ArrayAttribute, | ||
| 99 | + "approved_by_ids": types.ArrayAttribute, | ||
| 100 | 100 | "in": types.CommaSeparatedListAttribute, | |
| 101 | 101 | "labels": types.CommaSeparatedListAttribute, | |
| 102 | 102 | } | |
@@ -133,8 +133,8 @@ class GroupMergeRequestManager(ListMixin, RESTManager): | |||
| 133 | 133 | "wip", | |
| 134 | 134 | ) | |
| 135 | 135 | _types = { | |
| 136 | - "approver_ids": types.CommaSeparatedListAttribute, | ||
| 137 | - "approved_by_ids": types.CommaSeparatedListAttribute, | ||
| 136 | + "approver_ids": types.ArrayAttribute, | ||
| 137 | + "approved_by_ids": types.ArrayAttribute, | ||
| 138 | 138 | "labels": types.CommaSeparatedListAttribute, | |
| 139 | 139 | } | |
| 140 | 140 | ||
@@ -455,9 +455,9 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager): | |||
| 455 | 455 | "wip", | |
| 456 | 456 | ) | |
| 457 | 457 | _types = { | |
| 458 | - "approver_ids": types.CommaSeparatedListAttribute, | ||
| 459 | - "approved_by_ids": types.CommaSeparatedListAttribute, | ||
| 460 | - "iids": types.CommaSeparatedListAttribute, | ||
| 458 | + "approver_ids": types.ArrayAttribute, | ||
| 459 | + "approved_by_ids": types.ArrayAttribute, | ||
| 460 | + "iids": types.ArrayAttribute, | ||
| 461 | 461 | "labels": types.CommaSeparatedListAttribute, | |
| 462 | 462 | } | |
| 463 | 463 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,7 +93,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager): | |||
| 93 | 93 | optional=("title", "description", "due_date", "start_date", "state_event"), | |
| 94 | 94 | ) | |
| 95 | 95 | _list_filters = ("iids", "state", "search") | |
| 96 | - _types = {"iids": types.CommaSeparatedListAttribute} | ||
| 96 | + _types = {"iids": types.ArrayAttribute} | ||
| 97 | 97 | ||
| 98 | 98 | def get( | |
| 99 | 99 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
@@ -177,7 +177,7 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager): | |||
| 177 | 177 | optional=("title", "description", "due_date", "start_date", "state_event"), | |
| 178 | 178 | ) | |
| 179 | 179 | _list_filters = ("iids", "state", "search") | |
| 180 | - _types = {"iids": types.CommaSeparatedListAttribute} | ||
| 180 | + _types = {"iids": types.ArrayAttribute} | ||
| 181 | 181 | ||
| 182 | 182 | def get( | |
| 183 | 183 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,7 @@ class ProjectGroupManager(ListMixin, RESTManager): | |||
| 125 | 125 | "shared_min_access_level", | |
| 126 | 126 | "shared_visible_only", | |
| 127 | 127 | ) | |
| 128 | - _types = {"skip_groups": types.CommaSeparatedListAttribute} | ||
| 128 | + _types = {"skip_groups": types.ArrayAttribute} | ||
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | 131 | class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,12 +80,12 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager): | |||
| 80 | 80 | ), | |
| 81 | 81 | ) | |
| 82 | 82 | _types = { | |
| 83 | - "asset_proxy_allowlist": types.CommaSeparatedListAttribute, | ||
| 84 | - "disabled_oauth_sign_in_sources": types.CommaSeparatedListAttribute, | ||
| 85 | - "domain_allowlist": types.CommaSeparatedListAttribute, | ||
| 86 | - "domain_denylist": types.CommaSeparatedListAttribute, | ||
| 87 | - "import_sources": types.CommaSeparatedListAttribute, | ||
| 88 | - "restricted_visibility_levels": types.CommaSeparatedListAttribute, | ||
| 83 | + "asset_proxy_allowlist": types.ArrayAttribute, | ||
| 84 | + "disabled_oauth_sign_in_sources": types.ArrayAttribute, | ||
| 85 | + "domain_allowlist": types.ArrayAttribute, | ||
| 86 | + "domain_denylist": types.ArrayAttribute, | ||
| 87 | + "import_sources": types.ArrayAttribute, | ||
| 88 | + "restricted_visibility_levels": types.ArrayAttribute, | ||
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | 91 | @exc.on_http_error(exc.GitlabUpdateError) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -369,7 +369,7 @@ class ProjectUserManager(ListMixin, RESTManager): | |||
| 369 | 369 | _obj_cls = ProjectUser | |
| 370 | 370 | _from_parent_attrs = {"project_id": "id"} | |
| 371 | 371 | _list_filters = ("search", "skip_users") | |
| 372 | - _types = {"skip_users": types.CommaSeparatedListAttribute} | ||
| 372 | + _types = {"skip_users": types.ArrayAttribute} | ||
| 373 | 373 | ||
| 374 | 374 | ||
| 375 | 375 | class UserEmail(ObjectDeleteMixin, RESTObject): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,45 +30,63 @@ def test_gitlab_attribute_get(): | |||
| 30 | 30 | assert o._value is None | |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | - def test_csv_list_attribute_input(): | ||
| 34 | - o = types.CommaSeparatedListAttribute() | ||
| 33 | + def test_array_attribute_input(): | ||
| 34 | + o = types.ArrayAttribute() | ||
| 35 | 35 | o.set_from_cli("foo,bar,baz") | |
| 36 | 36 | assert o.get() == ["foo", "bar", "baz"] | |
| 37 | 37 | ||
| 38 | 38 | o.set_from_cli("foo") | |
| 39 | 39 | assert o.get() == ["foo"] | |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | - def test_csv_list_attribute_empty_input(): | ||
| 43 | - o = types.CommaSeparatedListAttribute() | ||
| 42 | + def test_array_attribute_empty_input(): | ||
| 43 | + o = types.ArrayAttribute() | ||
| 44 | 44 | o.set_from_cli("") | |
| 45 | 45 | assert o.get() == [] | |
| 46 | 46 | ||
| 47 | 47 | o.set_from_cli(" ") | |
| 48 | 48 | assert o.get() == [] | |
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | - def test_csv_list_attribute_get_for_api_from_cli(): | ||
| 52 | - o = types.CommaSeparatedListAttribute() | ||
| 51 | + def test_array_attribute_get_for_api_from_cli(): | ||
| 52 | + o = types.ArrayAttribute() | ||
| 53 | 53 | o.set_from_cli("foo,bar,baz") | |
| 54 | 54 | assert o.get_for_api() == "foo,bar,baz" | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | - def test_csv_list_attribute_get_for_api_from_list(): | ||
| 58 | - o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"]) | ||
| 57 | + def test_array_attribute_get_for_api_from_list(): | ||
| 58 | + o = types.ArrayAttribute(["foo", "bar", "baz"]) | ||
| 59 | 59 | assert o.get_for_api() == "foo,bar,baz" | |
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | - def test_csv_list_attribute_get_for_api_from_int_list(): | ||
| 63 | - o = types.CommaSeparatedListAttribute([1, 9, 7]) | ||
| 62 | + def test_array_attribute_get_for_api_from_int_list(): | ||
| 63 | + o = types.ArrayAttribute([1, 9, 7]) | ||
| 64 | 64 | assert o.get_for_api() == "1,9,7" | |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | - def test_csv_list_attribute_does_not_split_string(): | ||
| 68 | - o = types.CommaSeparatedListAttribute("foo") | ||
| 67 | + def test_array_attribute_does_not_split_string(): | ||
| 68 | + o = types.ArrayAttribute("foo") | ||
| 69 | 69 | assert o.get_for_api() == "foo" | |
| 70 | 70 | ||
| 71 | 71 | ||
| 72 | + # CommaSeparatedListAttribute tests | ||
| 73 | + def test_csv_string_attribute_get_for_api_from_cli(): | ||
| 74 | + o = types.CommaSeparatedListAttribute() | ||
| 75 | + o.set_from_cli("foo,bar,baz") | ||
| 76 | + assert o.get_for_api() == "foo,bar,baz" | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + def test_csv_string_attribute_get_for_api_from_list(): | ||
| 80 | + o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"]) | ||
| 81 | + assert o.get_for_api() == "foo,bar,baz" | ||
| 82 | + | ||
| 83 | + | ||
| 84 | + def test_csv_string_attribute_get_for_api_from_int_list(): | ||
| 85 | + o = types.CommaSeparatedListAttribute([1, 9, 7]) | ||
| 86 | + assert o.get_for_api() == "1,9,7" | ||
| 87 | + | ||
| 88 | + | ||
| 89 | + # LowercaseStringAttribute tests | ||
| 72 | 90 | def test_lowercase_string_attribute_get_for_api(): | |
| 73 | 91 | o = types.LowercaseStringAttribute("FOO") | |
| 74 | 92 | assert o.get_for_api() == "foo" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments