Skip to content

Commit a83f779

Browse files
author
nateatkins
committed
Issue 643 project-variable update. Fix to remove 'key' from require3d argument list after it is popped to add to the http path.
1 parent 011274e commit a83f779

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

gitlab/mixins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ def create(self, data, **kwargs):
208208
class UpdateMixin(object):
209209
def _check_missing_update_attrs(self, data):
210210
required, optional = self.get_update_attrs()
211+
# Remove the id field from the required list as it has been moved to the http path.
212+
required = tuple(filter(lambda k: k != self._obj_cls._id_attr, required))
211213
missing = []
212214
for attr in required:
213215
if attr not in data:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from gitlab import cli
2+
import pytest
3+
import sys
4+
5+
PROJECT_ID = 9460322
6+
7+
8+
def test_project_variable(capsys):
9+
key = "junk1"
10+
value1 = "car"
11+
value2 = "bus"
12+
13+
with pytest.raises(SystemExit) as exit_exc:
14+
cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}"
15+
print("--->", cmd_line)
16+
sys.argv = cmd_line.split()
17+
cli.main()
18+
out, err = capsys.readouterr()
19+
20+
if key not in out:
21+
with pytest.raises(SystemExit) as exit_exc:
22+
cmd_line = f"gitlab project-variable create --project-id {PROJECT_ID} --key {key} --value {value1}"
23+
print("--->", cmd_line)
24+
sys.argv = cmd_line.split()
25+
cli.main()
26+
out, err = capsys.readouterr()
27+
28+
with pytest.raises(SystemExit) as exit_exc:
29+
cmd_line = f"gitlab project-variable get --project-id {PROJECT_ID} --key {key}"
30+
print("--->", cmd_line)
31+
sys.argv = cmd_line.split()
32+
cli.main()
33+
out, err = capsys.readouterr()
34+
35+
with pytest.raises(SystemExit) as exit_exc:
36+
cmd_line = f"gitlab project-variable update --project-id {PROJECT_ID} --key {key} --value {value2}"
37+
print("--->", cmd_line)
38+
sys.argv = cmd_line.split()
39+
cli.main()
40+
out, err = capsys.readouterr()
41+
assert key in out
42+
assert value2 in out
43+
44+
with pytest.raises(SystemExit) as exit_exc:
45+
cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}"
46+
print("--->", cmd_line)
47+
sys.argv = cmd_line.split()
48+
cli.main()
49+
out, _ = capsys.readouterr()
50+
51+
if key in out:
52+
with pytest.raises(SystemExit) as exit_exc:
53+
cmd_line = f"gitlab project-variable delete --project-id {PROJECT_ID} --key {key}"
54+
print("--->", cmd_line)
55+
sys.argv = cmd_line.split()
56+
cli.main()
57+
out, _ = capsys.readouterr()
58+
59+
pass

tools/cli_test_v4.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ testcase "merge request validation" '
8989
--iid "$MR_ID" >/dev/null 2>&1
9090
'
9191

92+
# Test project variables
93+
testcase "create project variable" '
94+
OUTPUT=$(GITLAB -v project-variable create --project-id $PROJECT_ID \
95+
--key junk --value car)
96+
'
97+
98+
testcase "get project variable" '
99+
OUTPUT=$(GITLAB -v project-variable get --project-id $PROJECT_ID \
100+
--key junk)
101+
'
102+
103+
testcase "update project variable" '
104+
OUTPUT=$(GITLAB -v project-variable update --project-id $PROJECT_ID \
105+
--key junk --value bus)
106+
'
107+
108+
testcase "list project variable" '
109+
OUTPUT=$(GITLAB -v project-variable list --project-id $PROJECT_ID)
110+
'
111+
112+
testcase "delete project variable" '
113+
OUTPUT=$(GITLAB -v project-variable delete --project-id $PROJECT_ID \
114+
--key junk)
115+
'
116+
92117
testcase "branch deletion" '
93118
GITLAB project-branch delete --project-id "$PROJECT_ID" \
94119
--name branch1 >/dev/null 2>&1

0 commit comments

Comments
 (0)