FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tests/unit/objects/test_templates.py at v8.6.0 · python-gitlab/python-gitlab · GitHub
python-gitlab
python-gitlab
Repository navigation
Code
Issues
16
(16)
Pull requests
15
(15)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_templates.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (80 loc) · 3.05 KB
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_templates.py
Copy path
File metadata and controls
94 lines (80 loc) · 3.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Gitlab API:
https://docs.gitlab.com/ce/api/templates/dockerfiles.html
https://docs.gitlab.com/ce/api/templates/gitignores.html
https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
https://docs.gitlab.com/ce/api/templates/licenses.html
https://docs.gitlab.com/ce/api/project_templates.html
"""
import
pytest
import
responses
from
gitlab
.
v4
.
objects
import
(
Dockerfile
,
Gitignore
,
Gitlabciyml
,
License
,
ProjectDockerfileTemplate
,
ProjectGitignoreTemplate
,
ProjectGitlabciymlTemplate
,
ProjectIssueTemplate
,
ProjectLicenseTemplate
,
ProjectMergeRequestTemplate
,
)
@
pytest
.
mark
.
parametrize
(
"tmpl, tmpl_mgr, tmpl_path"
,
[
(
Dockerfile
,
"dockerfiles"
,
"dockerfiles"
),
(
Gitignore
,
"gitignores"
,
"gitignores"
),
(
Gitlabciyml
,
"gitlabciymls"
,
"gitlab_ci_ymls"
),
(
License
,
"licenses"
,
"licenses"
),
],
ids
=
[
"dockerfile"
,
"gitignore"
,
"gitlabciyml"
,
"license"
],
)
def
test_get_template
(
gl
,
tmpl
,
tmpl_mgr
,
tmpl_path
):
tmpl_id
=
"sample"
tmpl_content
=
{
"name"
:
tmpl_id
,
"content"
:
"Sample template content"
}
# License templates have 'key' as the id attribute, so ensure
# this is included in the response content
if
tmpl
==
License
:
tmpl_id
=
"smpl"
tmpl_content
.
update
({
"key"
:
tmpl_id
})
path
=
f"templates/
{
tmpl_path
}
/
{
tmpl_id
}
"
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
f"http://localhost/api/v4/
{
path
}
"
,
json
=
tmpl_content
,
)
template
=
getattr
(
gl
,
tmpl_mgr
).
get
(
tmpl_id
)
assert
isinstance
(
template
,
tmpl
)
assert
getattr
(
template
,
template
.
_id_attr
)
==
tmpl_id
@
pytest
.
mark
.
parametrize
(
"tmpl, tmpl_mgr, tmpl_path"
,
[
(
ProjectDockerfileTemplate
,
"dockerfile_templates"
,
"dockerfiles"
),
(
ProjectGitignoreTemplate
,
"gitignore_templates"
,
"gitignores"
),
(
ProjectGitlabciymlTemplate
,
"gitlabciyml_templates"
,
"gitlab_ci_ymls"
),
(
ProjectLicenseTemplate
,
"license_templates"
,
"licenses"
),
(
ProjectIssueTemplate
,
"issue_templates"
,
"issues"
),
(
ProjectMergeRequestTemplate
,
"merge_request_templates"
,
"merge_requests"
),
],
ids
=
[
"dockerfile"
,
"gitignore"
,
"gitlabciyml"
,
"license"
,
"issue"
,
"mergerequest"
],
)
def
test_get_project_template
(
project
,
tmpl
,
tmpl_mgr
,
tmpl_path
):
tmpl_id
=
"sample"
tmpl_content
=
{
"name"
:
tmpl_id
,
"content"
:
"Sample template content"
}
# ProjectLicenseTemplate templates have 'key' as the id attribute, so ensure
# this is included in the response content
if
tmpl
==
ProjectLicenseTemplate
:
tmpl_id
=
"smpl"
tmpl_content
.
update
({
"key"
:
tmpl_id
})
path
=
f"projects/
{
project
.
id
}
/templates/
{
tmpl_path
}
/
{
tmpl_id
}
"
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
f"http://localhost/api/v4/
{
path
}
"
,
json
=
tmpl_content
,
)
template
=
getattr
(
project
,
tmpl_mgr
).
get
(
tmpl_id
)
assert
isinstance
(
template
,
tmpl
)
assert
getattr
(
template
,
template
.
_id_attr
)
==
tmpl_id
Back
|
FazBrowse Home
|
New Git URL