From a83f77964fb6c8a384c214dc4aebe861431ae9d0 Mon Sep 17 00:00:00 2001 From: nateatkins Date: Sun, 25 Nov 2018 12:05:27 -0700 Subject: [PATCH 1/2] Issue 643 project-variable update. Fix to remove 'key' from require3d argument list after it is popped to add to the http path. --- gitlab/mixins.py | 2 + gitlab/tests/test_project_variable_api.py | 59 +++++++++++++++++++++++ tools/cli_test_v4.sh | 25 ++++++++++ 3 files changed, 86 insertions(+) create mode 100644 gitlab/tests/test_project_variable_api.py diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 2c80f36db..d5b05a738 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -208,6 +208,8 @@ def create(self, data, **kwargs): class UpdateMixin(object): def _check_missing_update_attrs(self, data): required, optional = self.get_update_attrs() + # Remove the id field from the required list as it has been moved to the http path. + required = tuple(filter(lambda k: k != self._obj_cls._id_attr, required)) missing = [] for attr in required: if attr not in data: diff --git a/gitlab/tests/test_project_variable_api.py b/gitlab/tests/test_project_variable_api.py new file mode 100644 index 000000000..28fe111ea --- /dev/null +++ b/gitlab/tests/test_project_variable_api.py @@ -0,0 +1,59 @@ +from gitlab import cli +import pytest +import sys + +PROJECT_ID = 9460322 + + +def test_project_variable(capsys): + key = "junk1" + value1 = "car" + value2 = "bus" + + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, err = capsys.readouterr() + + if key not in out: + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable create --project-id {PROJECT_ID} --key {key} --value {value1}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, err = capsys.readouterr() + + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable get --project-id {PROJECT_ID} --key {key}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, err = capsys.readouterr() + + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable update --project-id {PROJECT_ID} --key {key} --value {value2}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, err = capsys.readouterr() + assert key in out + assert value2 in out + + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, _ = capsys.readouterr() + + if key in out: + with pytest.raises(SystemExit) as exit_exc: + cmd_line = f"gitlab project-variable delete --project-id {PROJECT_ID} --key {key}" + print("--->", cmd_line) + sys.argv = cmd_line.split() + cli.main() + out, _ = capsys.readouterr() + + pass \ No newline at end of file diff --git a/tools/cli_test_v4.sh b/tools/cli_test_v4.sh index b62e5cd39..dea0509eb 100644 --- a/tools/cli_test_v4.sh +++ b/tools/cli_test_v4.sh @@ -89,6 +89,31 @@ testcase "merge request validation" ' --iid "$MR_ID" >/dev/null 2>&1 ' +# Test project variables +testcase "create project variable" ' + OUTPUT=$(GITLAB -v project-variable create --project-id $PROJECT_ID \ + --key junk --value car) +' + +testcase "get project variable" ' + OUTPUT=$(GITLAB -v project-variable get --project-id $PROJECT_ID \ + --key junk) +' + +testcase "update project variable" ' + OUTPUT=$(GITLAB -v project-variable update --project-id $PROJECT_ID \ + --key junk --value bus) +' + +testcase "list project variable" ' + OUTPUT=$(GITLAB -v project-variable list --project-id $PROJECT_ID) +' + +testcase "delete project variable" ' + OUTPUT=$(GITLAB -v project-variable delete --project-id $PROJECT_ID \ + --key junk) +' + testcase "branch deletion" ' GITLAB project-branch delete --project-id "$PROJECT_ID" \ --name branch1 >/dev/null 2>&1 From b3ce1bdb131f7aead131f2396e38e9f86bb809b3 Mon Sep 17 00:00:00 2001 From: nateatkins Date: Sat, 15 Dec 2018 09:46:23 -0700 Subject: [PATCH 2/2] Removed unit tests that were used to debug the problem. Testing is covered in the tools/cli_test_v4.sh script. --- gitlab/mixins.py | 2 +- gitlab/tests/test_project_variable_api.py | 59 ----------------------- tools/cli_test_v4.sh | 0 3 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 gitlab/tests/test_project_variable_api.py mode change 100644 => 100755 tools/cli_test_v4.sh diff --git a/gitlab/mixins.py b/gitlab/mixins.py index d5b05a738..71967486a 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -208,7 +208,7 @@ def create(self, data, **kwargs): class UpdateMixin(object): def _check_missing_update_attrs(self, data): required, optional = self.get_update_attrs() - # Remove the id field from the required list as it has been moved to the http path. + # Remove the id field from the required list as it was previously moved to the http path. required = tuple(filter(lambda k: k != self._obj_cls._id_attr, required)) missing = [] for attr in required: diff --git a/gitlab/tests/test_project_variable_api.py b/gitlab/tests/test_project_variable_api.py deleted file mode 100644 index 28fe111ea..000000000 --- a/gitlab/tests/test_project_variable_api.py +++ /dev/null @@ -1,59 +0,0 @@ -from gitlab import cli -import pytest -import sys - -PROJECT_ID = 9460322 - - -def test_project_variable(capsys): - key = "junk1" - value1 = "car" - value2 = "bus" - - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, err = capsys.readouterr() - - if key not in out: - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable create --project-id {PROJECT_ID} --key {key} --value {value1}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, err = capsys.readouterr() - - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable get --project-id {PROJECT_ID} --key {key}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, err = capsys.readouterr() - - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable update --project-id {PROJECT_ID} --key {key} --value {value2}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, err = capsys.readouterr() - assert key in out - assert value2 in out - - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable list --project-id {PROJECT_ID}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, _ = capsys.readouterr() - - if key in out: - with pytest.raises(SystemExit) as exit_exc: - cmd_line = f"gitlab project-variable delete --project-id {PROJECT_ID} --key {key}" - print("--->", cmd_line) - sys.argv = cmd_line.split() - cli.main() - out, _ = capsys.readouterr() - - pass \ No newline at end of file diff --git a/tools/cli_test_v4.sh b/tools/cli_test_v4.sh old mode 100644 new mode 100755