FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tests/unit/objects/test_badges.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_badges.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (155 loc) · 5.53 KB
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_badges.py
Copy path
File metadata and controls
200 lines (155 loc) · 5.53 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"""
GitLab API: https://docs.gitlab.com/ee/api/project_badges.html
GitLab API: https://docs.gitlab.com/ee/api/group_badges.html
"""
import
re
import
pytest
import
responses
from
gitlab
.
v4
.
objects
import
GroupBadge
,
ProjectBadge
link_url
=
(
"http://example.com/ci_status.svg?project=example-org/example-project&ref=main"
)
image_url
=
"https://example.io/my/badge"
rendered_link_url
=
(
"http://example.com/ci_status.svg?project=example-org/example-project&ref=main"
)
rendered_image_url
=
"https://example.io/my/badge"
new_badge
=
{
"link_url"
:
link_url
,
"image_url"
:
image_url
}
badge_content
=
{
"name"
:
"Coverage"
,
"id"
:
1
,
"link_url"
:
link_url
,
"image_url"
:
image_url
,
"rendered_link_url"
:
rendered_image_url
,
"rendered_image_url"
:
rendered_image_url
,
}
preview_badge_content
=
{
"link_url"
:
link_url
,
"image_url"
:
image_url
,
"rendered_link_url"
:
rendered_link_url
,
"rendered_image_url"
:
rendered_image_url
,
}
@
pytest
.
fixture
()
def
resp_get_badge
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges/1"
),
json
=
badge_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
()
def
resp_list_badges
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges"
),
json
=
[
badge_content
],
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
()
def
resp_create_badge
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
POST
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges"
),
json
=
badge_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
()
def
resp_update_badge
():
updated_content
=
dict
(
badge_content
)
updated_content
[
"link_url"
]
=
"http://link_url"
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
PUT
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges/1"
),
json
=
updated_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
()
def
resp_delete_badge
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges/1"
),
status
=
204
,
)
yield
rsps
@
pytest
.
fixture
()
def
resp_preview_badge
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(projects|groups)/1/badges/render"
),
json
=
preview_badge_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
def
test_list_project_badges
(
project
,
resp_list_badges
):
badges
=
project
.
badges
.
list
()
assert
isinstance
(
badges
,
list
)
assert
isinstance
(
badges
[
0
],
ProjectBadge
)
def
test_list_group_badges
(
group
,
resp_list_badges
):
badges
=
group
.
badges
.
list
()
assert
isinstance
(
badges
,
list
)
assert
isinstance
(
badges
[
0
],
GroupBadge
)
def
test_get_project_badge
(
project
,
resp_get_badge
):
badge
=
project
.
badges
.
get
(
1
)
assert
isinstance
(
badge
,
ProjectBadge
)
assert
badge
.
name
==
"Coverage"
assert
badge
.
id
==
1
def
test_get_group_badge
(
group
,
resp_get_badge
):
badge
=
group
.
badges
.
get
(
1
)
assert
isinstance
(
badge
,
GroupBadge
)
assert
badge
.
name
==
"Coverage"
assert
badge
.
id
==
1
def
test_delete_project_badge
(
project
,
resp_delete_badge
):
badge
=
project
.
badges
.
get
(
1
,
lazy
=
True
)
badge
.
delete
()
def
test_delete_group_badge
(
group
,
resp_delete_badge
):
badge
=
group
.
badges
.
get
(
1
,
lazy
=
True
)
badge
.
delete
()
def
test_create_project_badge
(
project
,
resp_create_badge
):
badge
=
project
.
badges
.
create
(
new_badge
)
assert
isinstance
(
badge
,
ProjectBadge
)
assert
badge
.
image_url
==
image_url
def
test_create_group_badge
(
group
,
resp_create_badge
):
badge
=
group
.
badges
.
create
(
new_badge
)
assert
isinstance
(
badge
,
GroupBadge
)
assert
badge
.
image_url
==
image_url
def
test_preview_project_badge
(
project
,
resp_preview_badge
):
output
=
project
.
badges
.
render
(
link_url
=
link_url
,
image_url
=
image_url
)
assert
isinstance
(
output
,
dict
)
assert
"rendered_link_url"
in
output
assert
"rendered_image_url"
in
output
assert
output
[
"link_url"
]
==
output
[
"rendered_link_url"
]
assert
output
[
"image_url"
]
==
output
[
"rendered_image_url"
]
def
test_preview_group_badge
(
group
,
resp_preview_badge
):
output
=
group
.
badges
.
render
(
link_url
=
link_url
,
image_url
=
image_url
)
assert
isinstance
(
output
,
dict
)
assert
"rendered_link_url"
in
output
assert
"rendered_image_url"
in
output
assert
output
[
"link_url"
]
==
output
[
"rendered_link_url"
]
assert
output
[
"image_url"
]
==
output
[
"rendered_image_url"
]
def
test_update_project_badge
(
project
,
resp_update_badge
):
badge
=
project
.
badges
.
get
(
1
,
lazy
=
True
)
badge
.
link_url
=
"http://link_url"
badge
.
save
()
assert
badge
.
link_url
==
"http://link_url"
def
test_update_group_badge
(
group
,
resp_update_badge
):
badge
=
group
.
badges
.
get
(
1
,
lazy
=
True
)
badge
.
link_url
=
"http://link_url"
badge
.
save
()
assert
badge
.
link_url
==
"http://link_url"
Back
|
FazBrowse Home
|
New Git URL