Skip to content

Fix: ListAttribute get_for_api() splits strings #1058

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 2 commits into from
Apr 2, 2020
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
10 changes: 9 additions & 1 deletion gitlab/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ def test_empty_input(self):
o.set_from_cli(" ")
self.assertEqual([], o.get())

def test_get_for_api(self):
def test_get_for_api_from_cli(self):
o = types.ListAttribute()
o.set_from_cli("foo,bar,baz")
self.assertEqual("foo,bar,baz", o.get_for_api())

def test_get_for_api_from_list(self):
o = types.ListAttribute(["foo", "bar", "baz"])
self.assertEqual("foo,bar,baz", o.get_for_api())

def test_get_for_api_does_not_split_string(self):
o = types.ListAttribute("foo")
self.assertEqual("foo", o.get_for_api())


class TestLowercaseStringAttribute(unittest.TestCase):
def test_get_for_api(self):
Expand Down
4 changes: 4 additions & 0 deletions gitlab/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def set_from_cli(self, cli_value):
self._value = [item.strip() for item in cli_value.split(",")]

def get_for_api(self):
# Do not comma-split single value passed as string
if isinstance(self._value, str):
return self._value

return ",".join(self._value)


Expand Down
9 changes: 8 additions & 1 deletion tools/python_test_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,17 @@
assert type(issue1.closed_by()) == list
assert type(issue1.related_merge_requests()) == list

# issues labels and events
# issue labels
label2 = admin_project.labels.create({"name": "label2", "color": "#aabbcc"})
issue1.labels = ["label2"]
issue1.save()

assert issue1 in admin_project.issues.list(labels=["label2"])
assert issue1 in admin_project.issues.list(labels="label2")
assert issue1 in admin_project.issues.list(labels="Any")
assert issue1 not in admin_project.issues.list(labels="None")

# issue events
events = issue1.resourcelabelevents.list()
assert events
event = issue1.resourcelabelevents.get(events[0].id)
Expand Down