Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita71be72

Browse files
committed
test(templates): Added unit tests for templates
1 parent24724f3 commita71be72

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

‎tests/unit/objects/test_templates.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""
2+
Gitlab API:
3+
https://docs.gitlab.com/ce/api/templates/dockerfiles.html
4+
https://docs.gitlab.com/ce/api/templates/gitignores.html
5+
https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
6+
https://docs.gitlab.com/ce/api/templates/licenses.html
7+
https://docs.gitlab.com/ce/api/project_templates.html
8+
"""
9+
10+
importpytest
11+
importresponses
12+
13+
fromgitlab.v4.objectsimport (
14+
Dockerfile,
15+
Gitignore,
16+
Gitlabciyml,
17+
License,
18+
ProjectDockerfileTemplate,
19+
ProjectGitignoreTemplate,
20+
ProjectGitlabciymlTemplate,
21+
ProjectIssueTemplate,
22+
ProjectLicenseTemplate,
23+
ProjectMergeRequestTemplate,
24+
)
25+
26+
27+
@pytest.mark.parametrize(
28+
"tmpl, tmpl_mgr, tmpl_path",
29+
[
30+
(Dockerfile,"dockerfiles","dockerfiles"),
31+
(Gitignore,"gitignores","gitignores"),
32+
(Gitlabciyml,"gitlabciymls","gitlab_ci_ymls"),
33+
(License,"licenses","licenses"),
34+
],
35+
ids=[
36+
"dockerfile",
37+
"gitignore",
38+
"gitlabciyml",
39+
"license",
40+
],
41+
)
42+
deftest_get_template(gl,tmpl,tmpl_mgr,tmpl_path):
43+
tmpl_id="sample"
44+
tmpl_content= {"name":tmpl_id,"content":"Sample template content"}
45+
46+
# License templates have 'key' as the id attribute, so ensure
47+
# this is included in the response content
48+
iftmpl==License:
49+
tmpl_id="smpl"
50+
tmpl_content.update({"key":tmpl_id})
51+
52+
path=f"templates/{tmpl_path}/{tmpl_id}"
53+
withresponses.RequestsMock()asrsps:
54+
rsps.add(
55+
method=responses.GET,
56+
url=f"http://localhost/api/v4/{path}",
57+
json=tmpl_content,
58+
)
59+
60+
template=getattr(gl,tmpl_mgr).get(tmpl_id)
61+
62+
assertisinstance(template,tmpl)
63+
assertgetattr(template,template._id_attr)==tmpl_id
64+
65+
66+
@pytest.mark.parametrize(
67+
"tmpl, tmpl_mgr, tmpl_path",
68+
[
69+
(ProjectDockerfileTemplate,"dockerfile_templates","dockerfiles"),
70+
(ProjectGitignoreTemplate,"gitignore_templates","gitignores"),
71+
(ProjectGitlabciymlTemplate,"gitlabciyml_templates","gitlab_ci_ymls"),
72+
(ProjectLicenseTemplate,"license_templates","licenses"),
73+
(ProjectIssueTemplate,"issue_templates","issues"),
74+
(ProjectMergeRequestTemplate,"merge_request_templates","merge_requests"),
75+
],
76+
ids=[
77+
"dockerfile",
78+
"gitignore",
79+
"gitlabciyml",
80+
"license",
81+
"issue",
82+
"mergerequest",
83+
],
84+
)
85+
deftest_get_project_template(project,tmpl,tmpl_mgr,tmpl_path):
86+
tmpl_id="sample"
87+
tmpl_content= {"name":tmpl_id,"content":"Sample template content"}
88+
89+
# ProjectLicenseTemplate templates have 'key' as the id attribute, so ensure
90+
# this is included in the response content
91+
iftmpl==ProjectLicenseTemplate:
92+
tmpl_id="smpl"
93+
tmpl_content.update({"key":tmpl_id})
94+
95+
path=f"projects/{project.id}/templates/{tmpl_path}/{tmpl_id}"
96+
withresponses.RequestsMock()asrsps:
97+
rsps.add(
98+
method=responses.GET,
99+
url=f"http://localhost/api/v4/{path}",
100+
json=tmpl_content,
101+
)
102+
103+
template=getattr(project,tmpl_mgr).get(tmpl_id)
104+
105+
assertisinstance(template,tmpl)
106+
assertgetattr(template,template._id_attr)==tmpl_id

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp