Skip to content

Commit 6491f1b

Browse files
nejchJohnVillalovos
authored andcommitted
refactor(objects): move ci lint to separate file
1 parent 1fbfb22 commit 6491f1b

File tree

5 files changed

+73
-62
lines changed

5 files changed

+73
-62
lines changed

gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .boards import *
2626
from .branches import *
2727
from .broadcast_messages import *
28+
from .ci_lint import *
2829
from .clusters import *
2930
from .commits import *
3031
from .container_registry import *

gitlab/v4/objects/ci_lint.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ee/api/lint.html
4+
"""
5+
6+
from typing import Any, cast
7+
8+
from gitlab.base import RESTManager, RESTObject
9+
from gitlab.mixins import CreateMixin, GetWithoutIdMixin
10+
11+
12+
class ProjectCiLint(RESTObject):
13+
pass
14+
15+
16+
class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
17+
_path = "/projects/{project_id}/ci/lint"
18+
_obj_cls = ProjectCiLint
19+
_from_parent_attrs = {"project_id": "id"}
20+
21+
def get(self, **kwargs: Any) -> ProjectCiLint:
22+
return cast(ProjectCiLint, super().get(**kwargs))

gitlab/v4/objects/projects.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
GitLab API:
33
https://docs.gitlab.com/ee/api/projects.html
4-
https://docs.gitlab.com/ee/api/lint.html
54
"""
65
from typing import (
76
Any,
@@ -39,6 +38,7 @@
3938
from .badges import ProjectBadgeManager # noqa: F401
4039
from .boards import ProjectBoardManager # noqa: F401
4140
from .branches import ProjectBranchManager, ProjectProtectedBranchManager # noqa: F401
41+
from .ci_lint import ProjectCiLint, ProjectCiLintManager # noqa: F401
4242
from .clusters import ProjectClusterManager # noqa: F401
4343
from .commits import ProjectCommitManager # noqa: F401
4444
from .container_registry import ProjectRegistryRepositoryManager # noqa: F401
@@ -1063,18 +1063,3 @@ class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
10631063

10641064
def get(self, **kwargs: Any) -> ProjectStorage:
10651065
return cast(ProjectStorage, super().get(**kwargs))
1066-
1067-
1068-
class ProjectCiLint(RESTObject):
1069-
pass
1070-
1071-
1072-
class ProjectCiLintManager(GetWithoutIdMixin, CreateMixin, RESTManager):
1073-
"""GitLab API: https://docs.gitlab.com/ee/api/lint.html"""
1074-
1075-
_path = "/projects/{project_id}/ci/lint"
1076-
_obj_cls = ProjectCiLint
1077-
_from_parent_attrs = {"project_id": "id"}
1078-
1079-
def get(self, **kwargs: Any) -> ProjectCiLint:
1080-
return cast(ProjectCiLint, super().get(**kwargs))

tests/unit/objects/test_ci_lint.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
import responses
3+
4+
ci_lint_get_content = {
5+
"valid": True,
6+
"merged_yaml": "---\n:test_job:\n :script: echo 1\n",
7+
"errors": [],
8+
"warnings": [],
9+
}
10+
11+
12+
@pytest.fixture
13+
def resp_get_ci_lint():
14+
with responses.RequestsMock() as rsps:
15+
rsps.add(
16+
method=responses.GET,
17+
url="http://localhost/api/v4/projects/1/ci/lint",
18+
json=ci_lint_get_content,
19+
content_type="application/json",
20+
status=200,
21+
)
22+
yield rsps
23+
24+
25+
@pytest.fixture
26+
def resp_create_ci_lint():
27+
with responses.RequestsMock() as rsps:
28+
rsps.add(
29+
method=responses.POST,
30+
url="http://localhost/api/v4/projects/1/ci/lint",
31+
json=ci_lint_get_content,
32+
content_type="application/json",
33+
status=200,
34+
)
35+
yield rsps
36+
37+
38+
def test_project_ci_lint_get(project, resp_get_ci_lint):
39+
lint_result = project.ci_lint.get()
40+
assert lint_result.valid is True
41+
42+
43+
def test_project_ci_lint_create(project, resp_create_ci_lint):
44+
gitlab_ci_yml = """---
45+
:test_job:
46+
:script: echo 1
47+
"""
48+
lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
49+
assert lint_result.valid is True

tests/unit/objects/test_projects.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@
8282
"status": "created",
8383
"source": "trigger",
8484
}
85-
ci_lint_get_content = {
86-
"valid": True,
87-
"merged_yaml": "---\n:test_job:\n :script: echo 1\n",
88-
"errors": [],
89-
"warnings": [],
90-
}
9185

9286

9387
@pytest.fixture
@@ -547,32 +541,6 @@ def resp_artifact():
547541
yield rsps
548542

549543

550-
@pytest.fixture
551-
def resp_get_ci_lint():
552-
with responses.RequestsMock() as rsps:
553-
rsps.add(
554-
method=responses.GET,
555-
url="http://localhost/api/v4/projects/1/ci/lint",
556-
json=ci_lint_get_content,
557-
content_type="application/json",
558-
status=200,
559-
)
560-
yield rsps
561-
562-
563-
@pytest.fixture
564-
def resp_create_ci_lint():
565-
with responses.RequestsMock() as rsps:
566-
rsps.add(
567-
method=responses.POST,
568-
url="http://localhost/api/v4/projects/1/ci/lint",
569-
json=ci_lint_get_content,
570-
content_type="application/json",
571-
status=200,
572-
)
573-
yield rsps
574-
575-
576544
def test_get_project(gl, resp_get_project):
577545
data = gl.projects.get(1)
578546
assert isinstance(data, Project)
@@ -788,17 +756,3 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
788756
def test_project_snapshot(project, resp_snapshot_project):
789757
tar_file = project.snapshot()
790758
assert isinstance(tar_file, bytes)
791-
792-
793-
def test_project_ci_lint_get(project, resp_get_ci_lint):
794-
lint_result = project.ci_lint.get()
795-
assert lint_result.valid is True
796-
797-
798-
def test_project_ci_lint_create(project, resp_create_ci_lint):
799-
gitlab_ci_yml = """---
800-
:test_job:
801-
:script: echo 1
802-
"""
803-
lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
804-
assert lint_result.valid is True

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy