diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-29 10:45:51 +0200 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-29 10:45:51 +0200 |
commit | 7ea178bad398c8c2851a4584f4dca5b8adc89d29 (patch) | |
tree | e558235551a994de9f09da30625f925976372b84 | |
parent | 71495d127d30d2f4c00285485adae5454a590584 (diff) | |
download | gitlab-7ea178bad398c8c2851a4584f4dca5b8adc89d29.tar.gz |
test(packages): add tests for Packages API
-rw-r--r-- | gitlab/tests/objects/conftest.py | 5 | ||||
-rw-r--r-- | gitlab/tests/objects/test_packages.py | 119 | ||||
-rw-r--r-- | tools/functional/api/test_packages.py | 13 | ||||
-rw-r--r-- | tools/functional/cli/test_cli_packages.py | 12 | ||||
-rw-r--r-- | tools/functional/cli/test_cli_v4.py (renamed from tools/functional/test_cli_v4.py) | 0 | ||||
-rwxr-xr-x | tools/functional_tests.sh | 2 | ||||
-rwxr-xr-x | tools/py_functional_tests.sh | 1 |
7 files changed, 151 insertions, 1 deletions
diff --git a/gitlab/tests/objects/conftest.py b/gitlab/tests/objects/conftest.py index 76f76d1..d8a40d9 100644 --- a/gitlab/tests/objects/conftest.py +++ b/gitlab/tests/objects/conftest.py @@ -22,6 +22,11 @@ def created_content(): @pytest.fixture +def no_content(): + return {"message": "204 No Content"} + + +@pytest.fixture def resp_export(accepted_content, binary_content): """Common fixture for group and project exports.""" export_status_content = { diff --git a/gitlab/tests/objects/test_packages.py b/gitlab/tests/objects/test_packages.py new file mode 100644 index 0000000..d4d97ff --- /dev/null +++ b/gitlab/tests/objects/test_packages.py @@ -0,0 +1,119 @@ +""" +GitLab API: https://docs.gitlab.com/ce/api/packages.html +""" +import re + +import pytest +import responses + +from gitlab.v4.objects import GroupPackage, ProjectPackage + + +package_content = { + "id": 1, + "name": "com/mycompany/my-app", + "version": "1.0-SNAPSHOT", + "package_type": "maven", + "_links": { + "web_path": "/namespace1/project1/-/packages/1", + "delete_api_path": "/namespace1/project1/-/packages/1", + }, + "created_at": "2019-11-27T03:37:38.711Z", + "pipeline": { + "id": 123, + "status": "pending", + "ref": "new-pipeline", + "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", + "web_url": "https://example.com/foo/bar/pipelines/47", + "created_at": "2016-08-11T11:28:34.085Z", + "updated_at": "2016-08-11T11:32:35.169Z", + "user": { + "name": "Administrator", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + }, + }, + "versions": [ + { + "id": 2, + "version": "2.0-SNAPSHOT", + "created_at": "2020-04-28T04:42:11.573Z", + "pipeline": { + "id": 234, + "status": "pending", + "ref": "new-pipeline", + "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", + "web_url": "https://example.com/foo/bar/pipelines/58", + "created_at": "2016-08-11T11:28:34.085Z", + "updated_at": "2016-08-11T11:32:35.169Z", + "user": { + "name": "Administrator", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + }, + }, + } + ], +} + + +@pytest.fixture +def resp_list_packages(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url=re.compile(r"http://localhost/api/v4/(groups|projects)/1/packages"), + json=[package_content], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_get_package(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/packages/1", + json=package_content, + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_delete_package(no_content): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.DELETE, + url="http://localhost/api/v4/projects/1/packages/1", + json=no_content, + content_type="application/json", + status=204, + ) + yield rsps + + +def test_list_project_packages(project, resp_list_packages): + packages = project.packages.list() + assert isinstance(packages, list) + assert isinstance(packages[0], ProjectPackage) + assert packages[0].version == "1.0-SNAPSHOT" + + +def test_list_group_packages(group, resp_list_packages): + packages = group.packages.list() + assert isinstance(packages, list) + assert isinstance(packages[0], GroupPackage) + assert packages[0].version == "1.0-SNAPSHOT" + + +def test_get_project_package(project, resp_get_package): + package = project.packages.get(1) + assert isinstance(package, ProjectPackage) + assert package.version == "1.0-SNAPSHOT" + + +def test_delete_project_package(project, resp_delete_package): + package = project.packages.get(1, lazy=True) + package.delete() diff --git a/tools/functional/api/test_packages.py b/tools/functional/api/test_packages.py new file mode 100644 index 0000000..9160a68 --- /dev/null +++ b/tools/functional/api/test_packages.py @@ -0,0 +1,13 @@ +""" +GitLab API: https://docs.gitlab.com/ce/api/packages.html +""" + + +def test_list_project_packages(project): + packages = project.packages.list() + assert isinstance(packages, list) + + +def test_list_group_packages(group): + packages = group.packages.list() + assert isinstance(packages, list) diff --git a/tools/functional/cli/test_cli_packages.py b/tools/functional/cli/test_cli_packages.py new file mode 100644 index 0000000..a3734a2 --- /dev/null +++ b/tools/functional/cli/test_cli_packages.py @@ -0,0 +1,12 @@ +def test_list_project_packages(gitlab_cli, project): + cmd = ["project-package", "list", "--project-id", project.id] + ret = gitlab_cli(cmd) + + assert ret.success + + +def test_list_group_packages(gitlab_cli, group): + cmd = ["group-package", "list", "--group-id", group.id] + ret = gitlab_cli(cmd) + + assert ret.success diff --git a/tools/functional/test_cli_v4.py b/tools/functional/cli/test_cli_v4.py index 4f78c0c..4f78c0c 100644 --- a/tools/functional/test_cli_v4.py +++ b/tools/functional/cli/test_cli_v4.py diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index b86be3a..87907c5 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/test_cli_v4.py" +pytest "$(dirname "$0")/functional/cli" diff --git a/tools/py_functional_tests.sh b/tools/py_functional_tests.sh index 75bb761..1009cb9 100755 --- a/tools/py_functional_tests.sh +++ b/tools/py_functional_tests.sh @@ -19,3 +19,4 @@ BUILD_TEST_ENV_AUTO_CLEANUP=true . "$setenv_script" "$@" || exit 1 try python "$(dirname "$0")"/python_test_v${API_VER}.py +pytest "$(dirname "$0")/functional/api" |