Skip to content

chore: rename types.ListAttribute to types.CommaSeparatedListAttribute #1858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gitlab/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_for_api(self) -> Any:
return self._value


class ListAttribute(GitlabAttribute):
class CommaSeparatedListAttribute(GitlabAttribute):
def set_from_cli(self, cli_value: str) -> None:
if not cli_value.strip():
self._value = []
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/deploy_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
"username",
),
)
_types = {"scopes": types.ListAttribute}
_types = {"scopes": types.CommaSeparatedListAttribute}


class ProjectDeployToken(ObjectDeleteMixin, RESTObject):
Expand All @@ -60,4 +60,4 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager
"username",
),
)
_types = {"scopes": types.ListAttribute}
_types = {"scopes": types.CommaSeparatedListAttribute}
2 changes: 1 addition & 1 deletion gitlab/v4/objects/epics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GroupEpicManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
optional=("title", "labels", "description", "start_date", "end_date"),
)
_types = {"labels": types.ListAttribute}
_types = {"labels": types.CommaSeparatedListAttribute}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> GroupEpic:
return cast(GroupEpic, super().get(id=id, lazy=lazy, **kwargs))
Expand Down
7 changes: 5 additions & 2 deletions gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ class GroupManager(CRUDMixin, RESTManager):
"shared_runners_setting",
),
)
_types = {"avatar": types.ImageAttribute, "skip_groups": types.ListAttribute}
_types = {
"avatar": types.ImageAttribute,
"skip_groups": types.CommaSeparatedListAttribute,
}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Group:
return cast(Group, super().get(id=id, lazy=lazy, **kwargs))
Expand Down Expand Up @@ -374,7 +377,7 @@ class GroupSubgroupManager(ListMixin, RESTManager):
"with_custom_attributes",
"min_access_level",
)
_types = {"skip_groups": types.ListAttribute}
_types = {"skip_groups": types.CommaSeparatedListAttribute}


class GroupDescendantGroup(RESTObject):
Expand Down
15 changes: 12 additions & 3 deletions gitlab/v4/objects/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class IssueManager(RetrieveMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Issue:
return cast(Issue, super().get(id=id, lazy=lazy, **kwargs))
Expand Down Expand Up @@ -95,7 +98,10 @@ class GroupIssueManager(ListMixin, RESTManager):
"updated_after",
"updated_before",
)
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}


class ProjectIssue(
Expand Down Expand Up @@ -233,7 +239,10 @@ class ProjectIssueManager(CRUDMixin, RESTManager):
"discussion_locked",
),
)
_types = {"iids": types.ListAttribute, "labels": types.ListAttribute}
_types = {
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GroupMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.ListAttribute}
_types = {"user_ids": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down Expand Up @@ -101,7 +101,7 @@ class ProjectMemberManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
required=("access_level",), optional=("expires_at",)
)
_types = {"user_ids": types.ListAttribute}
_types = {"user_ids": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
22 changes: 11 additions & 11 deletions gitlab/v4/objects/merge_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class MergeRequestManager(ListMixin, RESTManager):
"deployed_after",
)
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"in": types.ListAttribute,
"labels": types.ListAttribute,
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"in": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}


Expand Down Expand Up @@ -133,9 +133,9 @@ class GroupMergeRequestManager(ListMixin, RESTManager):
"wip",
)
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"labels": types.ListAttribute,
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}


Expand Down Expand Up @@ -455,10 +455,10 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
"wip",
)
_types = {
"approver_ids": types.ListAttribute,
"approved_by_ids": types.ListAttribute,
"iids": types.ListAttribute,
"labels": types.ListAttribute,
"approver_ids": types.CommaSeparatedListAttribute,
"approved_by_ids": types.CommaSeparatedListAttribute,
"iids": types.CommaSeparatedListAttribute,
"labels": types.CommaSeparatedListAttribute,
}

def get(
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class GroupMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.ListAttribute}
_types = {"iids": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down Expand Up @@ -177,7 +177,7 @@ class ProjectMilestoneManager(CRUDMixin, RESTManager):
optional=("title", "description", "due_date", "start_date", "state_event"),
)
_list_filters = ("iids", "state", "search")
_types = {"iids": types.ListAttribute}
_types = {"iids": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
Expand Down
7 changes: 5 additions & 2 deletions gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ProjectGroupManager(ListMixin, RESTManager):
"shared_min_access_level",
"shared_visible_only",
)
_types = {"skip_groups": types.ListAttribute}
_types = {"skip_groups": types.CommaSeparatedListAttribute}


class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject):
Expand Down Expand Up @@ -807,7 +807,10 @@ class ProjectManager(CRUDMixin, RESTManager):
"with_merge_requests_enabled",
"with_programming_language",
)
_types = {"avatar": types.ImageAttribute, "topic": types.ListAttribute}
_types = {
"avatar": types.ImageAttribute,
"topic": types.CommaSeparatedListAttribute,
}

def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Project:
return cast(Project, super().get(id=id, lazy=lazy, **kwargs))
Expand Down
6 changes: 3 additions & 3 deletions gitlab/v4/objects/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RunnerManager(CRUDMixin, RESTManager):
),
)
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}
_types = {"tag_list": types.CommaSeparatedListAttribute}

@cli.register_custom_action("RunnerManager", tuple(), ("scope",))
@exc.on_http_error(exc.GitlabListError)
Expand Down Expand Up @@ -130,7 +130,7 @@ class GroupRunnerManager(ListMixin, RESTManager):
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(required=("runner_id",))
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}
_types = {"tag_list": types.CommaSeparatedListAttribute}


class ProjectRunner(ObjectDeleteMixin, RESTObject):
Expand All @@ -143,4 +143,4 @@ class ProjectRunnerManager(CreateMixin, DeleteMixin, ListMixin, RESTManager):
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("runner_id",))
_list_filters = ("scope", "tag_list")
_types = {"tag_list": types.ListAttribute}
_types = {"tag_list": types.CommaSeparatedListAttribute}
12 changes: 6 additions & 6 deletions gitlab/v4/objects/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
),
)
_types = {
"asset_proxy_allowlist": types.ListAttribute,
"disabled_oauth_sign_in_sources": types.ListAttribute,
"domain_allowlist": types.ListAttribute,
"domain_denylist": types.ListAttribute,
"import_sources": types.ListAttribute,
"restricted_visibility_levels": types.ListAttribute,
"asset_proxy_allowlist": types.CommaSeparatedListAttribute,
"disabled_oauth_sign_in_sources": types.CommaSeparatedListAttribute,
"domain_allowlist": types.CommaSeparatedListAttribute,
"domain_denylist": types.CommaSeparatedListAttribute,
"import_sources": types.CommaSeparatedListAttribute,
"restricted_visibility_levels": types.CommaSeparatedListAttribute,
}

@exc.on_http_error(exc.GitlabUpdateError)
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ProjectUserManager(ListMixin, RESTManager):
_obj_cls = ProjectUser
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("search", "skip_users")
_types = {"skip_users": types.ListAttribute}
_types = {"skip_users": types.CommaSeparatedListAttribute}


class UserEmail(ObjectDeleteMixin, RESTObject):
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ def test_gitlab_attribute_get():
assert o._value is None


def test_list_attribute_input():
o = types.ListAttribute()
def test_csv_list_attribute_input():
o = types.CommaSeparatedListAttribute()
o.set_from_cli("foo,bar,baz")
assert o.get() == ["foo", "bar", "baz"]

o.set_from_cli("foo")
assert o.get() == ["foo"]


def test_list_attribute_empty_input():
o = types.ListAttribute()
def test_csv_list_attribute_empty_input():
o = types.CommaSeparatedListAttribute()
o.set_from_cli("")
assert o.get() == []

o.set_from_cli(" ")
assert o.get() == []


def test_list_attribute_get_for_api_from_cli():
o = types.ListAttribute()
def test_csv_list_attribute_get_for_api_from_cli():
o = types.CommaSeparatedListAttribute()
o.set_from_cli("foo,bar,baz")
assert o.get_for_api() == "foo,bar,baz"


def test_list_attribute_get_for_api_from_list():
o = types.ListAttribute(["foo", "bar", "baz"])
def test_csv_list_attribute_get_for_api_from_list():
o = types.CommaSeparatedListAttribute(["foo", "bar", "baz"])
assert o.get_for_api() == "foo,bar,baz"


def test_list_attribute_get_for_api_from_int_list():
o = types.ListAttribute([1, 9, 7])
def test_csv_list_attribute_get_for_api_from_int_list():
o = types.CommaSeparatedListAttribute([1, 9, 7])
assert o.get_for_api() == "1,9,7"


def test_list_attribute_does_not_split_string():
o = types.ListAttribute("foo")
def test_csv_list_attribute_does_not_split_string():
o = types.CommaSeparatedListAttribute("foo")
assert o.get_for_api() == "foo"


Expand Down