55import pytest
66import responses
77
8- from gitlab .v4 .objects import Project
8+ from gitlab .v4 .objects import (
9+ Project ,
10+ ProjectFork ,
11+ ProjectUser ,
12+ StarredProject ,
13+ UserProject ,
14+ )
915
1016project_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+ ]
1132import_content = {
1233"id" :1 ,
1334"name" :"project" ,
@@ -28,6 +49,71 @@ def resp_get_project():
2849yield rsps
2950
3051
52+ @pytest .fixture
53+ def resp_user_projects ():
54+ with responses .RequestsMock ()as rsps :
55+ rsps .add (
56+ method = responses .GET ,
57+ url = "http://localhost/api/v4/users/1/projects" ,
58+ json = [project_content ],
59+ content_type = "application/json" ,
60+ status = 200 ,
61+ )
62+ yield rsps
63+
64+
65+ @pytest .fixture
66+ def resp_starred_projects ():
67+ with responses .RequestsMock ()as rsps :
68+ rsps .add (
69+ method = responses .GET ,
70+ url = "http://localhost/api/v4/users/1/starred_projects" ,
71+ json = [project_content ],
72+ content_type = "application/json" ,
73+ status = 200 ,
74+ )
75+ yield rsps
76+
77+
78+ @pytest .fixture
79+ def resp_list_users ():
80+ with responses .RequestsMock ()as rsps :
81+ rsps .add (
82+ method = responses .GET ,
83+ url = "http://localhost/api/v4/projects/1/users" ,
84+ json = [user_content ],
85+ content_type = "application/json" ,
86+ status = 200 ,
87+ )
88+ yield rsps
89+
90+
91+ @pytest .fixture
92+ def resp_list_forks ():
93+ with responses .RequestsMock ()as rsps :
94+ rsps .add (
95+ method = responses .GET ,
96+ url = "http://localhost/api/v4/projects/1/forks" ,
97+ json = forks_content ,
98+ content_type = "application/json" ,
99+ status = 200 ,
100+ )
101+ yield rsps
102+
103+
104+ @pytest .fixture
105+ def resp_list_languages ():
106+ with responses .RequestsMock ()as rsps :
107+ rsps .add (
108+ method = responses .GET ,
109+ url = "http://localhost/api/v4/projects/1/languages" ,
110+ json = languages_content ,
111+ content_type = "application/json" ,
112+ status = 200 ,
113+ )
114+ yield rsps
115+
116+
31117@pytest .fixture
32118def resp_list_projects ():
33119with responses .RequestsMock ()as rsps :
@@ -98,19 +184,26 @@ def test_import_bitbucket_server(gl, resp_import_bitbucket_server):
98184assert res ["import_status" ]== "scheduled"
99185
100186
101- @pytest .mark .skip (reason = "missing test" )
102- def test_list_user_projects (gl ):
103- pass
187+ def test_list_user_projects (user ,resp_user_projects ):
188+ user_project = user .projects .list ()[0 ]
189+ assert isinstance (user_project ,UserProject )
190+ assert user_project .name == "name"
191+ assert user_project .id == 1
104192
105193
106- @pytest .mark .skip (reason = "missing test" )
107- def test_list_user_starred_projects (gl ):
108- pass
194+ def test_list_user_starred_projects (user ,resp_starred_projects ):
195+ starred_projects = user .starred_projects .list ()[0 ]
196+ assert isinstance (starred_projects ,StarredProject )
197+ assert starred_projects .name == "name"
198+ assert starred_projects .id == 1
109199
110200
111- @pytest .mark .skip (reason = "missing test" )
112- def test_list_project_users (gl ):
113- pass
201+ def test_list_project_users (project ,resp_list_users ):
202+ user = project .users .list ()[0 ]
203+ assert isinstance (user ,ProjectUser )
204+ assert user .id == 1
205+ assert user .name == "first"
206+ assert user .state == "active"
114207
115208
116209@pytest .mark .skip (reason = "missing test" )
@@ -133,9 +226,10 @@ def test_fork_project(gl):
133226pass
134227
135228
136- @pytest .mark .skip (reason = "missing test" )
137- def test_list_project_forks (gl ):
138- pass
229+ def test_list_project_forks (project ,resp_list_forks ):
230+ fork = project .forks .list ()[0 ]
231+ assert isinstance (fork ,ProjectFork )
232+ assert fork .id == 1
139233
140234
141235@pytest .mark .skip (reason = "missing test" )
@@ -153,9 +247,13 @@ def test_list_project_starrers(gl):
153247pass
154248
155249
156- @pytest .mark .skip (reason = "missing test" )
157- def test_get_project_languages (gl ):
158- pass
250+ def test_get_project_languages (project ,resp_list_languages ):
251+ python = project .languages ().get ("python" )
252+ ruby = project .languages ().get ("ruby" )
253+ coffee_script = project .languages ().get ("CoffeeScript" )
254+ assert python == 80.00
255+ assert ruby == 99.99
256+ assert coffee_script == 00.01
159257
160258
161259@pytest .mark .skip (reason = "missing test" )
@@ -233,13 +331,11 @@ def test_delete_project_push_rule(gl):
233331pass
234332
235333
236- def test_transfer_project (gl ,resp_transfer_project ):
237- project = gl .projects .get (1 ,lazy = True )
334+ def test_transfer_project (project ,resp_transfer_project ):
238335project .transfer ("test-namespace" )
239336
240337
241- def test_transfer_project_deprecated_warns (gl ,resp_transfer_project ):
242- project = gl .projects .get (1 ,lazy = True )
338+ def test_transfer_project_deprecated_warns (project ,resp_transfer_project ):
243339with pytest .warns (DeprecationWarning ):
244340project .transfer_project ("test-namespace" )
245341