diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-29 17:48:27 +0200 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-31 23:48:55 +0200 |
commit | 66d108de9665055921123476426fb6716c602496 (patch) | |
tree | 77afaad489e7b162345ed50bf1dc1bf1dd8c3b61 /tools | |
parent | 4492fc42c9f6e0031dd3f3c6c99e4c58d4f472ff (diff) | |
download | gitlab-66d108de9665055921123476426fb6716c602496.tar.gz |
test(api): add tests for variables API
Diffstat (limited to 'tools')
-rw-r--r-- | tools/functional/api/test_variables.py | 48 | ||||
-rw-r--r-- | tools/functional/cli/conftest.py | 21 | ||||
-rw-r--r-- | tools/functional/cli/test_cli_variables.py | 19 | ||||
-rw-r--r-- | tools/functional/conftest.py | 27 | ||||
-rwxr-xr-x | tools/functional_tests.sh | 2 | ||||
-rw-r--r-- | tools/python_test_v4.py | 19 |
6 files changed, 95 insertions, 41 deletions
diff --git a/tools/functional/api/test_variables.py b/tools/functional/api/test_variables.py new file mode 100644 index 0000000..d20ebba --- /dev/null +++ b/tools/functional/api/test_variables.py @@ -0,0 +1,48 @@ +""" +GitLab API: +https://docs.gitlab.com/ee/api/instance_level_ci_variables.html +https://docs.gitlab.com/ee/api/project_level_variables.html +https://docs.gitlab.com/ee/api/group_level_variables.html +""" + + +def test_instance_variables(gl): + variable = gl.variables.create({"key": "key1", "value": "value1"}) + assert variable.value == "value1" + assert len(gl.variables.list()) == 1 + + variable.value = "new_value1" + variable.save() + variable = gl.variables.get(variable.key) + assert variable.value == "new_value1" + + variable.delete() + assert len(gl.variables.list()) == 0 + + +def test_group_variables(group): + variable = group.variables.create({"key": "key1", "value": "value1"}) + assert variable.value == "value1" + assert len(group.variables.list()) == 1 + + variable.value = "new_value1" + variable.save() + variable = group.variables.get(variable.key) + assert variable.value == "new_value1" + + variable.delete() + assert len(group.variables.list()) == 0 + + +def test_project_variables(project): + variable = project.variables.create({"key": "key1", "value": "value1"}) + assert variable.value == "value1" + assert len(project.variables.list()) == 1 + + variable.value = "new_value1" + variable.save() + variable = project.variables.get(variable.key) + assert variable.value == "new_value1" + + variable.delete() + assert len(project.variables.list()) == 0 diff --git a/tools/functional/cli/conftest.py b/tools/functional/cli/conftest.py new file mode 100644 index 0000000..13c3096 --- /dev/null +++ b/tools/functional/cli/conftest.py @@ -0,0 +1,21 @@ +import pytest + + +@pytest.fixture +def gitlab_cli(script_runner, CONFIG): + """Wrapper fixture to help make test cases less verbose.""" + + def _gitlab_cli(subcommands): + """ + Return a script_runner.run method that takes a default gitlab + command, and subcommands passed as arguments inside test cases. + """ + command = ["gitlab", "--config-file", CONFIG] + + for subcommand in subcommands: + # ensure we get strings (e.g from IDs) + command.append(str(subcommand)) + + return script_runner.run(*command) + + return _gitlab_cli diff --git a/tools/functional/cli/test_cli_variables.py b/tools/functional/cli/test_cli_variables.py new file mode 100644 index 0000000..9b1b16d --- /dev/null +++ b/tools/functional/cli/test_cli_variables.py @@ -0,0 +1,19 @@ +def test_list_instance_variables(gitlab_cli, gl): + cmd = ["variable", "list"] + ret = gitlab_cli(cmd) + + assert ret.success + + +def test_list_group_variables(gitlab_cli, group): + cmd = ["group-variable", "list", "--group-id", group.id] + ret = gitlab_cli(cmd) + + assert ret.success + + +def test_list_project_variables(gitlab_cli, project): + cmd = ["project-variable", "list", "--project-id", project.id] + ret = gitlab_cli(cmd) + + assert ret.success diff --git a/tools/functional/conftest.py b/tools/functional/conftest.py index bd99fa9..e12471b 100644 --- a/tools/functional/conftest.py +++ b/tools/functional/conftest.py @@ -1,3 +1,5 @@ +import os +import tempfile from random import randint import pytest @@ -5,6 +7,9 @@ import pytest import gitlab +TEMP_DIR = tempfile.gettempdir() + + def random_id(): """ Helper to ensure new resource creation does not clash with @@ -17,27 +22,7 @@ def random_id(): @pytest.fixture(scope="session") def CONFIG(): - return "/tmp/python-gitlab.cfg" - - -@pytest.fixture -def gitlab_cli(script_runner, CONFIG): - """Wrapper fixture to help make test cases less verbose.""" - - def _gitlab_cli(subcommands): - """ - Return a script_runner.run method that takes a default gitlab - command, and subcommands passed as arguments inside test cases. - """ - command = ["gitlab", "--config-file", CONFIG] - - for subcommand in subcommands: - # ensure we get strings (e.g from IDs) - command.append(str(subcommand)) - - return script_runner.run(*command) - - return _gitlab_cli + return os.path.join(TEMP_DIR, "python-gitlab.cfg") @pytest.fixture(scope="session") diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index 87907c5..9b91f0f 100755 --- a/tools/functional_tests.sh +++ b/tools/functional_tests.sh @@ -18,4 +18,4 @@ setenv_script=$(dirname "$0")/build_test_env.sh || exit 1 BUILD_TEST_ENV_AUTO_CLEANUP=true . "$setenv_script" "$@" || exit 1 -pytest "$(dirname "$0")/functional/cli" +pytest --script-launch-mode=subprocess "$(dirname "$0")/functional/cli" diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 21faf9e..7ff97b6 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -367,17 +367,6 @@ assert gm1.state == "closed" assert len(gm1.issues()) == 0 assert len(gm1.merge_requests()) == 0 -# group variables -group1.variables.create({"key": "foo", "value": "bar"}) -g_v = group1.variables.get("foo") -assert g_v.value == "bar" -g_v.value = "baz" -g_v.save() -g_v = group1.variables.get("foo") -assert g_v.value == "baz" -assert len(group1.variables.list()) == 1 -g_v.delete() -assert len(group1.variables.list()) == 0 # group labels # group1.labels.create({"name": "foo", "description": "bar", "color": "#112233"}) @@ -856,14 +845,6 @@ tr1 = admin_project.triggers.create({"description": "trigger1"}) assert len(admin_project.triggers.list()) == 1 tr1.delete() -# variables -v1 = admin_project.variables.create({"key": "key1", "value": "value1"}) -assert len(admin_project.variables.list()) == 1 -v1.value = "new_value1" -v1.save() -v1 = admin_project.variables.get(v1.key) -assert v1.value == "new_value1" -v1.delete() # branches and merges to_merge = admin_project.branches.create({"branch": "branch1", "ref": "master"}) |