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

Commit0ba035b

Browse files
committed
test: increase projects coverage
1 parentef207da commit0ba035b

File tree

1 file changed

+153
-16
lines changed

1 file changed

+153
-16
lines changed

‎tests/unit/objects/test_projects.py‎

Lines changed: 153 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,33 @@
55
importpytest
66
importresponses
77

8-
fromgitlab.v4.objectsimportProject
8+
fromgitlab.v4.objectsimport (
9+
Project,
10+
ProjectFork,
11+
ProjectUser,
12+
StarredProject,
13+
UserProject,
14+
)
915

1016
project_content= {"name":"name","id":1}
17+
languages_content= {
18+
"python":80.00,
19+
"ruby":99.99,
20+
"CoffeeScript":0.01,
21+
}
22+
user_content= {
23+
"name":"first",
24+
"id":1,
25+
"state":"active",
26+
}
27+
forks_content= [
28+
{
29+
"id":1,
30+
},
31+
{
32+
"id":"python-gitlab%2Fpython-gitlab",
33+
},
34+
]
1135
import_content= {
1236
"id":1,
1337
"name":"project",
@@ -28,6 +52,106 @@ def resp_get_project():
2852
yieldrsps
2953

3054

55+
@pytest.fixture
56+
defresp_user_projects():
57+
withresponses.RequestsMock()asrsps:
58+
rsps.add(
59+
method=responses.GET,
60+
url="http://localhost/api/v4/users/1",
61+
json=user_content,
62+
content_type="application/json",
63+
status=200,
64+
)
65+
rsps.add(
66+
method=responses.GET,
67+
url="http://localhost/api/v4/users/1/projects",
68+
json=[project_content],
69+
content_type="application/json",
70+
status=200,
71+
)
72+
yieldrsps
73+
74+
75+
@pytest.fixture
76+
defresp_starred_projects():
77+
withresponses.RequestsMock()asrsps:
78+
rsps.add(
79+
method=responses.GET,
80+
url="http://localhost/api/v4/users/1",
81+
json=user_content,
82+
content_type="application/json",
83+
status=200,
84+
)
85+
rsps.add(
86+
method=responses.GET,
87+
url="http://localhost/api/v4/users/1/starred_projects",
88+
json=[project_content],
89+
content_type="application/json",
90+
status=200,
91+
)
92+
yieldrsps
93+
94+
95+
@pytest.fixture
96+
defresp_list_users():
97+
withresponses.RequestsMock()asrsps:
98+
rsps.add(
99+
method=responses.GET,
100+
url="http://localhost/api/v4/projects/1",
101+
json=project_content,
102+
content_type="application/json",
103+
status=200,
104+
)
105+
rsps.add(
106+
method=responses.GET,
107+
url="http://localhost/api/v4/projects/1/users",
108+
json=[user_content],
109+
content_type="application/json",
110+
status=200,
111+
)
112+
yieldrsps
113+
114+
115+
@pytest.fixture
116+
defresp_list_forks():
117+
withresponses.RequestsMock()asrsps:
118+
rsps.add(
119+
method=responses.GET,
120+
url="http://localhost/api/v4/projects/1",
121+
json=project_content,
122+
content_type="application/json",
123+
status=200,
124+
)
125+
rsps.add(
126+
method=responses.GET,
127+
url="http://localhost/api/v4/projects/1/forks",
128+
json=forks_content,
129+
content_type="application/json",
130+
status=200,
131+
)
132+
yieldrsps
133+
134+
135+
@pytest.fixture
136+
defresp_list_languages():
137+
withresponses.RequestsMock()asrsps:
138+
rsps.add(
139+
method=responses.GET,
140+
url="http://localhost/api/v4/projects/1",
141+
json=project_content,
142+
content_type="application/json",
143+
status=200,
144+
)
145+
rsps.add(
146+
method=responses.GET,
147+
url="http://localhost/api/v4/projects/1/languages",
148+
json=languages_content,
149+
content_type="application/json",
150+
status=200,
151+
)
152+
yieldrsps
153+
154+
31155
@pytest.fixture
32156
defresp_list_projects():
33157
withresponses.RequestsMock()asrsps:
@@ -98,19 +222,26 @@ def test_import_bitbucket_server(gl, resp_import_bitbucket_server):
98222
assertres["import_status"]=="scheduled"
99223

100224

101-
@pytest.mark.skip(reason="missing test")
102-
deftest_list_user_projects(gl):
103-
pass
225+
deftest_list_user_projects(gl,resp_user_projects):
226+
user_project=gl.users.get(1).projects.list()[0]
227+
assertisinstance(user_project,UserProject)
228+
assertuser_project.name=="name"
229+
assertuser_project.id==1
104230

105231

106-
@pytest.mark.skip(reason="missing test")
107-
deftest_list_user_starred_projects(gl):
108-
pass
232+
deftest_list_user_starred_projects(gl,resp_starred_projects):
233+
starred_projects=gl.users.get(1).starred_projects.list()[0]
234+
assertisinstance(starred_projects,StarredProject)
235+
assertstarred_projects.name=="name"
236+
assertstarred_projects.id==1
109237

110238

111-
@pytest.mark.skip(reason="missing test")
112-
deftest_list_project_users(gl):
113-
pass
239+
deftest_list_project_users(gl,resp_list_users):
240+
user=gl.projects.get(1).users.list()[0]
241+
assertisinstance(user,ProjectUser)
242+
assertuser.id==1
243+
assertuser.name=="first"
244+
assertuser.state=="active"
114245

115246

116247
@pytest.mark.skip(reason="missing test")
@@ -133,9 +264,11 @@ def test_fork_project(gl):
133264
pass
134265

135266

136-
@pytest.mark.skip(reason="missing test")
137-
deftest_list_project_forks(gl):
138-
pass
267+
deftest_list_project_forks(gl,resp_list_forks):
268+
forks=gl.projects.get(1).forks.list()
269+
assertisinstance(forks[0],ProjectFork)
270+
assertforks[0].id==1
271+
assertforks[1].id=="python-gitlab%2Fpython-gitlab"
139272

140273

141274
@pytest.mark.skip(reason="missing test")
@@ -153,9 +286,13 @@ def test_list_project_starrers(gl):
153286
pass
154287

155288

156-
@pytest.mark.skip(reason="missing test")
157-
deftest_get_project_languages(gl):
158-
pass
289+
deftest_get_project_languages(gl,resp_list_languages):
290+
python=gl.projects.get(1).languages().get("python")
291+
ruby=gl.projects.get(1).languages().get("ruby")
292+
coffee_script=gl.projects.get(1).languages().get("CoffeeScript")
293+
assertpython==80.00
294+
assertruby==99.99
295+
assertcoffee_script==00.01
159296

160297

161298
@pytest.mark.skip(reason="missing test")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp