From babd298eca0586dce134d65586bf50410aacd035 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 28 Mar 2020 17:37:39 +0100 Subject: [PATCH 1/2] test(types): reproduce get_for_api splitting strings (#1057) --- gitlab/tests/test_types.py | 10 +++++++++- tools/python_test_v4.py | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gitlab/tests/test_types.py b/gitlab/tests/test_types.py index 5b9f2caf8..3613383de 100644 --- a/gitlab/tests/test_types.py +++ b/gitlab/tests/test_types.py @@ -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): diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 69b0d3181..e0cb3a609 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -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) From a26e58585b3d82cf1a3e60a3b7b3bfd7f51d77e5 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 28 Mar 2020 18:52:29 +0100 Subject: [PATCH 2/2] fix(types): do not split single value string in ListAttribute --- gitlab/types.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gitlab/types.py b/gitlab/types.py index 525dc3043..e07d078e1 100644 --- a/gitlab/types.py +++ b/gitlab/types.py @@ -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)