summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-07-05 11:48:55 +0200
committerJohn Villalovos <john@sodarock.com>2022-07-05 09:19:34 -0700
commit6491f1bbb68ffe04c719eb9d326b7ca3e78eba84 (patch)
tree14bc790ff3fe045378ee9bee2886a4b1cad6594e
parent1fbfb224388c107ada9c741e88193179eab3f23c (diff)
downloadgitlab-6491f1bbb68ffe04c719eb9d326b7ca3e78eba84.tar.gz
refactor(objects): move ci lint to separate file
-rw-r--r--gitlab/v4/objects/__init__.py1
-rw-r--r--gitlab/v4/objects/ci_lint.py22
-rw-r--r--gitlab/v4/objects/projects.py17
-rw-r--r--tests/unit/objects/test_ci_lint.py49
-rw-r--r--tests/unit/objects/test_projects.py46
5 files changed, 73 insertions, 62 deletions
diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py
index 40f9bf3..a390a4d 100644
--- a/gitlab/v4/objects/__init__.py
+++ b/gitlab/v4/objects/__init__.py
@@ -25,6 +25,7 @@ from .badges import *
from .boards import *
from .branches import *
from .broadcast_messages import *
+from .ci_lint import *
from .clusters import *
from .commits import *
from .container_registry import *
diff --git a/gitlab/v4/objects/ci_lint.py b/gitlab/v4/objects/ci_lint.py
new file mode 100644
index 0000000..3d5d488
--- /dev/null
+++ b/gitlab/v4/objects/ci_lint.py
@@ -0,0 +1,22 @@
+"""
+GitLab API:
+https://docs.gitlab.com/ee/api/lint.html
+"""
+
+from typing import Any, cast
+
+from gitlab.base import RESTManager, RESTObject
+from gitlab.mixins import CreateMixin, GetWithoutIdMixin
+
+
+class ProjectCiLint(RESTObject):
+ pass
+
+
+class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
+ _path = "/projects/{project_id}/ci/lint"
+ _obj_cls = ProjectCiLint
+ _from_parent_attrs = {"project_id": "id"}
+
+ def get(self, **kwargs: Any) -> ProjectCiLint:
+ return cast(ProjectCiLint, super().get(**kwargs))
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py
index 367ab68..9d7262f 100644
--- a/gitlab/v4/objects/projects.py
+++ b/gitlab/v4/objects/projects.py
@@ -1,7 +1,6 @@
"""
GitLab API:
https://docs.gitlab.com/ee/api/projects.html
-https://docs.gitlab.com/ee/api/lint.html
"""
from typing import (
Any,
@@ -39,6 +38,7 @@ from .audit_events import ProjectAuditEventManager # noqa: F401
from .badges import ProjectBadgeManager # noqa: F401
from .boards import ProjectBoardManager # noqa: F401
from .branches import ProjectBranchManager, ProjectProtectedBranchManager # noqa: F401
+from .ci_lint import ProjectCiLint, ProjectCiLintManager # noqa: F401
from .clusters import ProjectClusterManager # noqa: F401
from .commits import ProjectCommitManager # noqa: F401
from .container_registry import ProjectRegistryRepositoryManager # noqa: F401
@@ -1063,18 +1063,3 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
def get(self, **kwargs: Any) -> ProjectStorage:
return cast(ProjectStorage, super().get(**kwargs))
-
-
-class ProjectCiLint(RESTObject):
- pass
-
-
-class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
- """GitLab API: https://docs.gitlab.com/ee/api/lint.html"""
-
- _path = "/projects/{project_id}/ci/lint"
- _obj_cls = ProjectCiLint
- _from_parent_attrs = {"project_id": "id"}
-
- def get(self, **kwargs: Any) -> ProjectCiLint:
- return cast(ProjectCiLint, super().get(**kwargs))
diff --git a/tests/unit/objects/test_ci_lint.py b/tests/unit/objects/test_ci_lint.py
new file mode 100644
index 0000000..6591198
--- /dev/null
+++ b/tests/unit/objects/test_ci_lint.py
@@ -0,0 +1,49 @@
+import pytest
+import responses
+
+ci_lint_get_content = {
+ "valid": True,
+ "merged_yaml": "---\n:test_job:\n :script: echo 1\n",
+ "errors": [],
+ "warnings": [],
+}
+
+
+@pytest.fixture
+def resp_get_ci_lint():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/ci/lint",
+ json=ci_lint_get_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_create_ci_lint():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/ci/lint",
+ json=ci_lint_get_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+def test_project_ci_lint_get(project, resp_get_ci_lint):
+ lint_result = project.ci_lint.get()
+ assert lint_result.valid is True
+
+
+def test_project_ci_lint_create(project, resp_create_ci_lint):
+ gitlab_ci_yml = """---
+:test_job:
+ :script: echo 1
+"""
+ lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
+ assert lint_result.valid is True
diff --git a/tests/unit/objects/test_projects.py b/tests/unit/objects/test_projects.py
index 4db8835..85bae86 100644
--- a/tests/unit/objects/test_projects.py
+++ b/tests/unit/objects/test_projects.py
@@ -82,12 +82,6 @@ pipeline_trigger_content = {
"status": "created",
"source": "trigger",
}
-ci_lint_get_content = {
- "valid": True,
- "merged_yaml": "---\n:test_job:\n :script: echo 1\n",
- "errors": [],
- "warnings": [],
-}
@pytest.fixture
@@ -547,32 +541,6 @@ def resp_artifact():
yield rsps
-@pytest.fixture
-def resp_get_ci_lint():
- with responses.RequestsMock() as rsps:
- rsps.add(
- method=responses.GET,
- url="http://localhost/api/v4/projects/1/ci/lint",
- json=ci_lint_get_content,
- content_type="application/json",
- status=200,
- )
- yield rsps
-
-
-@pytest.fixture
-def resp_create_ci_lint():
- with responses.RequestsMock() as rsps:
- rsps.add(
- method=responses.POST,
- url="http://localhost/api/v4/projects/1/ci/lint",
- json=ci_lint_get_content,
- content_type="application/json",
- status=200,
- )
- yield rsps
-
-
def test_get_project(gl, resp_get_project):
data = gl.projects.get(1)
assert isinstance(data, Project)
@@ -788,17 +756,3 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
def test_project_snapshot(project, resp_snapshot_project):
tar_file = project.snapshot()
assert isinstance(tar_file, bytes)
-
-
-def test_project_ci_lint_get(project, resp_get_ci_lint):
- lint_result = project.ci_lint.get()
- assert lint_result.valid is True
-
-
-def test_project_ci_lint_create(project, resp_create_ci_lint):
- gitlab_ci_yml = """---
-:test_job:
- :script: echo 1
-"""
- lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
- assert lint_result.valid is True