Skip to content

Commit 50fcd12

Browse files
authored
Merge pull request #1058 from python-gitlab/fix/listattribute-get-api-splits-string
Fix: ListAttribute get_for_api() splits strings
2 parents c5904c4 + a26e585 commit 50fcd12

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

gitlab/tests/test_types.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,19 @@ def test_empty_input(self):
5151
o.set_from_cli(" ")
5252
self.assertEqual([], o.get())
5353

54-
def test_get_for_api(self):
54+
def test_get_for_api_from_cli(self):
5555
o = types.ListAttribute()
5656
o.set_from_cli("foo,bar,baz")
5757
self.assertEqual("foo,bar,baz", o.get_for_api())
5858

59+
def test_get_for_api_from_list(self):
60+
o = types.ListAttribute(["foo", "bar", "baz"])
61+
self.assertEqual("foo,bar,baz", o.get_for_api())
62+
63+
def test_get_for_api_does_not_split_string(self):
64+
o = types.ListAttribute("foo")
65+
self.assertEqual("foo", o.get_for_api())
66+
5967

6068
class TestLowercaseStringAttribute(unittest.TestCase):
6169
def test_get_for_api(self):

gitlab/types.py

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def set_from_cli(self, cli_value):
3838
self._value = [item.strip() for item in cli_value.split(",")]
3939

4040
def get_for_api(self):
41+
# Do not comma-split single value passed as string
42+
if isinstance(self._value, str):
43+
return self._value
44+
4145
return ",".join(self._value)
4246

4347

tools/python_test_v4.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,17 @@
677677
assert type(issue1.closed_by()) == list
678678
assert type(issue1.related_merge_requests()) == list
679679

680-
# issues labels and events
680+
# issue labels
681681
label2 = admin_project.labels.create({"name": "label2", "color": "#aabbcc"})
682682
issue1.labels = ["label2"]
683683
issue1.save()
684+
685+
assert issue1 in admin_project.issues.list(labels=["label2"])
686+
assert issue1 in admin_project.issues.list(labels="label2")
687+
assert issue1 in admin_project.issues.list(labels="Any")
688+
assert issue1 not in admin_project.issues.list(labels="None")
689+
690+
# issue events
684691
events = issue1.resourcelabelevents.list()
685692
assert events
686693
event = issue1.resourcelabelevents.get(events[0].id)

0 commit comments

Comments
 (0)